annotate Platforms/Wasm/Defaults.cpp @ 272:d7d91d96b9d8 am-2

fix
author am@osimis.io
date Fri, 24 Aug 2018 09:11:06 +0200
parents 65562a28fe05
children 8a86695fcbc3
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>
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
7 #include <Framework/Widgets/LayerWidget.h>
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
8 #include <algorithm>
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
9 #include "Applications/Wasm/StartupParametersBuilder.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
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
16 static std::unique_ptr<OrthancStone::IBasicApplication> application;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
17 static std::unique_ptr<OrthancStone::BasicApplicationContext> context;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
18 static OrthancStone::StartupParametersBuilder startupParametersBuilder;
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 242
diff changeset
19 static OrthancStone::MessageBroker broker;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
20
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
21 static OrthancStone::ChangeObserver changeObserver_;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
22 static OrthancStone::StatusBar statusBar_;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
23
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
24 static std::list<std::shared_ptr<OrthancStone::WidgetViewport>> viewports_;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
25
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
26 std::shared_ptr<OrthancStone::WidgetViewport> FindViewportSharedPtr(ViewportHandle viewport) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
27 for (const auto& v : viewports_) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
28 if (v.get() == viewport) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
29 return v;
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
30 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
31 }
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
32 assert(false);
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
33 return std::shared_ptr<OrthancStone::WidgetViewport>();
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
34 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
35
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
36 #ifdef __cplusplus
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
37 extern "C" {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
38 #endif
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
39
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
40 using namespace OrthancStone;
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
41
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
42 // when WASM needs a C++ viewport
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
43 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
44
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
45 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
46 printf("viewport %x\n", viewport.get());
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
47
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
48 viewports_.push_back(viewport);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
49
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
50 printf("There are now %d viewports in C++\n", viewports_.size());
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
51
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
52 viewport->SetStatusBar(statusBar_);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
53 viewport->Register(changeObserver_);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
54
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
55 return viewport.get();
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
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
58 // 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
59 void EMSCRIPTEN_KEEPALIVE ReleaseCppViewport(ViewportHandle viewport) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
60 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
61
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
62 printf("There are now %d viewports in C++\n", viewports_.size());
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
63 }
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 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) {
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
66
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
67 printf("CreateWasmApplication\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
68
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 242
diff changeset
69 application.reset(CreateUserApplication(broker));
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
70 WasmWebService::SetBroker(broker);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
71
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
72 startupParametersBuilder.Clear();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
73 }
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 void EMSCRIPTEN_KEEPALIVE SetStartupParameter(const char* keyc,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
76 const char* value) {
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
77 startupParametersBuilder.SetStartupParameter(keyc, value);
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
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 229
diff changeset
80 void EMSCRIPTEN_KEEPALIVE StartWasmApplication() {
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
81
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
82 printf("StartWasmApplication\n");
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 // recreate a command line from uri arguments and parse it
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
85 boost::program_options::variables_map parameters;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
86 boost::program_options::options_description options;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
87 application->DeclareStartupOptions(options);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
88 startupParametersBuilder.GetStartupParameters(parameters, options);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
89
272
am@osimis.io
parents: 255
diff changeset
90 context.reset(new OrthancStone::BasicApplicationContext());
am@osimis.io
parents: 255
diff changeset
91 context->SetWebService(OrthancStone::WasmWebService::GetInstance());
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
92 application->Initialize(context.get(), statusBar_, parameters);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 236
diff changeset
93 application->InitializeWasm();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
94
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 229
diff changeset
95 // viewport->SetSize(width_, height_);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
96 printf("StartWasmApplication - completed\n");
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
97 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
98
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
99 void EMSCRIPTEN_KEEPALIVE NotifyUpdateContent()
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
100 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
101 for (auto viewport : viewports_) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
102 // TODO Only launch the JavaScript timer if "HasUpdateContent()"
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
103 if (viewport->HasUpdateContent())
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
104 {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
105 viewport->UpdateContent();
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
106 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
107
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
108 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
109
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
110 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
111
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
112
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
113 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
114 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
115 width_ = width;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
116 height_ = height;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
117
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
118 viewport->SetSize(width, height);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
119 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
120
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
121 int EMSCRIPTEN_KEEPALIVE ViewportRender(ViewportHandle viewport,
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
122 unsigned int width,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
123 unsigned int height,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
124 uint8_t* data)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
125 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
126 changeObserver_.Reset();
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
127
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
128 //printf("ViewportRender called %dx%d\n", width, height);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
129 if (width == 0 ||
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
130 height == 0)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
131 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
132 return 1;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
133 }
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 Orthanc::ImageAccessor surface;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
136 surface.AssignWritable(Orthanc::PixelFormat_BGRA32, width, height, 4 * width, data);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
137
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 223
diff changeset
138 viewport->Render(surface);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
139
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
140 // Convert from BGRA32 memory layout (only color mode supported by
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
141 // Cairo, which corresponds to CAIRO_FORMAT_ARGB32) to RGBA32 (as
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
142 // expected by HTML5 canvas). This simply amounts to swapping the
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
143 // B and R channels.
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
144 uint8_t* p = data;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
145 for (unsigned int y = 0; y < height; y++) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
146 for (unsigned int x = 0; x < width; x++) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
147 uint8_t tmp = p[0];
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
148 p[0] = p[2];
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
149 p[2] = tmp;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
150
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
151 p += 4;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
152 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
153 }
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 return 1;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
156 }
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
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
159 void EMSCRIPTEN_KEEPALIVE ViewportMouseDown(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
160 unsigned int rawButton,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
161 int x,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
162 int y,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
163 unsigned int rawModifiers)
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 OrthancStone::MouseButton button;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
166 switch (rawButton)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
167 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
168 case 0:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
169 button = OrthancStone::MouseButton_Left;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
170 break;
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 case 1:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
173 button = OrthancStone::MouseButton_Middle;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
174 break;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
175
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
176 case 2:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
177 button = OrthancStone::MouseButton_Right;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
178 break;
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 default:
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
181 return; // Unknown button
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
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
184 viewport->MouseDown(button, x, y, OrthancStone::KeyboardModifiers_None /* TODO */);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
185 }
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
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
188 void EMSCRIPTEN_KEEPALIVE ViewportMouseWheel(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
189 int deltaY,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
190 int x,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
191 int y,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
192 int isControl)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
193 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
194 if (deltaY != 0)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
195 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
196 OrthancStone::MouseWheelDirection direction = (deltaY < 0 ?
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
197 OrthancStone::MouseWheelDirection_Up :
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
198 OrthancStone::MouseWheelDirection_Down);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
199 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
200
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
201 if (isControl != 0)
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 modifiers = OrthancStone::KeyboardModifiers_Control;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
204 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
205
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
206 viewport->MouseWheel(direction, x, y, modifiers);
223
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 }
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
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
211 void EMSCRIPTEN_KEEPALIVE ViewportMouseMove(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
212 int x,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
213 int y)
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 viewport->MouseMove(x, y);
223
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 ViewportKeyPressed(ViewportHandle viewport,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
219 const char* key,
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
220 bool isShiftPressed,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
221 bool isControlPressed,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
222 bool isAltPressed)
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 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None;
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
226 if (isShiftPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
227 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Shift);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
228 }
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
229 if (isControlPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
230 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Control);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
231 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
232 if (isAltPressed) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
233 modifiers = static_cast<OrthancStone::KeyboardModifiers>(modifiers + OrthancStone::KeyboardModifiers_Alt);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
234 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
235 printf("key pressed : %c\n", key[0]);
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
236 viewport->KeyPressed(key[0], modifiers);
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
237 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
238
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
239
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
240 void EMSCRIPTEN_KEEPALIVE ViewportMouseUp(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
241 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
242 viewport->MouseUp();
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
243 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
244
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
245
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
246 void EMSCRIPTEN_KEEPALIVE ViewportMouseEnter(ViewportHandle viewport)
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
247 {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
248 viewport->MouseEnter();
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 ViewportMouseLeave(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->MouseLeave();
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
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
258 #ifdef __cplusplus
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
259 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents: 222
diff changeset
260 #endif