Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/Defaults.cpp @ 754:92c400a09f1b
Merge from default
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 22 May 2019 16:13:46 +0200 |
parents | c35e98d22764 |
children | 238693c3bc51 |
comparison
equal
deleted
inserted
replaced
753:a386bbc955dc | 754:92c400a09f1b |
---|---|
1 #include "Defaults.h" | 1 #include "Defaults.h" |
2 | 2 |
3 #include "WasmWebService.h" | 3 #include "WasmWebService.h" |
4 #include "WasmDelayedCallExecutor.h" | 4 #include "WasmDelayedCallExecutor.h" |
5 #include <Framework/dev.h> | 5 #include "../../Framework/Deprecated/Widgets/TestCairoWidget.h" |
6 #include "Framework/Widgets/TestCairoWidget.h" | 6 #include <Framework/Deprecated/Viewport/WidgetViewport.h> |
7 #include <Framework/Viewport/WidgetViewport.h> | |
8 #include <Applications/Wasm/StartupParametersBuilder.h> | 7 #include <Applications/Wasm/StartupParametersBuilder.h> |
9 #include <Platforms/Wasm/WasmPlatformApplicationAdapter.h> | 8 #include <Platforms/Wasm/WasmPlatformApplicationAdapter.h> |
10 #include <Core/Logging.h> | 9 #include <Core/Logging.h> |
11 | 10 |
12 #include <algorithm> | 11 #include <algorithm> |
24 static OrthancStone::MessageBroker broker; | 23 static OrthancStone::MessageBroker broker; |
25 | 24 |
26 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_(broker); | 25 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_(broker); |
27 static OrthancStone::StatusBar statusBar_; | 26 static OrthancStone::StatusBar statusBar_; |
28 | 27 |
29 static std::list<std::shared_ptr<OrthancStone::WidgetViewport>> viewports_; | 28 static std::list<std::shared_ptr<Deprecated::WidgetViewport>> viewports_; |
30 | 29 |
31 std::shared_ptr<OrthancStone::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) { | 30 std::shared_ptr<Deprecated::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) { |
32 for (const auto& v : viewports_) { | 31 for (const auto& v : viewports_) { |
33 if (v.get() == viewport) { | 32 if (v.get() == viewport) { |
34 return v; | 33 return v; |
35 } | 34 } |
36 } | 35 } |
37 assert(false); | 36 assert(false); |
38 return std::shared_ptr<OrthancStone::WidgetViewport>(); | 37 return std::shared_ptr<Deprecated::WidgetViewport>(); |
39 } | 38 } |
40 | 39 |
41 #ifdef __cplusplus | 40 #ifdef __cplusplus |
42 extern "C" { | 41 extern "C" { |
43 #endif | 42 #endif |
45 using namespace OrthancStone; | 44 using namespace OrthancStone; |
46 | 45 |
47 // when WASM needs a C++ viewport | 46 // when WASM needs a C++ viewport |
48 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { | 47 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { |
49 | 48 |
50 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport(broker)); | 49 std::shared_ptr<Deprecated::WidgetViewport> viewport(new Deprecated::WidgetViewport(broker)); |
51 printf("viewport %x\n", (int)viewport.get()); | 50 printf("viewport %x\n", (int)viewport.get()); |
52 | 51 |
53 viewports_.push_back(viewport); | 52 viewports_.push_back(viewport); |
54 | 53 |
55 printf("There are now %lu viewports in C++\n", viewports_.size()); | 54 printf("There are now %lu viewports in C++\n", viewports_.size()); |
56 | 55 |
57 viewport->SetStatusBar(statusBar_); | 56 viewport->SetStatusBar(statusBar_); |
58 | 57 |
59 viewport->RegisterObserverCallback( | 58 viewport->RegisterObserverCallback( |
60 new Callable<ViewportContentChangedObserver, IViewport::ViewportChangedMessage> | 59 new Callable<ViewportContentChangedObserver, Deprecated::IViewport::ViewportChangedMessage> |
61 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged)); | 60 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged)); |
62 | 61 |
63 return viewport.get(); | 62 return viewport.get(); |
64 } | 63 } |
65 | 64 |
66 // when WASM does not need a viewport anymore, it should release it | 65 // when WASM does not need a viewport anymore, it should release it |
67 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) { | 66 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) { |
68 viewports_.remove_if([viewport](const std::shared_ptr<OrthancStone::WidgetViewport>& v) { return v.get() == viewport;}); | 67 viewports_.remove_if([viewport](const std::shared_ptr<Deprecated::WidgetViewport>& v) { return v.get() == viewport;}); |
69 | 68 |
70 printf("There are now %lu viewports in C++\n", viewports_.size()); | 69 printf("There are now %lu viewports in C++\n", viewports_.size()); |
71 } | 70 } |
72 | 71 |
73 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | 72 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { |
74 | 73 |
75 printf("CreateWasmApplication\n"); | 74 printf("CreateWasmApplication\n"); |
76 | 75 |
77 application.reset(CreateUserApplication(broker)); | 76 application.reset(CreateUserApplication(broker)); |
78 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get())); | 77 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get())); |
79 WasmWebService::SetBroker(broker); | 78 Deprecated::WasmWebService::SetBroker(broker); |
80 WasmDelayedCallExecutor::SetBroker(broker); | 79 Deprecated::WasmDelayedCallExecutor::SetBroker(broker); |
81 | 80 |
82 startupParametersBuilder.Clear(); | 81 startupParametersBuilder.Clear(); |
83 } | 82 } |
84 | 83 |
85 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, | 84 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, |
102 startupParametersBuilder.GetStartupParameters(parameters, options); | 101 startupParametersBuilder.GetStartupParameters(parameters, options); |
103 | 102 |
104 context.reset(new OrthancStone::StoneApplicationContext(broker)); | 103 context.reset(new OrthancStone::StoneApplicationContext(broker)); |
105 context->SetOrthancBaseUrl(baseUri); | 104 context->SetOrthancBaseUrl(baseUri); |
106 printf("Base URL to Orthanc API: [%s]\n", baseUri); | 105 printf("Base URL to Orthanc API: [%s]\n", baseUri); |
107 context->SetWebService(OrthancStone::WasmWebService::GetInstance()); | 106 context->SetWebService(Deprecated::WasmWebService::GetInstance()); |
108 context->SetDelayedCallExecutor(OrthancStone::WasmDelayedCallExecutor::GetInstance()); | 107 context->SetDelayedCallExecutor(Deprecated::WasmDelayedCallExecutor::GetInstance()); |
109 application->Initialize(context.get(), statusBar_, parameters); | 108 application->Initialize(context.get(), statusBar_, parameters); |
110 application->InitializeWasm(); | 109 application->InitializeWasm(); |
111 | 110 |
112 // viewport->SetSize(width_, height_); | 111 // viewport->SetSize(width_, height_); |
113 printf("StartWasmApplication - completed\n"); | 112 printf("StartWasmApplication - completed\n"); |
206 | 205 |
207 default: | 206 default: |
208 return; // Unknown button | 207 return; // Unknown button |
209 } | 208 } |
210 | 209 |
211 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<OrthancStone::Touch>()); | 210 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<Deprecated::Touch>()); |
212 } | 211 } |
213 | 212 |
214 | 213 |
215 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, | 214 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, |
216 int deltaY, | 215 int deltaY, |
237 | 236 |
238 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, | 237 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, |
239 int x, | 238 int x, |
240 int y) | 239 int y) |
241 { | 240 { |
242 viewport->MouseMove(x, y, std::vector<OrthancStone::Touch>()); | 241 viewport->MouseMove(x, y, std::vector<Deprecated::Touch>()); |
243 } | 242 } |
244 | 243 |
245 void GetTouchVector(std::vector<OrthancStone::Touch>& output, | 244 void GetTouchVector(std::vector<Deprecated::Touch>& output, |
246 int touchCount, | 245 int touchCount, |
247 float x0, | 246 float x0, |
248 float y0, | 247 float y0, |
249 float x1, | 248 float x1, |
250 float y1, | 249 float y1, |
252 float y2) | 251 float y2) |
253 { | 252 { |
254 // 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++ | 253 // 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++ |
255 if (touchCount > 0) | 254 if (touchCount > 0) |
256 { | 255 { |
257 output.push_back(OrthancStone::Touch(x0, y0)); | 256 output.push_back(Deprecated::Touch(x0, y0)); |
258 } | 257 } |
259 if (touchCount > 1) | 258 if (touchCount > 1) |
260 { | 259 { |
261 output.push_back(OrthancStone::Touch(x1, y1)); | 260 output.push_back(Deprecated::Touch(x1, y1)); |
262 } | 261 } |
263 if (touchCount > 2) | 262 if (touchCount > 2) |
264 { | 263 { |
265 output.push_back(OrthancStone::Touch(x2, y2)); | 264 output.push_back(Deprecated::Touch(x2, y2)); |
266 } | 265 } |
267 | 266 |
268 } | 267 } |
269 | 268 |
270 void EMSCRIPTEN_KEEPALIVE ViewportTouchStart(ViewportHandle viewport, | 269 void EMSCRIPTEN_KEEPALIVE ViewportTouchStart(ViewportHandle viewport, |
276 float x2, | 275 float x2, |
277 float y2) | 276 float y2) |
278 { | 277 { |
279 printf("touch start with %d touches\n", touchCount); | 278 printf("touch start with %d touches\n", touchCount); |
280 | 279 |
281 std::vector<OrthancStone::Touch> touches; | 280 std::vector<Deprecated::Touch> touches; |
282 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | 281 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
283 viewport->TouchStart(touches); | 282 viewport->TouchStart(touches); |
284 } | 283 } |
285 | 284 |
286 void EMSCRIPTEN_KEEPALIVE ViewportTouchMove(ViewportHandle viewport, | 285 void EMSCRIPTEN_KEEPALIVE ViewportTouchMove(ViewportHandle viewport, |
292 float x2, | 291 float x2, |
293 float y2) | 292 float y2) |
294 { | 293 { |
295 printf("touch move with %d touches\n", touchCount); | 294 printf("touch move with %d touches\n", touchCount); |
296 | 295 |
297 std::vector<OrthancStone::Touch> touches; | 296 std::vector<Deprecated::Touch> touches; |
298 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | 297 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
299 viewport->TouchMove(touches); | 298 viewport->TouchMove(touches); |
300 } | 299 } |
301 | 300 |
302 void EMSCRIPTEN_KEEPALIVE ViewportTouchEnd(ViewportHandle viewport, | 301 void EMSCRIPTEN_KEEPALIVE ViewportTouchEnd(ViewportHandle viewport, |
308 float x2, | 307 float x2, |
309 float y2) | 308 float y2) |
310 { | 309 { |
311 printf("touch end with %d touches remaining\n", touchCount); | 310 printf("touch end with %d touches remaining\n", touchCount); |
312 | 311 |
313 std::vector<OrthancStone::Touch> touches; | 312 std::vector<Deprecated::Touch> touches; |
314 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | 313 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
315 viewport->TouchEnd(touches); | 314 viewport->TouchEnd(touches); |
316 } | 315 } |
317 | 316 |
318 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, | 317 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, |