Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/Defaults.h @ 427:3f9017db1738 am-vsol-upgrade-radiography-export
wip
author | am@osimis.io |
---|---|
date | Fri, 23 Nov 2018 16:06:23 +0100 |
parents | 3e6e10a5a6c8 |
children | 7105a0bad250 |
rev | line source |
---|---|
222 | 1 #pragma once |
2 | |
223 | 3 #include <emscripten/emscripten.h> |
4 | |
222 | 5 #include <Framework/dev.h> |
6 #include <Framework/Viewport/WidgetViewport.h> | |
7 #include <Framework/Widgets/LayoutWidget.h> | |
288 | 8 #include <Applications/IStoneApplication.h> |
307 | 9 #include <Platforms/Wasm/WasmPlatformApplicationAdapter.h> |
222 | 10 |
233 | 11 typedef OrthancStone::WidgetViewport* ViewportHandle; // the objects exchanged between JS and C++ |
227 | 12 |
222 | 13 #ifdef __cplusplus |
14 extern "C" { | |
15 #endif | |
16 | |
223 | 17 // JS methods accessible from C++ |
229 | 18 extern void ScheduleWebViewportRedrawFromCpp(ViewportHandle cppViewportHandle); |
287 | 19 extern void UpdateStoneApplicationStatusFromCpp(const char* statusUpdateMessage); |
222 | 20 |
223 | 21 // C++ methods accessible from JS |
229 | 22 extern void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle cppViewportHandle); |
254 | 23 extern void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, const char* value); |
24 | |
223 | 25 |
222 | 26 #ifdef __cplusplus |
27 } | |
28 #endif | |
29 | |
307 | 30 // these methods must be implemented in the custom app "mainWasm.cpp" |
288 | 31 extern OrthancStone::IStoneApplication* CreateUserApplication(OrthancStone::MessageBroker& broker); |
307 | 32 extern OrthancStone::WasmPlatformApplicationAdapter* CreateWasmApplicationAdapter(OrthancStone::MessageBroker& broker, OrthancStone::IStoneApplication* application); |
222 | 33 |
34 namespace OrthancStone { | |
35 | |
287 | 36 // default Observer to trigger Viewport redraw when something changes in the Viewport |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
37 class ViewportContentChangedObserver : public IObserver |
222 | 38 { |
39 private: | |
40 // Flag to avoid flooding JavaScript with redundant Redraw requests | |
41 bool isScheduled_; | |
42 | |
43 public: | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
44 ViewportContentChangedObserver(MessageBroker& broker) : |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
45 IObserver(broker), |
222 | 46 isScheduled_(false) |
47 { | |
48 } | |
49 | |
50 void Reset() | |
51 { | |
52 isScheduled_ = false; | |
53 } | |
54 | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
55 void OnViewportChanged(const IViewport::ViewportChangedMessage& message) |
222 | 56 { |
57 if (!isScheduled_) | |
58 { | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
59 ScheduleWebViewportRedrawFromCpp((ViewportHandle)&message.GetOrigin()); // loosing constness when transmitted to Web |
222 | 60 isScheduled_ = true; |
61 } | |
62 } | |
63 }; | |
64 | |
223 | 65 // default status bar to log messages on the console/stdout |
222 | 66 class StatusBar : public OrthancStone::IStatusBar |
67 { | |
68 public: | |
69 virtual void ClearMessage() | |
70 { | |
71 } | |
72 | |
73 virtual void SetMessage(const std::string& message) | |
74 { | |
75 printf("%s\n", message.c_str()); | |
76 } | |
77 }; | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
78 } |