comparison Platforms/Wasm/Defaults.cpp @ 726:4f2416d519b4

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