Mercurial > hg > orthanc-stone
annotate Framework/Viewport/WebAssemblyViewport.cpp @ 1331:ab81ee8fce1f broker
- Viewport is not passed and stored as a shared_ptr instead
of raw reference.
- ViewportController can now be injected with an undo
stack (not a ctor param anymore, as a preparation for the
move of the undo stack to an interactor)
- Added (temp) flag to disable emscripten events registration
in the WebAssemblyViewport (because legacy client code
deals with them directly)
- Added emscripten_clear_timeout in ~WebGLViewportsRegistry
- Removed GenericToolbox::HoldingRef whose responsibility is
better served with proper callback un-registration.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 30 Mar 2020 14:23:46 +0200 |
parents | fd616c4a5904 |
children | df8bf351c23f |
rev | line source |
---|---|
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1239
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
16 * |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "WebAssemblyViewport.h" |
1050 | 23 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
24 #include "../Toolbox/GenericToolbox.h" |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
25 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
26 #include <Core/OrthancException.h> |
1050 | 27 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
28 #include <boost/make_shared.hpp> |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
29 #include <boost/enable_shared_from_this.hpp> |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 namespace OrthancStone |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
33 static void ConvertMouseEvent(PointerEvent& target, |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
34 const EmscriptenMouseEvent& source, |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
35 const ICompositor& compositor) |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
37 int x = static_cast<int>(source.targetX); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
38 int y = static_cast<int>(source.targetY); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
40 switch (source.button) |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
41 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
42 case 0: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
43 target.SetMouseButton(MouseButton_Left); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
44 break; |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
46 case 1: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
47 target.SetMouseButton(MouseButton_Middle); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
48 break; |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
49 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
50 case 2: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
51 target.SetMouseButton(MouseButton_Right); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
52 break; |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
53 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
54 default: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
55 target.SetMouseButton(MouseButton_None); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
56 break; |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
57 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
58 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
59 target.AddPosition(compositor.GetPixelCenterCoordinates(x, y)); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
60 target.SetAltModifier(source.altKey); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
61 target.SetControlModifier(source.ctrlKey); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
62 target.SetShiftModifier(source.shiftKey); |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
63 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
64 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
65 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
66 class WebAssemblyViewport::WasmLock : public ILock |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
67 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
68 private: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
69 WebAssemblyViewport& that_; |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
70 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
71 public: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
72 WasmLock(WebAssemblyViewport& that) : |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
73 that_(that) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
74 { |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
75 } |
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
76 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
77 virtual bool HasCompositor() const ORTHANC_OVERRIDE |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
78 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
79 return that_.compositor_.get() != NULL; |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
80 } |
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
81 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
82 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
83 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
84 if (that_.compositor_.get() == NULL) |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
85 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
87 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
88 else |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
89 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
90 return *that_.compositor_; |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
91 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
92 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
93 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
94 virtual ViewportController& GetController() ORTHANC_OVERRIDE |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
95 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
96 assert(that_.controller_); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
97 return *that_.controller_; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
98 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
99 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
100 virtual void Invalidate() ORTHANC_OVERRIDE |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
101 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
102 that_.Invalidate(); |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
103 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
104 }; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
105 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
106 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
107 EM_BOOL WebAssemblyViewport::OnRequestAnimationFrame(double time, void *userData) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
108 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
109 LOG(TRACE) << __func__; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
110 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
111 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
112 if (that->compositor_.get() != NULL && |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
113 that->controller_ /* should always be true */) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
114 { |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
115 that->Paint(*that->compositor_, *that->controller_); |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
116 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
117 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
118 LOG(TRACE) << "Exiting: " << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
119 return true; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
120 } |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
121 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
122 EM_BOOL WebAssemblyViewport::OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
123 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
124 LOG(TRACE) << __func__; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
125 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
126 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
127 if (that->compositor_.get() != NULL) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
128 { |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
129 that->UpdateSize(*that->compositor_); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
130 that->Invalidate(); |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
131 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
132 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
133 LOG(TRACE) << "Exiting: " << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
134 return true; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
135 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
136 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
137 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
138 EM_BOOL WebAssemblyViewport::OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
139 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
140 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
141 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
142 LOG(TRACE) << "mouse down: " << that->GetFullCanvasId(); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
143 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
144 if (that->compositor_.get() != NULL && |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
145 that->interactor_.get() != NULL) |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
146 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
147 PointerEvent pointer; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
148 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
149 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
150 that->controller_->HandleMousePress(*that->interactor_, pointer, |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
151 that->compositor_->GetCanvasWidth(), |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
152 that->compositor_->GetCanvasHeight()); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
153 that->Invalidate(); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
154 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
155 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
156 LOG(TRACE) << "Exiting: " << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
157 return true; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
158 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
159 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
160 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
161 EM_BOOL WebAssemblyViewport::OnMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
162 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
163 LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP1. userData = " << userData; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
164 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
165 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
166 LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP2"; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
167 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
168 if (that->compositor_.get() != NULL && |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
169 that->controller_->HasActiveTracker()) |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
170 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
171 LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP3"; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
172 PointerEvent pointer; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
173 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
174 LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP4"; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
175 if (that->controller_->HandleMouseMove(pointer)) |
1050 | 176 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
177 LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP5"; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
178 that->Invalidate(); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
179 LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP6"; |
1050 | 180 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
181 } |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
182 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
183 LOG(TRACE) << "Exiting: " << __func__; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
184 return true; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
185 } |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
186 |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
187 EM_BOOL WebAssemblyViewport::OnMouseUp(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
188 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
189 LOG(TRACE) << __func__; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
190 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
191 |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
192 if (that->compositor_.get() != NULL) |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
193 { |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
194 PointerEvent pointer; |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
195 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
196 that->controller_->HandleMouseRelease(pointer); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
197 that->Invalidate(); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
198 } |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
199 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
200 LOG(TRACE) << "Exiting: " << __func__; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
201 return true; |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
202 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
203 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
204 void WebAssemblyViewport::Invalidate() |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
205 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
206 emscripten_request_animation_frame(OnRequestAnimationFrame, reinterpret_cast<void*>(this)); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
207 } |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
208 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
209 void WebAssemblyViewport::AcquireCompositor(ICompositor* compositor /* takes ownership */) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
210 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
211 if (compositor == NULL) |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
212 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
213 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
214 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
215 else |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
216 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
217 compositor_.reset(compositor); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
218 } |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
219 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
220 |
1318
cbfdba08e039
removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
221 WebAssemblyViewport::WebAssemblyViewport( |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
222 const std::string& canvasId, bool enableEmscriptenEvents) : |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
223 shortCanvasId_(canvasId), |
1318
cbfdba08e039
removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
224 fullCanvasId_(canvasId), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
225 interactor_(new DefaultViewportInteractor), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
226 enableEmscriptenEvents_(enableEmscriptenEvents) |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
227 { |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
228 } |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
229 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
230 void WebAssemblyViewport::PostConstructor() |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
231 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
232 boost::shared_ptr<IViewport> viewport = shared_from_this(); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
233 controller_.reset(new ViewportController(viewport)); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
234 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
235 LOG(INFO) << "Initializing Stone viewport on HTML canvas: " |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
236 << shortCanvasId_; |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
237 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
238 if (shortCanvasId_.empty() || |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
239 shortCanvasId_[0] == '#') |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
240 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
241 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
242 "The canvas identifier must not start with '#'"); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
243 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
244 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
245 // Disable right-click on the canvas (i.e. context menu) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
246 EM_ASM({ |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
247 document.getElementById(UTF8ToString($0)).oncontextmenu = |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
248 function(event) |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
249 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
250 event.preventDefault(); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
251 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
252 }, |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
253 shortCanvasId_.c_str() // $0 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
254 ); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
255 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
256 if (enableEmscriptenEvents_) |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
257 { |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
258 // It is not possible to monitor the resizing of individual |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
259 // canvas, so we track the full window of the browser |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
260 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
261 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
262 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
263 OnResize); |
1318
cbfdba08e039
removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
264 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
265 emscripten_set_mousedown_callback(fullCanvasId_.c_str(), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
266 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
267 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
268 OnMouseDown); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
269 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
270 emscripten_set_mousemove_callback(fullCanvasId_.c_str(), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
271 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
272 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
273 OnMouseMove); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
274 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
275 emscripten_set_mouseup_callback(fullCanvasId_.c_str(), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
276 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
277 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
278 OnMouseUp); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
279 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
280 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
281 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
282 WebAssemblyViewport::~WebAssemblyViewport() |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
283 { |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
284 if (enableEmscriptenEvents_) |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
285 { |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
286 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
287 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
288 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
289 NULL); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
290 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
291 emscripten_set_mousedown_callback(fullCanvasId_.c_str(), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
292 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
293 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
294 OnMouseDown); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
295 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
296 emscripten_set_mousemove_callback(fullCanvasId_.c_str(), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
297 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
298 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
299 OnMouseMove); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
300 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
301 emscripten_set_mouseup_callback(fullCanvasId_.c_str(), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
302 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
303 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
304 OnMouseUp); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
305 } |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
306 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
307 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
308 IViewport::ILock* WebAssemblyViewport::Lock() |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
309 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
310 return new WasmLock(*this); |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
311 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
312 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
313 void WebAssemblyViewport::AcquireInteractor(IViewportInteractor* interactor) |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
314 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
315 if (interactor == NULL) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
316 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
317 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
318 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
319 else |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
320 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
321 interactor_.reset(interactor); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
322 } |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
323 } |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 } |