annotate Platforms/Wasm/Defaults.cpp @ 427:3f9017db1738 am-vsol-upgrade-radiography-export

wip
author am@osimis.io
date Fri, 23 Nov 2018 16:06:23 +0100
parents c23df8b3433b
children 26b90b110719
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"
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
4 #include <Framework/dev.h>
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
5 #include "Framework/Widgets/TestCairoWidget.h"
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
6 #include <Framework/Viewport/WidgetViewport.h>
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
7 #include <algorithm>
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
8 #include "Applications/Wasm/StartupParametersBuilder.h"
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
9 #include "Platforms/Wasm/WasmPlatformApplicationAdapter.h"
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
10
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
11 static unsigned int width_ = 0;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
12 static unsigned int height_ = 0;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
13
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
288
8c8da145fefa renamings and doc
am@osimis.io
parents: 287
diff changeset
16 static std::unique_ptr<OrthancStone::IStoneApplication> application;
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
17 static std::unique_ptr<OrthancStone::WasmPlatformApplicationAdapter> applicationWasmAdapter = NULL;
288
8c8da145fefa renamings and doc
am@osimis.io
parents: 287
diff changeset
18 static std::unique_ptr<OrthancStone::StoneApplicationContext> context;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
19 static OrthancStone::StartupParametersBuilder startupParametersBuilder;
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 242
diff changeset
20 static OrthancStone::MessageBroker broker;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
21
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
22 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_(broker);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
23 static OrthancStone::StatusBar statusBar_;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
24
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
25 static std::list<std::shared_ptr<OrthancStone::WidgetViewport>> viewports_;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
26
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
27 std::shared_ptr<OrthancStone::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
28 for (const auto& v : viewports_) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
29 if (v.get() == viewport) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
30 return v;
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
31 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
32 }
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
33 assert(false);
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
34 return std::shared_ptr<OrthancStone::WidgetViewport>();
228
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
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
37 #ifdef __cplusplus
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
38 extern "C" {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
39 #endif
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
40
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
41 using namespace OrthancStone;
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
42
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
43 // when WASM needs a C++ viewport
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
44 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
45
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
46 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport(broker));
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
47 printf("viewport %x\n", (int)viewport.get());
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
48
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
49 viewports_.push_back(viewport);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
50
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
51 printf("There are now %d viewports in C++\n", viewports_.size());
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 viewport->SetStatusBar(statusBar_);
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
54
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
55 viewport->RegisterObserverCallback(
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
56 new Callable<ViewportContentChangedObserver, IViewport::ViewportChangedMessage>
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
57 (viewportContentChangedObserver_, &ViewportContentChangedObserver::OnViewportChanged));
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
58
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
59 return viewport.get();
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
60 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
61
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
62 // 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
63 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
64 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
65
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
66 printf("There are now %d viewports in C++\n", viewports_.size());
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
67 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
68
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
69 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) {
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
70
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
71 printf("CreateWasmApplication\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
72
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 242
diff changeset
73 application.reset(CreateUserApplication(broker));
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
74 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get()));
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
75 WasmWebService::SetBroker(broker);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
76
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
77 startupParametersBuilder.Clear();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
78 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
79
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
80 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
81 const char* value) {
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
82 startupParametersBuilder.SetStartupParameter(keyc, value);
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
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
85 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri) {
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
86
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
87 printf("StartWasmApplication\n");
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 // recreate a command line from uri arguments and parse it
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
90 boost::program_options::variables_map parameters;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
91 boost::program_options::options_description options;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
92 application->DeclareStartupOptions(options);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
93 startupParametersBuilder.GetStartupParameters(parameters, options);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
94
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
95 context.reset(new OrthancStone::StoneApplicationContext(broker));
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
96 context->SetOrthancBaseUrl(baseUri);
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
97 printf("Base URL to Orthanc API: [%s]\n", baseUri);
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
98 context->SetWebService(OrthancStone::WasmWebService::GetInstance());
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
99 application->Initialize(context.get(), statusBar_, parameters);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
100 application->InitializeWasm();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
101
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 229
diff changeset
102 // viewport->SetSize(width_, height_);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
103 printf("StartWasmApplication - completed\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
104 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
105
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
106 void EMSCRIPTEN_KEEPALIVE WasmDoAnimation()
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
107 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
108 for (auto viewport : viewports_) {
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
109 // TODO Only launch the JavaScript timer if "HasAnimation()"
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
110 if (viewport->HasAnimation())
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
111 {
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 385
diff changeset
112 viewport->DoAnimation();
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
113 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
114
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
115 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
116
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
117 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
118
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
119
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
120 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
121 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
122 width_ = width;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
123 height_ = height;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
124
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
125 viewport->SetSize(width, height);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
126 }
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 int EMSCRIPTEN_KEEPALIVE ViewportRender(ViewportHandle viewport,
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
129 unsigned int width,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
130 unsigned int height,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
131 uint8_t* data)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
132 {
278
8a86695fcbc3 renamings
am@osimis.io
parents: 272
diff changeset
133 viewportContentChangedObserver_.Reset();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
134
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
135 //printf("ViewportRender called %dx%d\n", width, height);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
136 if (width == 0 ||
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
137 height == 0)
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 return 1;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
140 }
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 Orthanc::ImageAccessor surface;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
143 surface.AssignWritable(Orthanc::PixelFormat_BGRA32, width, height, 4 * width, data);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
144
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
145 viewport->Render(surface);
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 // Convert from BGRA32 memory layout (only color mode supported by
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
148 // Cairo, which corresponds to CAIRO_FORMAT_ARGB32) to RGBA32 (as
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
149 // expected by HTML5 canvas). This simply amounts to swapping the
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
150 // B and R channels.
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
151 uint8_t* p = data;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
152 for (unsigned int y = 0; y < height; y++) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
153 for (unsigned int x = 0; x < width; x++) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
154 uint8_t tmp = p[0];
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
155 p[0] = p[2];
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
156 p[2] = tmp;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
157
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
158 p += 4;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
159 }
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 return 1;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
163 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
164
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
165
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
166 void EMSCRIPTEN_KEEPALIVE ViewportMouseDown(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
167 unsigned int rawButton,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
168 int x,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
169 int y,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
170 unsigned int rawModifiers)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
171 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
172 OrthancStone::MouseButton button;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
173 switch (rawButton)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
174 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
175 case 0:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
176 button = OrthancStone::MouseButton_Left;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
177 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
178
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
179 case 1:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
180 button = OrthancStone::MouseButton_Middle;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
181 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
182
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
183 case 2:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
184 button = OrthancStone::MouseButton_Right;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
185 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
186
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
187 default:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
188 return; // Unknown button
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
189 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
190
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
191 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None /* TODO */);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
192 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
193
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
194
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
195 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
196 int deltaY,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
197 int x,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
198 int y,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
199 int isControl)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
200 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
201 if (deltaY != 0)
223
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 OrthancStone::MouseWheelDirection direction = (deltaY < 0 ?
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
204 OrthancStone::MouseWheelDirection_Up :
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
205 OrthancStone::MouseWheelDirection_Down);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
206 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
207
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
208 if (isControl != 0)
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 modifiers = OrthancStone::KeyboardModifiers_Control;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
211 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
212
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
213 viewport->MouseWheel(direction, x, y, modifiers);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
214 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
215 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
216
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
217
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
218 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
219 int x,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
220 int y)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
221 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
222 viewport->MouseMove(x, y);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
223 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
224
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
225 void EMSCRIPTEN_KEEPALIVE ViewportKeyPressed(ViewportHandle viewport,
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
226 int key,
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
227 const char* keyChar,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
228 bool isShiftPressed,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
229 bool isControlPressed,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
230 bool isAltPressed)
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 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None;
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
234 if (isShiftPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
235 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Shift);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
236 }
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
237 if (isControlPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
238 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Control);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
239 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
240 if (isAltPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
241 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Alt);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
242 }
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
243
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
244 char c = 0;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
245 if (keyChar != NULL && key == OrthancStone::KeyboardKeys_Generic) {
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
246 c = keyChar[0];
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
247 }
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 309
diff changeset
248 viewport->KeyPressed(static_cast<OrthancStone::KeyboardKeys>(key), c, modifiers);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
249 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
250
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
251
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
252 void EMSCRIPTEN_KEEPALIVE ViewportMouseUp(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
253 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
254 viewport->MouseUp();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
255 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
256
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
257
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
258 void EMSCRIPTEN_KEEPALIVE ViewportMouseEnter(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
259 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
260 viewport->MouseEnter();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
261 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
262
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
263
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
264 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
265 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
266 viewport->MouseLeave();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
267 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
268
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
269 const char* EMSCRIPTEN_KEEPALIVE SendMessageToStoneApplication(const char* message)
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
270 {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
271 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
272
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
273 printf("SendMessageToStoneApplication\n");
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 307
diff changeset
274 printf("%s", message);
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
275
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
276 if (applicationWasmAdapter.get() != NULL) {
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
277 printf("sending message to C++\n");
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
278 applicationWasmAdapter->HandleMessageFromWeb(output, std::string(message));
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
279 return output.c_str();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
280 }
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
281 printf("This stone application does not have a Web Adapter");
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 288
diff changeset
282 return NULL;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
283 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 278
diff changeset
284
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
285
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
286 #ifdef __cplusplus
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
287 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
288 #endif