Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/Defaults.cpp @ 823:467d58a59718
wheel
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 May 2019 14:44:37 +0200 |
parents | c35e98d22764 |
children | 238693c3bc51 |
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 | |
44 using namespace OrthancStone; | |
227 | 45 |
46 // when WASM needs a C++ viewport | |
47 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { | |
48 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
49 std::shared_ptr<Deprecated::WidgetViewport> viewport(new Deprecated::WidgetViewport(broker)); |
287 | 50 printf("viewport %x\n", (int)viewport.get()); |
227 | 51 |
52 viewports_.push_back(viewport); | |
53 | |
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
|
54 printf("There are now %lu viewports in C++\n", viewports_.size()); |
227 | 55 |
56 viewport->SetStatusBar(statusBar_); | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
57 |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
58 viewport->RegisterObserverCallback( |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
59 new Callable<ViewportContentChangedObserver, Deprecated::IViewport::ViewportChangedMessage> |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
60 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged)); |
227 | 61 |
62 return viewport.get(); | |
63 } | |
64 | |
65 // when WASM does not need a viewport anymore, it should release it | |
66 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
|
67 viewports_.remove_if([viewport](const std::shared_ptr<Deprecated::WidgetViewport>& v) { return v.get() == viewport;}); |
227 | 68 |
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
|
69 printf("There are now %lu viewports in C++\n", viewports_.size()); |
227 | 70 } |
71 | |
72 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | |
223 | 73 |
74 printf("CreateWasmApplication\n"); | |
75 | |
253 | 76 application.reset(CreateUserApplication(broker)); |
307 | 77 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
|
78 Deprecated::WasmWebService::SetBroker(broker); |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
79 Deprecated::WasmDelayedCallExecutor::SetBroker(broker); |
223 | 80 |
242 | 81 startupParametersBuilder.Clear(); |
223 | 82 } |
83 | |
84 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc, | |
85 const char* value) { | |
242 | 86 startupParametersBuilder.SetStartupParameter(keyc, value); |
223 | 87 } |
88 | |
418 | 89 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri) { |
223 | 90 |
91 printf("StartWasmApplication\n"); | |
92 | |
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
|
93 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
|
94 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
|
95 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
|
96 |
223 | 97 // recreate a command line from uri arguments and parse it |
98 boost::program_options::variables_map parameters; | |
242 | 99 boost::program_options::options_description options; |
100 application->DeclareStartupOptions(options); | |
101 startupParametersBuilder.GetStartupParameters(parameters, options); | |
223 | 102 |
418 | 103 context.reset(new OrthancStone::StoneApplicationContext(broker)); |
104 context->SetOrthancBaseUrl(baseUri); | |
105 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
|
106 context->SetWebService(Deprecated::WasmWebService::GetInstance()); |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
107 context->SetDelayedCallExecutor(Deprecated::WasmDelayedCallExecutor::GetInstance()); |
242 | 108 application->Initialize(context.get(), statusBar_, parameters); |
109 application->InitializeWasm(); | |
223 | 110 |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
229
diff
changeset
|
111 // viewport->SetSize(width_, height_); |
223 | 112 printf("StartWasmApplication - completed\n"); |
113 } | |
114 | |
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
|
115 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
|
116 { |
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
|
117 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
|
118 } |
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
|
119 |
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
|
120 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
|
121 { |
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
|
122 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
|
123 } |
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
|
124 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
125 void EMSCRIPTEN_KEEPALIVE WasmDoAnimation() |
223 | 126 { |
228 | 127 for (auto viewport : viewports_) { |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
128 // TODO Only launch the JavaScript timer if "HasAnimation()" |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
129 if (viewport->HasAnimation()) |
228 | 130 { |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
131 viewport->DoAnimation(); |
228 | 132 } |
133 | |
223 | 134 } |
135 | |
136 } | |
137 | |
138 | |
228 | 139 void EMSCRIPTEN_KEEPALIVE ViewportSetSize(ViewportHandle viewport, unsigned int width, unsigned int height) |
223 | 140 { |
141 width_ = width; | |
142 height_ = height; | |
143 | |
228 | 144 viewport->SetSize(width, height); |
223 | 145 } |
146 | |
228 | 147 int EMSCRIPTEN_KEEPALIVE ViewportRender(ViewportHandle viewport, |
227 | 148 unsigned int width, |
223 | 149 unsigned int height, |
150 uint8_t* data) | |
151 { | |
278 | 152 viewportContentChangedObserver_.Reset(); |
223 | 153 |
154 //printf("ViewportRender called %dx%d\n", width, height); | |
155 if (width == 0 || | |
156 height == 0) | |
157 { | |
158 return 1; | |
159 } | |
160 | |
161 Orthanc::ImageAccessor surface; | |
162 surface.AssignWritable(Orthanc::PixelFormat_BGRA32, width, height, 4 * width, data); | |
163 | |
227 | 164 viewport->Render(surface); |
223 | 165 |
166 // Convert from BGRA32 memory layout (only color mode supported by | |
167 // Cairo, which corresponds to CAIRO_FORMAT_ARGB32) to RGBA32 (as | |
168 // expected by HTML5 canvas). This simply amounts to swapping the | |
169 // B and R channels. | |
170 uint8_t* p = data; | |
171 for (unsigned int y = 0; y < height; y++) { | |
172 for (unsigned int x = 0; x < width; x++) { | |
173 uint8_t tmp = p[0]; | |
174 p[0] = p[2]; | |
175 p[2] = tmp; | |
176 | |
177 p += 4; | |
178 } | |
179 } | |
180 | |
181 return 1; | |
182 } | |
183 | |
184 | |
228 | 185 void EMSCRIPTEN_KEEPALIVE ViewportMouseDown(ViewportHandle viewport, |
186 unsigned int rawButton, | |
223 | 187 int x, |
188 int y, | |
189 unsigned int rawModifiers) | |
190 { | |
191 OrthancStone::MouseButton button; | |
192 switch (rawButton) | |
193 { | |
194 case 0: | |
195 button = OrthancStone::MouseButton_Left; | |
196 break; | |
197 | |
198 case 1: | |
199 button = OrthancStone::MouseButton_Middle; | |
200 break; | |
201 | |
202 case 2: | |
203 button = OrthancStone::MouseButton_Right; | |
204 break; | |
205 | |
206 default: | |
207 return; // Unknown button | |
208 } | |
209 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
210 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<Deprecated::Touch>()); |
223 | 211 } |
212 | |
213 | |
228 | 214 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport, |
215 int deltaY, | |
223 | 216 int x, |
217 int y, | |
218 int isControl) | |
219 { | |
228 | 220 if (deltaY != 0) |
223 | 221 { |
222 OrthancStone::MouseWheelDirection direction = (deltaY < 0 ? | |
223 OrthancStone::MouseWheelDirection_Up : | |
224 OrthancStone::MouseWheelDirection_Down); | |
225 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; | |
226 | |
227 if (isControl != 0) | |
228 { | |
229 modifiers = OrthancStone::KeyboardModifiers_Control; | |
230 } | |
231 | |
228 | 232 viewport->MouseWheel(direction, x, y, modifiers); |
223 | 233 } |
234 } | |
235 | |
236 | |
228 | 237 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport, |
238 int x, | |
223 | 239 int y) |
240 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
241 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
|
242 } |
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
|
243 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 { |
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
|
253 // 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
|
254 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
|
255 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
256 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
|
257 } |
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
|
258 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
|
259 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
260 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
|
261 } |
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
|
262 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
|
263 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
264 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
|
265 } |
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
|
266 |
223 | 267 } |
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
|
268 |
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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 { |
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 printf("touch start with %d touches\n", 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 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 } |
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 |
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 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 { |
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 printf("touch move with %d touches\n", 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
|
295 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 } |
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
|
300 |
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 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 { |
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 printf("touch end with %d touches remaining\n", 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
|
311 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
603
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 } |
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 |
228 | 317 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport, |
327 | 318 int key, |
319 const char* keyChar, | |
223 | 320 bool isShiftPressed, |
321 bool isControlPressed, | |
322 bool isAltPressed) | |
323 | |
324 { | |
228 | 325 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; |
326 if (isShiftPressed) { | |
327 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Shift); | |
223 | 328 } |
228 | 329 if (isControlPressed) { |
330 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Control); | |
331 } | |
332 if (isAltPressed) { | |
333 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Alt); | |
334 } | |
327 | 335 |
336 char c = 0; | |
337 if (keyChar != NULL && key == OrthancStone::KeyboardKeys_Generic) { | |
338 c = keyChar[0]; | |
339 } | |
340 viewport->KeyPressed(static_cast<OrthancStone::KeyboardKeys>(key), c, modifiers); | |
223 | 341 } |
342 | |
343 | |
228 | 344 void EMSCRIPTEN_KEEPALIVE ViewportMouseUp(ViewportHandle viewport) |
223 | 345 { |
228 | 346 viewport->MouseUp(); |
223 | 347 } |
348 | |
349 | |
228 | 350 void EMSCRIPTEN_KEEPALIVE ViewportMouseEnter(ViewportHandle viewport) |
223 | 351 { |
228 | 352 viewport->MouseEnter(); |
223 | 353 } |
354 | |
355 | |
228 | 356 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport) |
223 | 357 { |
228 | 358 viewport->MouseLeave(); |
223 | 359 } |
360 | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
361 const char* EMSCRIPTEN_KEEPALIVE SendSerializedMessageToStoneApplication(const char* message) |
287 | 362 { |
363 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) | |
364 | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
365 printf("SendSerializedMessageToStoneApplication\n"); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
366 printf("%s", message); |
307 | 367 |
368 if (applicationWasmAdapter.get() != NULL) { | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
369 applicationWasmAdapter->HandleSerializedMessageFromWeb(output, std::string(message)); |
287 | 370 return output.c_str(); |
371 } | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
458
diff
changeset
|
372 printf("This Stone application does not have a Web Adapter"); |
307 | 373 return NULL; |
287 | 374 } |
375 | |
223 | 376 #ifdef __cplusplus |
377 } | |
378 #endif |