Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/Defaults.cpp @ 457:3b4df9925db6 am-touch-events
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
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 24 Jan 2019 16:42:27 +0100 |
parents | 26b90b110719 |
children | e74f9271d653 |
comparison
equal
deleted
inserted
replaced
456:b70fcc134ba4 | 457:3b4df9925db6 |
---|---|
47 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport(broker)); | 47 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport(broker)); |
48 printf("viewport %x\n", (int)viewport.get()); | 48 printf("viewport %x\n", (int)viewport.get()); |
49 | 49 |
50 viewports_.push_back(viewport); | 50 viewports_.push_back(viewport); |
51 | 51 |
52 printf("There are now %d viewports in C++\n", viewports_.size()); | 52 printf("There are now %lu viewports in C++\n", viewports_.size()); |
53 | 53 |
54 viewport->SetStatusBar(statusBar_); | 54 viewport->SetStatusBar(statusBar_); |
55 | 55 |
56 viewport->RegisterObserverCallback( | 56 viewport->RegisterObserverCallback( |
57 new Callable<ViewportContentChangedObserver, IViewport::ViewportChangedMessage> | 57 new Callable<ViewportContentChangedObserver, IViewport::ViewportChangedMessage> |
62 | 62 |
63 // when WASM does not need a viewport anymore, it should release it | 63 // when WASM does not need a viewport anymore, it should release it |
64 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) { | 64 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) { |
65 viewports_.remove_if([viewport](const std::shared_ptr<OrthancStone::WidgetViewport>& v) { return v.get() == viewport;}); | 65 viewports_.remove_if([viewport](const std::shared_ptr<OrthancStone::WidgetViewport>& v) { return v.get() == viewport;}); |
66 | 66 |
67 printf("There are now %d viewports in C++\n", viewports_.size()); | 67 printf("There are now %lu viewports in C++\n", viewports_.size()); |
68 } | 68 } |
69 | 69 |
70 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | 70 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { |
71 | 71 |
72 printf("CreateWasmApplication\n"); | 72 printf("CreateWasmApplication\n"); |
189 | 189 |
190 default: | 190 default: |
191 return; // Unknown button | 191 return; // Unknown button |
192 } | 192 } |
193 | 193 |
194 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None /* TODO */); | 194 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<OrthancStone::Touch>()); |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, | 198 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, |
199 int deltaY, | 199 int deltaY, |
220 | 220 |
221 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, | 221 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, |
222 int x, | 222 int x, |
223 int y) | 223 int y) |
224 { | 224 { |
225 viewport->MouseMove(x, y); | 225 viewport->MouseMove(x, y, std::vector<OrthancStone::Touch>()); |
226 } | 226 } |
227 | 227 |
228 void GetTouchVector(std::vector<OrthancStone::Touch>& output, | |
229 int touchCount, | |
230 float x0, | |
231 float y0, | |
232 float x1, | |
233 float y1, | |
234 float x2, | |
235 float y2) | |
236 { | |
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++ | |
238 if (touchCount > 0) | |
239 { | |
240 output.push_back(OrthancStone::Touch(x0, y0)); | |
241 } | |
242 if (touchCount > 1) | |
243 { | |
244 output.push_back(OrthancStone::Touch(x1, y1)); | |
245 } | |
246 if (touchCount > 2) | |
247 { | |
248 output.push_back(OrthancStone::Touch(x2, y2)); | |
249 } | |
250 | |
251 } | |
252 | |
253 void EMSCRIPTEN_KEEPALIVE ViewportTouchStart(ViewportHandle viewport, | |
254 int touchCount, | |
255 float x0, | |
256 float y0, | |
257 float x1, | |
258 float y1, | |
259 float x2, | |
260 float y2) | |
261 { | |
262 printf("touch start with %d touches\n", touchCount); | |
263 | |
264 std::vector<OrthancStone::Touch> touches; | |
265 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | |
266 viewport->TouchStart(touches); | |
267 } | |
268 | |
269 void EMSCRIPTEN_KEEPALIVE ViewportTouchMove(ViewportHandle viewport, | |
270 int touchCount, | |
271 float x0, | |
272 float y0, | |
273 float x1, | |
274 float y1, | |
275 float x2, | |
276 float y2) | |
277 { | |
278 printf("touch move with %d touches\n", touchCount); | |
279 | |
280 std::vector<OrthancStone::Touch> touches; | |
281 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | |
282 viewport->TouchMove(touches); | |
283 } | |
284 | |
285 void EMSCRIPTEN_KEEPALIVE ViewportTouchEnd(ViewportHandle viewport, | |
286 int touchCount, | |
287 float x0, | |
288 float y0, | |
289 float x1, | |
290 float y1, | |
291 float x2, | |
292 float y2) | |
293 { | |
294 printf("touch end with %d touches remaining\n", touchCount); | |
295 | |
296 std::vector<OrthancStone::Touch> touches; | |
297 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | |
298 viewport->TouchEnd(touches); | |
299 } | |
300 | |
228 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, | 301 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, |
229 int key, | 302 int key, |
230 const char* keyChar, | 303 const char* keyChar, |
231 bool isShiftPressed, | 304 bool isShiftPressed, |
232 bool isControlPressed, | 305 bool isControlPressed, |