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