Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/Defaults.h @ 1357:0dc5b8a4b3a0 broker
hgignore
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 15 Apr 2020 15:23:07 +0200 |
parents | c35e98d22764 |
children |
rev | line source |
---|---|
222 | 1 #pragma once |
2 | |
223 | 3 #include <emscripten/emscripten.h> |
4 | |
732
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
5 #include "../../Framework/Deprecated/Viewport/WidgetViewport.h" |
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
6 #include "../../Framework/Deprecated/Widgets/LayoutWidget.h" |
288 | 7 #include <Applications/IStoneApplication.h> |
307 | 8 #include <Platforms/Wasm/WasmPlatformApplicationAdapter.h> |
222 | 9 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
10 typedef Deprecated::WidgetViewport* ViewportHandle; // the objects exchanged between JS and C++ |
227 | 11 |
222 | 12 #ifdef __cplusplus |
13 extern "C" { | |
14 #endif | |
15 | |
223 | 16 // JS methods accessible from C++ |
229 | 17 extern void ScheduleWebViewportRedrawFromCpp(ViewportHandle cppViewportHandle); |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
389
diff
changeset
|
18 extern void UpdateStoneApplicationStatusFromCppWithString(const char* statusUpdateMessage); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
389
diff
changeset
|
19 extern void UpdateStoneApplicationStatusFromCppWithSerializedMessage(const char* statusUpdateMessage); |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
20 extern void stone_console_error(const char*); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
21 extern void stone_console_warning(const char*); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
22 extern void stone_console_info(const char*); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
23 extern void stone_console_trace(const char*); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
24 |
223 | 25 // C++ methods accessible from JS |
229 | 26 extern void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle cppViewportHandle); |
254 | 27 extern void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, const char* value); |
28 | |
223 | 29 |
222 | 30 #ifdef __cplusplus |
31 } | |
32 #endif | |
33 | |
307 | 34 // these methods must be implemented in the custom app "mainWasm.cpp" |
288 | 35 extern OrthancStone::IStoneApplication* CreateUserApplication(OrthancStone::MessageBroker& broker); |
307 | 36 extern OrthancStone::WasmPlatformApplicationAdapter* CreateWasmApplicationAdapter(OrthancStone::MessageBroker& broker, OrthancStone::IStoneApplication* application); |
222 | 37 |
38 namespace OrthancStone { | |
39 | |
287 | 40 // 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
|
41 class ViewportContentChangedObserver : public IObserver |
222 | 42 { |
43 private: | |
44 // Flag to avoid flooding JavaScript with redundant Redraw requests | |
45 bool isScheduled_; | |
46 | |
47 public: | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
48 ViewportContentChangedObserver(MessageBroker& broker) : |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
49 IObserver(broker), |
222 | 50 isScheduled_(false) |
51 { | |
52 } | |
53 | |
54 void Reset() | |
55 { | |
56 isScheduled_ = false; | |
57 } | |
58 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
59 void OnViewportChanged(const Deprecated::IViewport::ViewportChangedMessage& message) |
222 | 60 { |
61 if (!isScheduled_) | |
62 { | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
63 ScheduleWebViewportRedrawFromCpp((ViewportHandle)&message.GetOrigin()); // loosing constness when transmitted to Web |
222 | 64 isScheduled_ = true; |
65 } | |
66 } | |
67 }; | |
68 | |
223 | 69 // default status bar to log messages on the console/stdout |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
70 class StatusBar : public Deprecated::IStatusBar |
222 | 71 { |
72 public: | |
73 virtual void ClearMessage() | |
74 { | |
75 } | |
76 | |
77 virtual void SetMessage(const std::string& message) | |
78 { | |
79 printf("%s\n", message.c_str()); | |
80 } | |
81 }; | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
82 } |