Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/Defaults.cpp @ 877:f7e5ee59ba17 am-dev
debug code to monitor large malloc/free (currently disabled)
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 03 Jul 2019 10:16:22 +0200 |
parents | 238693c3bc51 |
children | 8f7930f589ef |
rev | line source |
---|---|
222 | 1 #include "Defaults.h" |
2 | |
223 | 3 #include "WasmWebService.h" |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
4 #include "WasmDelayedCallExecutor.h" |
732
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
5 #include "../../Framework/Deprecated/Widgets/TestCairoWidget.h" |
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
6 #include <Framework/Deprecated/Viewport/WidgetViewport.h> |
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:
535
diff
changeset
|
7 #include <Applications/Wasm/StartupParametersBuilder.h> |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
8 #include <Platforms/Wasm/WasmPlatformApplicationAdapter.h> |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
9 #include <Core/Logging.h> |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
10 |
228 | 11 #include <algorithm> |
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:
535
diff
changeset
|
12 |
223 | 13 |
14 static unsigned int width_ = 0; | |
15 static unsigned int height_ = 0; | |
16 | |
17 /**********************************/ | |
18 | |
288 | 19 static std::unique_ptr<OrthancStone::IStoneApplication> application; |
307 | 20 static std::unique_ptr<OrthancStone::WasmPlatformApplicationAdapter> applicationWasmAdapter = NULL; |
288 | 21 static std::unique_ptr<OrthancStone::StoneApplicationContext> context; |
242 | 22 static OrthancStone::StartupParametersBuilder startupParametersBuilder; |
253 | 23 static OrthancStone::MessageBroker broker; |
242 | 24 |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
25 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_(broker); |
223 | 26 static OrthancStone::StatusBar statusBar_; |
27 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
28 static std::list<std::shared_ptr<Deprecated::WidgetViewport>> viewports_; |
227 | 29 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
30 std::shared_ptr<Deprecated::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) { |
228 | 31 for (const auto& v : viewports_) { |
32 if (v.get() == viewport) { | |
33 return v; | |
34 } | |
35 } | |
229 | 36 assert(false); |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
37 return std::shared_ptr<Deprecated::WidgetViewport>(); |
228 | 38 } |
39 | |
223 | 40 #ifdef __cplusplus |
41 extern "C" { | |
42 #endif | |
43 | |
877
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
44 #if 0 |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
45 size_t bigChunksTotalSize = 0; |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
46 std::map<void*, size_t> allocatedBigChunks; |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
47 |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
48 extern void* emscripten_builtin_malloc(size_t bytes); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
49 extern void emscripten_builtin_free(void* mem); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
50 |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
51 void * __attribute__((noinline)) malloc(size_t size) |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
52 { |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
53 void *ptr = emscripten_builtin_malloc(size); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
54 if (size > 100000) |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
55 { |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
56 bigChunksTotalSize += size; |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
57 printf("++ Allocated %zu bytes, got %p. (%zu MB consumed by big chunks)\n", size, ptr, bigChunksTotalSize/(1024*1024)); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
58 allocatedBigChunks[ptr] = size; |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
59 } |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
60 return ptr; |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
61 } |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
62 |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
63 void __attribute__((noinline)) free(void *ptr) |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
64 { |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
65 emscripten_builtin_free(ptr); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
66 |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
67 std::map<void*, size_t>::iterator it = allocatedBigChunks.find(ptr); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
68 if (it != allocatedBigChunks.end()) |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
69 { |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
70 bigChunksTotalSize -= it->second; |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
71 printf("-- Freed %zu bytes at %p. (%zu MB consumed by big chunks)\n", it->second, ptr, bigChunksTotalSize/(1024*1024)); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
72 allocatedBigChunks.erase(it); |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
73 } |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
74 } |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
75 #endif // 0 |
f7e5ee59ba17
debug code to monitor large malloc/free (currently disabled)
Alain Mazy <alain@mazy.be>
parents:
860
diff
changeset
|
76 |
223 | 77 using namespace OrthancStone; |
227 | 78 |
79 // when WASM needs a C++ viewport | |
80 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { | |
81 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
82 std::shared_ptr<Deprecated::WidgetViewport> viewport(new Deprecated::WidgetViewport(broker)); |
287 | 83 printf("viewport %x\n", (int)viewport.get()); |
227 | 84 |
85 viewports_.push_back(viewport); | |
86 | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
87 printf("There are now %lu viewports in C++\n", viewports_.size()); |
227 | 88 |
89 viewport->SetStatusBar(statusBar_); | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
90 |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
91 viewport->RegisterObserverCallback( |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
92 new Callable<ViewportContentChangedObserver, Deprecated::IViewport::ViewportChangedMessage> |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
93 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged)); |
227 | 94 |
95 return viewport.get(); | |
96 } | |
97 | |
98 // when WASM does not need a viewport anymore, it should release it | |
99 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
100 viewports_.remove_if([viewport](const std::shared_ptr<Deprecated::WidgetViewport>& v) { return v.get() == viewport;}); |
227 | 101 |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
102 printf("There are now %lu viewports in C++\n", viewports_.size()); |
227 | 103 } |
104 | |
105 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | |
223 | 106 |
107 printf("CreateWasmApplication\n"); | |
108 | |
253 | 109 application.reset(CreateUserApplication(broker)); |
307 | 110 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get())); |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
111 Deprecated::WasmWebService::SetBroker(broker); |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
112 Deprecated::WasmDelayedCallExecutor::SetBroker(broker); |
223 | 113 |
242 | 114 startupParametersBuilder.Clear(); |
223 | 115 } |
116 | |
117 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, | |
118 const char* value) { | |
242 | 119 startupParametersBuilder.SetStartupParameter(keyc, value); |
223 | 120 } |
121 | |
418 | 122 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri) { |
223 | 123 |
124 printf("StartWasmApplication\n"); | |
125 | |
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:
535
diff
changeset
|
126 Orthanc::Logging::SetErrorWarnInfoTraceLoggingFunctions( |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
127 stone_console_error, stone_console_warning, |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
128 stone_console_info, stone_console_trace); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
129 |
223 | 130 // recreate a command line from uri arguments and parse it |
131 boost::program_options::variables_map parameters; | |
242 | 132 boost::program_options::options_description options; |
133 application->DeclareStartupOptions(options); | |
134 startupParametersBuilder.GetStartupParameters(parameters, options); | |
223 | 135 |
418 | 136 context.reset(new OrthancStone::StoneApplicationContext(broker)); |
137 context->SetOrthancBaseUrl(baseUri); | |
138 printf("Base URL to Orthanc API: [%s]\n", baseUri); | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
139 context->SetWebService(Deprecated::WasmWebService::GetInstance()); |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
140 context->SetDelayedCallExecutor(Deprecated::WasmDelayedCallExecutor::GetInstance()); |
242 | 141 application->Initialize(context.get(), statusBar_, parameters); |
142 application->InitializeWasm(); | |
223 | 143 |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
229
diff
changeset
|
144 // viewport->SetSize(width_, height_); |
223 | 145 printf("StartWasmApplication - completed\n"); |
146 } | |
147 | |
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:
535
diff
changeset
|
148 bool EMSCRIPTEN_KEEPALIVE WasmIsTraceLevelEnabled() |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
149 { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
150 return Orthanc::Logging::IsTraceLevelEnabled(); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
151 } |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
152 |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
153 bool EMSCRIPTEN_KEEPALIVE WasmIsInfoLevelEnabled() |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
154 { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
155 return Orthanc::Logging::IsInfoLevelEnabled(); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
156 } |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
535
diff
changeset
|
157 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
158 void EMSCRIPTEN_KEEPALIVE WasmDoAnimation() |
223 | 159 { |
228 | 160 for (auto viewport : viewports_) { |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
161 // TODO Only launch the JavaScript timer if "HasAnimation()" |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
162 if (viewport->HasAnimation()) |
228 | 163 { |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
164 viewport->DoAnimation(); |
228 | 165 } |
166 | |
223 | 167 } |
168 | |
169 } | |
170 | |
171 | |
228 | 172 void EMSCRIPTEN_KEEPALIVE ViewportSetSize(ViewportHandle viewport, unsigned int width, unsigned int height) |
223 | 173 { |
174 width_ = width; | |
175 height_ = height; | |
176 | |
228 | 177 viewport->SetSize(width, height); |
223 | 178 } |
179 | |
228 | 180 int EMSCRIPTEN_KEEPALIVE ViewportRender(ViewportHandle viewport, |
227 | 181 unsigned int width, |
223 | 182 unsigned int height, |
183 uint8_t* data) | |
184 { | |
278 | 185 viewportContentChangedObserver_.Reset(); |
223 | 186 |
187 //printf("ViewportRender called %dx%d\n", width, height); | |
188 if (width == 0 || | |
189 height == 0) | |
190 { | |
191 return 1; | |
192 } | |
193 | |
194 Orthanc::ImageAccessor surface; | |
195 surface.AssignWritable(Orthanc::PixelFormat_BGRA32, width, height, 4 * width, data); | |
196 | |
227 | 197 viewport->Render(surface); |
223 | 198 |
199 // Convert from BGRA32 memory layout (only color mode supported by | |
200 // Cairo, which corresponds to CAIRO_FORMAT_ARGB32) to RGBA32 (as | |
201 // expected by HTML5 canvas). This simply amounts to swapping the | |
202 // B and R channels. | |
203 uint8_t* p = data; | |
204 for (unsigned int y = 0; y < height; y++) { | |
205 for (unsigned int x = 0; x < width; x++) { | |
206 uint8_t tmp = p[0]; | |
207 p[0] = p[2]; | |
208 p[2] = tmp; | |
209 | |
210 p += 4; | |
211 } | |
212 } | |
213 | |
214 return 1; | |
215 } | |
216 | |
217 | |
228 | 218 void EMSCRIPTEN_KEEPALIVE ViewportMouseDown(ViewportHandle viewport, |
219 unsigned int rawButton, | |
223 | 220 int x, |
221 int y, | |
222 unsigned int rawModifiers) | |
223 { | |
224 OrthancStone::MouseButton button; | |
225 switch (rawButton) | |
226 { | |
227 case 0: | |
228 button = OrthancStone::MouseButton_Left; | |
229 break; | |
230 | |
231 case 1: | |
232 button = OrthancStone::MouseButton_Middle; | |
233 break; | |
234 | |
235 case 2: | |
236 button = OrthancStone::MouseButton_Right; | |
237 break; | |
238 | |
239 default: | |
240 return; // Unknown button | |
241 } | |
242 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
243 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<Deprecated::Touch>()); |
223 | 244 } |
245 | |
246 | |
228 | 247 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, |
248 int deltaY, | |
223 | 249 int x, |
250 int y, | |
251 int isControl) | |
252 { | |
228 | 253 if (deltaY != 0) |
223 | 254 { |
255 OrthancStone::MouseWheelDirection direction = (deltaY < 0 ? | |
256 OrthancStone::MouseWheelDirection_Up : | |
257 OrthancStone::MouseWheelDirection_Down); | |
258 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; | |
259 | |
260 if (isControl != 0) | |
261 { | |
262 modifiers = OrthancStone::KeyboardModifiers_Control; | |
263 } | |
264 | |
228 | 265 viewport->MouseWheel(direction, x, y, modifiers); |
223 | 266 } |
267 } | |
268 | |
269 | |
228 | 270 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, |
271 int x, | |
223 | 272 int y) |
273 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
274 viewport->MouseMove(x, y, std::vector<Deprecated::Touch>()); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
275 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
276 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
277 void GetTouchVector(std::vector<Deprecated::Touch>& output, |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
278 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
279 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
280 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
281 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
282 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
283 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
284 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
285 { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
286 // 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++ |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
287 if (touchCount > 0) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
288 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
289 output.push_back(Deprecated::Touch(x0, y0)); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
290 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
291 if (touchCount > 1) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
292 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
293 output.push_back(Deprecated::Touch(x1, y1)); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
294 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
295 if (touchCount > 2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
296 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
297 output.push_back(Deprecated::Touch(x2, y2)); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
298 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
299 |
223 | 300 } |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
301 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
302 void EMSCRIPTEN_KEEPALIVE ViewportTouchStart(ViewportHandle viewport, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
303 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
304 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
305 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
306 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
307 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
308 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
309 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
310 { |
838 | 311 // printf("touch start with %d touches\n", touchCount); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
312 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
313 std::vector<Deprecated::Touch> touches; |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
314 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
315 viewport->TouchStart(touches); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
316 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
317 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
318 void EMSCRIPTEN_KEEPALIVE ViewportTouchMove(ViewportHandle viewport, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
319 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
320 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
321 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
322 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
323 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
324 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
325 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
326 { |
838 | 327 // printf("touch move with %d touches\n", touchCount); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
328 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
329 std::vector<Deprecated::Touch> touches; |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
330 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
331 viewport->TouchMove(touches); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
332 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
333 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
334 void EMSCRIPTEN_KEEPALIVE ViewportTouchEnd(ViewportHandle viewport, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
335 int touchCount, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
336 float x0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
337 float y0, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
338 float x1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
339 float y1, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
340 float x2, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
341 float y2) |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
342 { |
838 | 343 // printf("touch end with %d touches remaining\n", touchCount); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
344 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
345 std::vector<Deprecated::Touch> touches; |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
346 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
347 viewport->TouchEnd(touches); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
348 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
431
diff
changeset
|
349 |
228 | 350 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, |
327 | 351 int key, |
352 const char* keyChar, | |
223 | 353 bool isShiftPressed, |
354 bool isControlPressed, | |
355 bool isAltPressed) | |
356 | |
357 { | |
228 | 358 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; |
359 if (isShiftPressed) { | |
360 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Shift); | |
223 | 361 } |
228 | 362 if (isControlPressed) { |
363 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Control); | |
364 } | |
365 if (isAltPressed) { | |
366 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Alt); | |
367 } | |
327 | 368 |
369 char c = 0; | |
370 if (keyChar != NULL && key == OrthancStone::KeyboardKeys_Generic) { | |
371 c = keyChar[0]; | |
372 } | |
373 viewport->KeyPressed(static_cast<OrthancStone::KeyboardKeys>(key), c, modifiers); | |
223 | 374 } |
375 | |
376 | |
228 | 377 void EMSCRIPTEN_KEEPALIVE ViewportMouseUp(ViewportHandle viewport) |
223 | 378 { |
228 | 379 viewport->MouseUp(); |
223 | 380 } |
381 | |
382 | |
228 | 383 void EMSCRIPTEN_KEEPALIVE ViewportMouseEnter(ViewportHandle viewport) |
223 | 384 { |
228 | 385 viewport->MouseEnter(); |
223 | 386 } |
387 | |
388 | |
228 | 389 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport) |
223 | 390 { |
228 | 391 viewport->MouseLeave(); |
223 | 392 } |
393 | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
394 const char* EMSCRIPTEN_KEEPALIVE SendSerializedMessageToStoneApplication(const char* message) |
287 | 395 { |
396 static std::string output; // we don't want the string to be deallocated when we return to JS code so we always use the same string (this is fine since JS is single-thread) | |
397 | |
838 | 398 //printf("SendSerializedMessageToStoneApplication\n"); |
399 //printf("%s", message); | |
307 | 400 |
401 if (applicationWasmAdapter.get() != NULL) { | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
402 applicationWasmAdapter->HandleSerializedMessageFromWeb(output, std::string(message)); |
287 | 403 return output.c_str(); |
404 } | |
838 | 405 printf("This Stone application does not have a Web Adapter, unable to send messages"); |
307 | 406 return NULL; |
287 | 407 } |
408 | |
223 | 409 #ifdef __cplusplus |
410 } | |
411 #endif |