annotate Platforms/Wasm/Defaults.cpp @ 920:5ca418d6579e refactor-viewport-controller

Close branch refactor-viewport-controller.
author Alain Mazy <am@osimis.io>
date Fri, 19 Jul 2019 14:15:49 +0000
parents 70992b38aa8a
children 4f2416d519b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
222
84844649a8fd continued: reusable applications
am@osimis.io
parents:
diff changeset
1 #include "Defaults.h"
84844649a8fd continued: reusable applications
am@osimis.io
parents:
diff changeset
2
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
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"
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
5 #include <Framework/dev.h>
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
6 #include "Framework/Widgets/TestCairoWidget.h"
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
7 #include <Framework/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
8 #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
9 #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
10 #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
11
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
12 #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
13
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
14
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
15 static unsigned int width_ = 0;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
16 static unsigned int height_ = 0;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
17
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
18 /**********************************/
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
19
288
8c8da145fefa renamings and doc
am@osimis.io
parents: 287
diff changeset
20 static std::unique_ptr<OrthancStone::IStoneApplication> application;
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
21 static std::unique_ptr<OrthancStone::WasmPlatformApplicationAdapter> applicationWasmAdapter = NULL;
288
8c8da145fefa renamings and doc
am@osimis.io
parents: 287
diff changeset
22 static std::unique_ptr<OrthancStone::StoneApplicationContext> context;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
23 static OrthancStone::StartupParametersBuilder startupParametersBuilder;
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 242
diff changeset
24 static OrthancStone::MessageBroker broker;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
25
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
26 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_(broker);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
27 static OrthancStone::StatusBar statusBar_;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
28
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
29 static std::list<std::shared_ptr<OrthancStone::WidgetViewport>> viewports_;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
30
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
31 std::shared_ptr<OrthancStone::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
32 for (const auto& v : viewports_) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
33 if (v.get() == viewport) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
34 return v;
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
35 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
36 }
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
37 assert(false);
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
38 return std::shared_ptr<OrthancStone::WidgetViewport>();
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
39 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
40
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
41 #ifdef __cplusplus
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
42 extern "C" {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
43 #endif
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
44
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
45 using namespace OrthancStone;
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
46
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
47 // when WASM needs a C++ viewport
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
48 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
49
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
50 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport(broker));
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
51 printf("viewport %x\n", (int)viewport.get());
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
52
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
53 viewports_.push_back(viewport);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
54
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
55 printf("There are now %lu viewports in C++\n", viewports_.size());
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
56
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
57 viewport->SetStatusBar(statusBar_);
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
58
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
59 viewport->RegisterObserverCallback(
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
60 new Callable<ViewportContentChangedObserver, IViewport::ViewportChangedMessage>
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
61 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged));
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
62
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
63 return viewport.get();
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
64 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
65
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
66 // when WASM does not need a viewport anymore, it should release it
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
67 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
68 viewports_.remove_if([viewport](const std::shared_ptr<OrthancStone::WidgetViewport>& v) { return v.get() == viewport;});
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
69
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
70 printf("There are now %lu viewports in C++\n", viewports_.size());
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
71 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
72
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
73 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) {
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
74
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
75 printf("CreateWasmApplication\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
76
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 242
diff changeset
77 application.reset(CreateUserApplication(broker));
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
78 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get()));
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
79 WasmWebService::SetBroker(broker);
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
80 WasmDelayedCallExecutor::SetBroker(broker);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
81
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
82 startupParametersBuilder.Clear();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
83 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
84
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
85 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
86 const char* value) {
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
87 startupParametersBuilder.SetStartupParameter(keyc, value);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
88 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
89
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
90 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri) {
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
91
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
92 printf("StartWasmApplication\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
93
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
94 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
95 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
96 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
97
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
98 // recreate a command line from uri arguments and parse it
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
99 boost::program_options::variables_map parameters;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
100 boost::program_options::options_description options;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
101 application->DeclareStartupOptions(options);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
102 startupParametersBuilder.GetStartupParameters(parameters, options);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
103
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
104 context.reset(new OrthancStone::StoneApplicationContext(broker));
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
105 context->SetOrthancBaseUrl(baseUri);
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
106 printf("Base URL to Orthanc API: [%s]\n", baseUri);
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
107 context->SetWebService(OrthancStone::WasmWebService::GetInstance());
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
108 context->SetDelayedCallExecutor(OrthancStone::WasmDelayedCallExecutor::GetInstance());
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
109 application->Initialize(context.get(), statusBar_, parameters);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
110 application->InitializeWasm();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
111
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 229
diff changeset
112 // viewport->SetSize(width_, height_);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
113 printf("StartWasmApplication - completed\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
114 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
115
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
116 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
117 {
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 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
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
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 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
122 {
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 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
124 }
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
125
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
126 void EMSCRIPTEN_KEEPALIVE WasmDoAnimation()
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
127 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
128 for (auto viewport : viewports_) {
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
129 // TODO Only launch the JavaScript timer if "HasAnimation()"
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
130 if (viewport->HasAnimation())
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
131 {
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
132 viewport->DoAnimation();
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
133 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
134
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
135 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
136
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
137 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
138
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
139
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
140 void EMSCRIPTEN_KEEPALIVE ViewportSetSize(ViewportHandle viewport, unsigned int width, unsigned int height)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
141 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
142 width_ = width;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
143 height_ = height;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
144
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
145 viewport->SetSize(width, height);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
146 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
147
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
148 int EMSCRIPTEN_KEEPALIVE ViewportRender(ViewportHandle viewport,
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
149 unsigned int width,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
150 unsigned int height,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
151 uint8_t* data)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
152 {
278
8a86695fcbc3 renamings
am@osimis.io
parents: 272
diff changeset
153 viewportContentChangedObserver_.Reset();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
154
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
155 //printf("ViewportRender called %dx%d\n", width, height);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
156 if (width == 0 ||
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
157 height == 0)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
158 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
159 return 1;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
160 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
161
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
162 Orthanc::ImageAccessor surface;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
163 surface.AssignWritable(Orthanc::PixelFormat_BGRA32, width, height, 4 * width, data);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
164
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
165 viewport->Render(surface);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
166
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
167 // Convert from BGRA32 memory layout (only color mode supported by
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
168 // Cairo, which corresponds to CAIRO_FORMAT_ARGB32) to RGBA32 (as
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
169 // expected by HTML5 canvas). This simply amounts to swapping the
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
170 // B and R channels.
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
171 uint8_t* p = data;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
172 for (unsigned int y = 0; y < height; y++) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
173 for (unsigned int x = 0; x < width; x++) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
174 uint8_t tmp = p[0];
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
175 p[0] = p[2];
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
176 p[2] = tmp;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
177
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
178 p += 4;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
179 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
180 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
181
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
182 return 1;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
183 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
184
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
185
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
186 void EMSCRIPTEN_KEEPALIVE ViewportMouseDown(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
187 unsigned int rawButton,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
188 int x,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
189 int y,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
190 unsigned int rawModifiers)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
191 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
192 OrthancStone::MouseButton button;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
193 switch (rawButton)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
194 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
195 case 0:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
196 button = OrthancStone::MouseButton_Left;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
197 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
198
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
199 case 1:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
200 button = OrthancStone::MouseButton_Middle;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
201 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
202
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
203 case 2:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
204 button = OrthancStone::MouseButton_Right;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
205 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
206
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
207 default:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
208 return; // Unknown button
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
209 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
210
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
211 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None, std::vector<OrthancStone::Touch>());
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
212 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
213
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
214
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
215 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
216 int deltaY,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
217 int x,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
218 int y,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
219 int isControl)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
220 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
221 if (deltaY != 0)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
222 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
223 OrthancStone::MouseWheelDirection direction = (deltaY < 0 ?
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
224 OrthancStone::MouseWheelDirection_Up :
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
225 OrthancStone::MouseWheelDirection_Down);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
226 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
227
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
228 if (isControl != 0)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
229 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
230 modifiers = OrthancStone::KeyboardModifiers_Control;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
231 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
232
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
233 viewport->MouseWheel(direction, x, y, modifiers);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
234 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
235 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
236
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
237
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
238 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
239 int x,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
240 int y)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
241 {
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 viewport->MouseMove(x, y, std::vector<OrthancStone::Touch>());
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 }
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
244
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 void GetTouchVector(std::vector<OrthancStone::Touch>& output,
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 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
247 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
248 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
249 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
250 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
251 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
252 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
253 {
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 // 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
255 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
256 {
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 output.push_back(OrthancStone::Touch(x0, 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
258 }
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 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
260 {
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 output.push_back(OrthancStone::Touch(x1, 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
262 }
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 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
264 {
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 output.push_back(OrthancStone::Touch(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
266 }
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
267
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
268 }
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
269
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 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 {
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 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
280
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 std::vector<OrthancStone::Touch> 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
282 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
283 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
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
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 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
287 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
288 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
289 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
290 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
291 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
292 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
293 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
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 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
296
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 std::vector<OrthancStone::Touch> 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
298 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
299 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
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
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 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
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 {
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 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
312
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 std::vector<OrthancStone::Touch> 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
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->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
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
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
318 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport,
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
319 int key,
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
320 const char* keyChar,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
321 bool isShiftPressed,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
322 bool isControlPressed,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
323 bool isAltPressed)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
324
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
325 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
326 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None;
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
327 if (isShiftPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
328 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Shift);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
329 }
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
330 if (isControlPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
331 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Control);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
332 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
333 if (isAltPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
334 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Alt);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
335 }
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
336
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
337 char c = 0;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
338 if (keyChar != NULL && key == OrthancStone::KeyboardKeys_Generic) {
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
339 c = keyChar[0];
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
340 }
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
341 viewport->KeyPressed(static_cast<OrthancStone::KeyboardKeys>(key), c, modifiers);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
342 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
343
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
344
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
345 void EMSCRIPTEN_KEEPALIVE ViewportMouseUp(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
346 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
347 viewport->MouseUp();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
348 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
349
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
350
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
351 void EMSCRIPTEN_KEEPALIVE ViewportMouseEnter(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
352 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
353 viewport->MouseEnter();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
354 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
355
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
356
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
357 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
358 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
359 viewport->MouseLeave();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
360 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
361
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 458
diff changeset
362 const char* EMSCRIPTEN_KEEPALIVE SendSerializedMessageToStoneApplication(const char* message)
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
363 {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
364 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)
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
365
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 458
diff changeset
366 printf("SendSerializedMessageToStoneApplication\n");
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 458
diff changeset
367 printf("%s", message);
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
368
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
369 if (applicationWasmAdapter.get() != NULL) {
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 458
diff changeset
370 applicationWasmAdapter->HandleSerializedMessageFromWeb(output, std::string(message));
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
371 return output.c_str();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
372 }
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 458
diff changeset
373 printf("This Stone application does not have a Web Adapter");
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
374 return NULL;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
375 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
376
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
377 #ifdef __cplusplus
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
378 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
379 #endif