Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/Defaults.cpp @ 715:636eb0e4c9dd twiga-viewer-first-release
Adding SetApplicationParameters
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 20 May 2019 18:42:39 +0200 |
parents | 79bb0a02d1cc |
children | 70992b38aa8a |
rev | line source |
---|---|
222 | 1 #include "Defaults.h" |
2 | |
223 | 3 #include "WasmWebService.h" |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
4 #include "WasmDelayedCallExecutor.h" |
223 | 5 #include <Framework/dev.h> |
6 #include "Framework/Widgets/TestCairoWidget.h" | |
7 #include <Framework/Viewport/WidgetViewport.h> | |
228 | 8 #include <algorithm> |
242 | 9 #include "Applications/Wasm/StartupParametersBuilder.h" |
307 | 10 #include "Platforms/Wasm/WasmPlatformApplicationAdapter.h" |
223 | 11 |
12 static unsigned int width_ = 0; | |
13 static unsigned int height_ = 0; | |
14 | |
15 /**********************************/ | |
16 | |
288 | 17 static std::unique_ptr<OrthancStone::IStoneApplication> application; |
307 | 18 static std::unique_ptr<OrthancStone::WasmPlatformApplicationAdapter> applicationWasmAdapter = NULL; |
288 | 19 static std::unique_ptr<OrthancStone::StoneApplicationContext> context; |
242 | 20 static OrthancStone::StartupParametersBuilder startupParametersBuilder; |
253 | 21 static OrthancStone::MessageBroker broker; |
242 | 22 |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
23 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_(broker); |
223 | 24 static OrthancStone::StatusBar statusBar_; |
25 | |
227 | 26 static std::list<std::shared_ptr<OrthancStone::WidgetViewport>> viewports_; |
27 | |
228 | 28 std::shared_ptr<OrthancStone::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) { |
29 for (const auto& v : viewports_) { | |
30 if (v.get() == viewport) { | |
31 return v; | |
32 } | |
33 } | |
229 | 34 assert(false); |
35 return std::shared_ptr<OrthancStone::WidgetViewport>(); | |
228 | 36 } |
37 | |
223 | 38 #ifdef __cplusplus |
39 extern "C" { | |
40 #endif | |
41 | |
42 using namespace OrthancStone; | |
227 | 43 |
44 // when WASM needs a C++ viewport | |
45 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { | |
46 | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
47 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport(broker)); |
287 | 48 printf("viewport %x\n", (int)viewport.get()); |
227 | 49 |
50 viewports_.push_back(viewport); | |
51 | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
52 printf("There are now %lu viewports in C++\n", viewports_.size()); |
227 | 53 |
54 viewport->SetStatusBar(statusBar_); | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
55 |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
56 viewport->RegisterObserverCallback( |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
57 new Callable<ViewportContentChangedObserver, IViewport::ViewportChangedMessage> |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
58 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged)); |
227 | 59 |
60 return viewport.get(); | |
61 } | |
62 | |
63 // when WASM does not need a viewport anymore, it should release it | |
64 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) { | |
65 viewports_.remove_if([viewport](const std::shared_ptr<OrthancStone::WidgetViewport>& v) { return v.get() == viewport;}); | |
66 | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
67 printf("There are now %lu viewports in C++\n", viewports_.size()); |
227 | 68 } |
69 | |
70 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | |
223 | 71 |
72 printf("CreateWasmApplication\n"); | |
73 | |
253 | 74 application.reset(CreateUserApplication(broker)); |
307 | 75 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get())); |
255 | 76 WasmWebService::SetBroker(broker); |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
77 WasmDelayedCallExecutor::SetBroker(broker); |
223 | 78 |
242 | 79 startupParametersBuilder.Clear(); |
223 | 80 } |
81 | |
82 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, | |
83 const char* value) { | |
242 | 84 startupParametersBuilder.SetStartupParameter(keyc, value); |
223 | 85 } |
86 | |
418 | 87 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri) { |
223 | 88 |
89 printf("StartWasmApplication\n"); | |
90 | |
91 // recreate a command line from uri arguments and parse it | |
92 boost::program_options::variables_map parameters; | |
242 | 93 boost::program_options::options_description options; |
94 application->DeclareStartupOptions(options); | |
95 startupParametersBuilder.GetStartupParameters(parameters, options); | |
223 | 96 |
418 | 97 context.reset(new OrthancStone::StoneApplicationContext(broker)); |
98 context->SetOrthancBaseUrl(baseUri); | |
99 printf("Base URL to Orthanc API: [%s]\n", baseUri); | |
100 context->SetWebService(OrthancStone::WasmWebService::GetInstance()); | |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
101 context->SetDelayedCallExecutor(OrthancStone::WasmDelayedCallExecutor::GetInstance()); |
242 | 102 application->Initialize(context.get(), statusBar_, parameters); |
103 application->InitializeWasm(); | |
223 | 104 |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
229
diff
changeset
|
105 // viewport->SetSize(width_, height_); |
223 | 106 printf("StartWasmApplication - completed\n"); |
107 } | |
108 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
109 void EMSCRIPTEN_KEEPALIVE WasmDoAnimation() |
223 | 110 { |
228 | 111 for (auto viewport : viewports_) { |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
112 // TODO Only launch the JavaScript timer if "HasAnimation()" |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
113 if (viewport->HasAnimation()) |
228 | 114 { |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
115 viewport->DoAnimation(); |
228 | 116 } |
117 | |
223 | 118 } |
119 | |
120 } | |
121 | |
122 | |
228 | 123 void EMSCRIPTEN_KEEPALIVE ViewportSetSize(ViewportHandle viewport, unsigned int width, unsigned int height) |
223 | 124 { |
125 width_ = width; | |
126 height_ = height; | |
127 | |
228 | 128 viewport->SetSize(width, height); |
223 | 129 } |
130 | |
228 | 131 int EMSCRIPTEN_KEEPALIVE ViewportRender(ViewportHandle viewport, |
227 | 132 unsigned int width, |
223 | 133 unsigned int height, |
134 uint8_t* data) | |
135 { | |
278 | 136 viewportContentChangedObserver_.Reset(); |
223 | 137 |
138 //printf("ViewportRender called %dx%d\n", width, height); | |
139 if (width == 0 || | |
140 height == 0) | |
141 { | |
142 return 1; | |
143 } | |
144 | |
145 Orthanc::ImageAccessor surface; | |
146 surface.AssignWritable(Orthanc::PixelFormat_BGRA32, width, height, 4 * width, data); | |
147 | |
227 | 148 viewport->Render(surface); |
223 | 149 |
150 // Convert from BGRA32 memory layout (only color mode supported by | |
151 // Cairo, which corresponds to CAIRO_FORMAT_ARGB32) to RGBA32 (as | |
152 // expected by HTML5 canvas). This simply amounts to swapping the | |
153 // B and R channels. | |
154 uint8_t* p = data; | |
155 for (unsigned int y = 0; y < height; y++) { | |
156 for (unsigned int x = 0; x < width; x++) { | |
157 uint8_t tmp = p[0]; | |
158 p[0] = p[2]; | |
159 p[2] = tmp; | |
160 | |
161 p += 4; | |
162 } | |
163 } | |
164 | |
165 return 1; | |
166 } | |
167 | |
168 | |
228 | 169 void EMSCRIPTEN_KEEPALIVE ViewportMouseDown(ViewportHandle viewport, |
170 unsigned int rawButton, | |
223 | 171 int x, |
172 int y, | |
173 unsigned int rawModifiers) | |
174 { | |
175 OrthancStone::MouseButton button; | |
176 switch (rawButton) | |
177 { | |
178 case 0: | |
179 button = OrthancStone::MouseButton_Left; | |
180 break; | |
181 | |
182 case 1: | |
183 button = OrthancStone::MouseButton_Middle; | |
184 break; | |
185 | |
186 case 2: | |
187 button = OrthancStone::MouseButton_Right; | |
188 break; | |
189 | |
190 default: | |
191 return; // Unknown button | |
192 } | |
193 | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
194 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<OrthancStone::Touch>()); |
223 | 195 } |
196 | |
197 | |
228 | 198 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, |
199 int deltaY, | |
223 | 200 int x, |
201 int y, | |
202 int isControl) | |
203 { | |
228 | 204 if (deltaY != 0) |
223 | 205 { |
206 OrthancStone::MouseWheelDirection direction = (deltaY < 0 ? | |
207 OrthancStone::MouseWheelDirection_Up : | |
208 OrthancStone::MouseWheelDirection_Down); | |
209 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; | |
210 | |
211 if (isControl != 0) | |
212 { | |
213 modifiers = OrthancStone::KeyboardModifiers_Control; | |
214 } | |
215 | |
228 | 216 viewport->MouseWheel(direction, x, y, modifiers); |
223 | 217 } |
218 } | |
219 | |
220 | |
228 | 221 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, |
222 int x, | |
223 | 223 int y) |
224 { | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
225 viewport->MouseMove(x, y, std::vector<OrthancStone::Touch>()); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
226 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
227 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
228 void GetTouchVector(std::vector<OrthancStone::Touch>& output, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
229 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
230 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
231 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
232 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
233 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
234 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
235 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
236 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
237 // TODO: it might be nice to try to pass all the x0,y0 coordinates as arrays but that's not so easy to pass array between JS and C++ |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
238 if (touchCount > 0) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
239 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
240 output.push_back(OrthancStone::Touch(x0, y0)); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
241 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
242 if (touchCount > 1) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
243 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
244 output.push_back(OrthancStone::Touch(x1, y1)); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
245 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
246 if (touchCount > 2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
247 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
248 output.push_back(OrthancStone::Touch(x2, y2)); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
249 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
250 |
223 | 251 } |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
252 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
253 void EMSCRIPTEN_KEEPALIVE ViewportTouchStart(ViewportHandle viewport, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
254 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
255 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
256 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
257 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
258 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
259 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
260 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
261 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
262 printf("touch start with %d touches\n", touchCount); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
263 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
264 std::vector<OrthancStone::Touch> touches; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
265 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
266 viewport->TouchStart(touches); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
267 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
268 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
269 void EMSCRIPTEN_KEEPALIVE ViewportTouchMove(ViewportHandle viewport, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
270 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
271 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
272 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
273 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
274 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
275 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
276 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
277 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
278 printf("touch move with %d touches\n", touchCount); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
279 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
280 std::vector<OrthancStone::Touch> touches; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
281 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
282 viewport->TouchMove(touches); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
283 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
284 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
285 void EMSCRIPTEN_KEEPALIVE ViewportTouchEnd(ViewportHandle viewport, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
286 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
287 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
288 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
289 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
290 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
291 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
292 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
293 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
294 printf("touch end with %d touches remaining\n", touchCount); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
295 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
296 std::vector<OrthancStone::Touch> touches; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
297 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
298 viewport->TouchEnd(touches); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
299 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
300 |
228 | 301 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, |
327 | 302 int key, |
303 const char* keyChar, | |
223 | 304 bool isShiftPressed, |
305 bool isControlPressed, | |
306 bool isAltPressed) | |
307 | |
308 { | |
228 | 309 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; |
310 if (isShiftPressed) { | |
311 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Shift); | |
223 | 312 } |
228 | 313 if (isControlPressed) { |
314 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Control); | |
315 } | |
316 if (isAltPressed) { | |
317 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Alt); | |
318 } | |
327 | 319 |
320 char c = 0; | |
321 if (keyChar != NULL && key == OrthancStone::KeyboardKeys_Generic) { | |
322 c = keyChar[0]; | |
323 } | |
324 viewport->KeyPressed(static_cast<OrthancStone::KeyboardKeys>(key), c, modifiers); | |
223 | 325 } |
326 | |
327 | |
228 | 328 void EMSCRIPTEN_KEEPALIVE ViewportMouseUp(ViewportHandle viewport) |
223 | 329 { |
228 | 330 viewport->MouseUp(); |
223 | 331 } |
332 | |
333 | |
228 | 334 void EMSCRIPTEN_KEEPALIVE ViewportMouseEnter(ViewportHandle viewport) |
223 | 335 { |
228 | 336 viewport->MouseEnter(); |
223 | 337 } |
338 | |
339 | |
228 | 340 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport) |
223 | 341 { |
228 | 342 viewport->MouseLeave(); |
223 | 343 } |
344 | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
345 const char* EMSCRIPTEN_KEEPALIVE SendSerializedMessageToStoneApplication(const char* message) |
287 | 346 { |
347 static std::string output; // we don't want the string to be deallocated when we return to JS code so we always use the same string (this is fine since JS is single-thread) | |
348 | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
349 printf("SendSerializedMessageToStoneApplication\n"); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
350 printf("%s", message); |
307 | 351 |
352 if (applicationWasmAdapter.get() != NULL) { | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
353 applicationWasmAdapter->HandleSerializedMessageFromWeb(output, std::string(message)); |
287 | 354 return output.c_str(); |
355 } | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
356 printf("This Stone application does not have a Web Adapter"); |
307 | 357 return NULL; |
287 | 358 } |
359 | |
223 | 360 #ifdef __cplusplus |
361 } | |
362 #endif |