Mercurial > hg > orthanc-stone
comparison Resources/Graveyard/Deprecated/Platforms/Wasm/Defaults.h @ 1503:553084468225
moving /Deprecated/ to /Resources/Graveyard/Deprecated/
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Jun 2020 11:38:13 +0200 |
parents | Deprecated/Platforms/Wasm/Defaults.h@828a9b4ee1b7 |
children |
comparison
equal
deleted
inserted
replaced
1502:e5729dab3f67 | 1503:553084468225 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include <emscripten/emscripten.h> | |
25 | |
26 #include "../../Framework/Deprecated/Viewport/WidgetViewport.h" | |
27 #include "../../Framework/Deprecated/Widgets/LayoutWidget.h" | |
28 #include <Applications/IStoneApplication.h> | |
29 #include <Platforms/Wasm/WasmPlatformApplicationAdapter.h> | |
30 | |
31 typedef Deprecated::WidgetViewport* ViewportHandle; // the objects exchanged between JS and C++ | |
32 | |
33 #ifdef __cplusplus | |
34 extern "C" { | |
35 #endif | |
36 | |
37 // JS methods accessible from C++ | |
38 extern void ScheduleWebViewportRedrawFromCpp(ViewportHandle cppViewportHandle); | |
39 extern void UpdateStoneApplicationStatusFromCppWithString(const char* statusUpdateMessage); | |
40 extern void UpdateStoneApplicationStatusFromCppWithSerializedMessage(const char* statusUpdateMessage); | |
41 extern void stone_console_error(const char*); | |
42 extern void stone_console_warning(const char*); | |
43 extern void stone_console_info(const char*); | |
44 extern void stone_console_trace(const char*); | |
45 | |
46 // C++ methods accessible from JS | |
47 extern void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle cppViewportHandle); | |
48 extern void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, const char* value); | |
49 | |
50 | |
51 #ifdef __cplusplus | |
52 } | |
53 #endif | |
54 | |
55 // these methods must be implemented in the custom app "mainWasm.cpp" | |
56 extern OrthancStone::IStoneApplication* CreateUserApplication(OrthancStone::MessageBroker& broker); | |
57 extern OrthancStone::WasmPlatformApplicationAdapter* CreateWasmApplicationAdapter(OrthancStone::MessageBroker& broker, OrthancStone::IStoneApplication* application); | |
58 | |
59 namespace OrthancStone { | |
60 | |
61 // default Observer to trigger Viewport redraw when something changes in the Viewport | |
62 class ViewportContentChangedObserver : public IObserver | |
63 { | |
64 private: | |
65 // Flag to avoid flooding JavaScript with redundant Redraw requests | |
66 bool isScheduled_; | |
67 | |
68 public: | |
69 ViewportContentChangedObserver(MessageBroker& broker) : | |
70 IObserver(broker), | |
71 isScheduled_(false) | |
72 { | |
73 } | |
74 | |
75 void Reset() | |
76 { | |
77 isScheduled_ = false; | |
78 } | |
79 | |
80 void OnViewportChanged(const Deprecated::IViewport::ViewportChangedMessage& message) | |
81 { | |
82 if (!isScheduled_) | |
83 { | |
84 ScheduleWebViewportRedrawFromCpp((ViewportHandle)&message.GetOrigin()); // loosing constness when transmitted to Web | |
85 isScheduled_ = true; | |
86 } | |
87 } | |
88 }; | |
89 | |
90 // default status bar to log messages on the console/stdout | |
91 class StatusBar : public Deprecated::IStatusBar | |
92 { | |
93 public: | |
94 virtual void ClearMessage() | |
95 { | |
96 } | |
97 | |
98 virtual void SetMessage(const std::string& message) | |
99 { | |
100 printf("%s\n", message.c_str()); | |
101 } | |
102 }; | |
103 } |