Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/Defaults.cpp @ 506:801d2697a1b1 bgo-commands-codegen
Merge with am-touch-events
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 26 Feb 2019 21:33:16 +0100 |
parents | e74f9271d653 |
children | 7105a0bad250 |
comparison
equal
deleted
inserted
replaced
505:4cc7bb55bd49 | 506:801d2697a1b1 |
---|---|
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, |
271 | 344 |
272 const char* EMSCRIPTEN_KEEPALIVE SendMessageToStoneApplication(const char* message) | 345 const char* EMSCRIPTEN_KEEPALIVE SendMessageToStoneApplication(const char* message) |
273 { | 346 { |
274 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) | 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) |
275 | 348 |
276 printf("SendMessageToStoneApplication\n"); | 349 printf("SendMessageToStoneApplication (JS -> C++): %s\n", message); |
277 printf("%s", message); | |
278 | 350 |
279 if (applicationWasmAdapter.get() != NULL) { | 351 if (applicationWasmAdapter.get() != NULL) { |
280 printf("sending message to C++\n"); | |
281 applicationWasmAdapter->HandleMessageFromWeb(output, std::string(message)); | 352 applicationWasmAdapter->HandleMessageFromWeb(output, std::string(message)); |
282 return output.c_str(); | 353 return output.c_str(); |
283 } | 354 } |
284 printf("This stone application does not have a Web Adapter"); | 355 printf("This stone application does not have a Web Adapter\n"); |
285 return NULL; | 356 return NULL; |
286 } | 357 } |
287 | 358 |
288 | 359 |
289 #ifdef __cplusplus | 360 #ifdef __cplusplus |