Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyViewport.cpp @ 2092:b7d4d288459a dicom-sr
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Nov 2023 10:32:16 +0100 |
parents | 07964689cb0b |
children | c23eef785569 |
rev | line source |
---|---|
1899
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 /** |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2077
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1899
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 * |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 * License along with this program. If not, see |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 **/ |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 #if defined(ORTHANC_BUILDING_STONE_LIBRARY) && ORTHANC_BUILDING_STONE_LIBRARY == 1 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 # include "WebAssemblyViewport.h" |
1901 | 26 # include "../../Scene2DViewport/ViewportController.h" |
27 # include "../../Toolbox/GenericToolbox.h" | |
28 # include "../../Viewport/DefaultViewportInteractor.h" | |
1899
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 #else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 // This is the case when using the WebAssembly side module, and this |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 // source file must be compiled within the WebAssembly main module |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 # include <Viewport/WebAssemblyViewport.h> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 # include <Toolbox/GenericToolbox.h> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 # include <Scene2DViewport/ViewportController.h> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 # include <Viewport/DefaultViewportInteractor.h> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 #endif |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 #include <OrthancException.h> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 #include <boost/make_shared.hpp> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 #include <boost/enable_shared_from_this.hpp> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 #include <boost/math/special_functions/round.hpp> |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 namespace OrthancStone |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 static void ConvertMouseEvent(PointerEvent& target, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
48 const EmscriptenMouseEvent& source, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
49 const ICompositor& compositor) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
51 int x = static_cast<int>(source.targetX); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 int y = static_cast<int>(source.targetY); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
53 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 switch (source.button) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
56 case 0: |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 target.SetMouseButton(MouseButton_Left); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 break; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 case 1: |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 target.SetMouseButton(MouseButton_Middle); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 break; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
64 case 2: |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 target.SetMouseButton(MouseButton_Right); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 break; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 default: |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 target.SetMouseButton(MouseButton_None); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 break; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 target.AddPosition(compositor.GetPixelCenterCoordinates(x, y)); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 target.SetAltModifier(source.altKey); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 target.SetControlModifier(source.ctrlKey); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 target.SetShiftModifier(source.shiftKey); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
79 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 class WebAssemblyViewport::WasmLock : public ILock |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 private: |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 WebAssemblyViewport& that_; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 public: |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 WasmLock(WebAssemblyViewport& that) : |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 that_(that) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 virtual bool HasCompositor() const ORTHANC_OVERRIDE |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 return that_.compositor_.get() != NULL; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
97 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 if (that_.compositor_.get() == NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
101 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
103 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
104 return *that_.compositor_; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
105 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
106 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
107 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 virtual ViewportController& GetController() ORTHANC_OVERRIDE |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
110 assert(that_.controller_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
111 return *that_.controller_; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
112 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
114 virtual void Invalidate() ORTHANC_OVERRIDE |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
115 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 that_.Invalidate(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
117 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
119 virtual void RefreshCanvasSize() ORTHANC_OVERRIDE |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
120 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
121 that_.RefreshCanvasSize(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
122 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
123 }; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
124 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
125 EM_BOOL WebAssemblyViewport::OnRequestAnimationFrame(double time, void *userData) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
126 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 LOG(TRACE) << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
128 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
129 WebAssemblyViewport* that = |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 WebAssemblyViewport::DereferenceObjectCookie(userData); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 if (that != NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 if (that->compositor_.get() != NULL && |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
135 that->controller_ /* should always be true */) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
137 that->Paint(*that->compositor_, *that->controller_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
138 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
139 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
140 else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
141 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
142 LOG(TRACE) << "WebAssemblyViewport::OnRequestAnimationFrame: the " << |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
143 "WebAssemblyViewport is deleted and Paint will not be called."; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
144 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
145 WebAssemblyViewport::ReleaseObjectCookie(userData); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
146 LOG(TRACE) << "Exiting: " << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
147 return true; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
148 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
149 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
150 EM_BOOL WebAssemblyViewport::OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
151 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
152 LOG(TRACE) << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
153 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
154 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
155 if (that->compositor_.get() != NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
156 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
157 that->RefreshCanvasSize(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
158 that->Invalidate(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
159 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
160 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
161 LOG(TRACE) << "Exiting: " << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
162 return true; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
163 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
164 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
165 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
166 EM_BOOL WebAssemblyViewport::OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
167 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
168 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
169 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
170 LOG(TRACE) << "mouse down: " << that->GetCanvasCssSelector(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
171 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
172 if (that->compositor_.get() != NULL && |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
173 that->interactor_.get() != NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
174 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
175 PointerEvent pointer; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
176 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
177 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
178 that->controller_->HandleMousePress(*that->interactor_, pointer, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
179 that->compositor_->GetCanvasWidth(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
180 that->compositor_->GetCanvasHeight()); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
181 that->Invalidate(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
182 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
183 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
184 LOG(TRACE) << "Exiting: " << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
185 return true; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
186 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
187 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
188 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
189 EM_BOOL WebAssemblyViewport::OnMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
190 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
191 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
192 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
193 if (that->compositor_.get() != NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
194 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
195 if (that->controller_->HasActiveTracker()) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
196 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
197 PointerEvent pointer; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
198 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
199 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
200 if (that->controller_->HandleMouseMove(pointer)) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
201 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
202 that->Invalidate(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
203 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
204 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
205 else if (that->interactor_.get() != NULL && |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
206 that->interactor_->HasMouseHover()) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
207 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
208 // New in Stone Web viewer 2.0 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
209 PointerEvent pointer; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
210 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
211 that->interactor_->HandleMouseHover(*that, pointer); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
212 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
213 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
214 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
215 LOG(TRACE) << "Exiting: " << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
216 return true; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
217 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
218 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
219 EM_BOOL WebAssemblyViewport::OnMouseUp(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
220 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
221 LOG(TRACE) << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
222 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
223 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
224 if (that->compositor_.get() != NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
225 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
226 PointerEvent pointer; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
227 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
228 that->controller_->HandleMouseRelease(pointer); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
229 that->Invalidate(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
230 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
231 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
232 LOG(TRACE) << "Exiting: " << __func__; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
233 return true; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
234 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
235 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
236 void* WebAssemblyViewport::CreateObjectCookie() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
237 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
238 boost::weak_ptr<WebAssemblyViewport>* weakThisPtr = |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
239 new boost::weak_ptr<WebAssemblyViewport>(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
240 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
241 *weakThisPtr = shared_from_this(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
242 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
243 void* cookie = reinterpret_cast<void*>(weakThisPtr); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
244 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
245 LOG(TRACE) << "WebAssemblyViewport::CreateObjectCookie() => cookie = " |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
246 << cookie << "\n"; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
247 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
248 return cookie; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
249 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
250 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
251 WebAssemblyViewport* WebAssemblyViewport::DereferenceObjectCookie(void* cookie) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
252 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
253 LOG(TRACE) << "WebAssemblyViewport::DereferenceObjectCookie(cookie = " |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
254 << cookie << ")\n"; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
255 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
256 boost::weak_ptr<WebAssemblyViewport>* weakThisPtr = |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
257 reinterpret_cast<boost::weak_ptr<WebAssemblyViewport>*>(cookie); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
258 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
259 boost::shared_ptr<WebAssemblyViewport> sharedThis = weakThisPtr->lock(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
260 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
261 return sharedThis.get(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
262 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
263 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
264 void WebAssemblyViewport::ReleaseObjectCookie(void* cookie) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
265 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
266 LOG(TRACE) << "WebAssemblyViewport::ReleaseObjectCookie(cookie = " |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
267 << cookie << ")\n"; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
268 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
269 boost::weak_ptr<WebAssemblyViewport>* weakThisPtr = |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
270 reinterpret_cast<boost::weak_ptr<WebAssemblyViewport>*>(cookie); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
271 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
272 delete weakThisPtr; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
273 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
274 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
275 void WebAssemblyViewport::Invalidate() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
276 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
277 LOG(TRACE) << "WebAssemblyViewport::Invalidate()\n"; |
1916 | 278 |
279 #if 1 | |
280 emscripten_request_animation_frame(OnRequestAnimationFrame, CreateObjectCookie()); | |
281 #else | |
282 animationFrameCallbackIds_.push_back( | |
283 emscripten_request_animation_frame(OnRequestAnimationFrame, CreateObjectCookie())); | |
284 #endif | |
1899
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
285 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
286 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
287 void WebAssemblyViewport::FitForPrint() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
288 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
289 if (compositor_.get() != NULL && |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
290 controller_ /* should always be true */) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
291 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
292 RefreshCanvasSize(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
293 compositor_->FitContent(controller_->GetScene()); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
294 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
295 void* cookie = CreateObjectCookie(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
296 OnRequestAnimationFrame(0, cookie); // Mandatory to work with Firefox |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
297 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
298 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
299 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
300 void WebAssemblyViewport::AcquireCompositor(ICompositor* compositor /* takes ownership */) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
301 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
302 if (compositor == NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
303 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
304 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
305 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
306 else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
307 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
308 compositor_.reset(compositor); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
309 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
310 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
311 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
312 #if DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR == 1 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
313 // everything OK..... we're using the new setting |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
314 #else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
315 #pragma message("WARNING: DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR is not defined or equal to 0. Stone will use the OLD Emscripten rules for DOM element selection.") |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
316 #endif |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
317 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
318 WebAssemblyViewport::WebAssemblyViewport( |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
319 const std::string& canvasId, bool enableEmscriptenMouseEvents) : |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
320 canvasId_(canvasId), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
321 #if DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR == 1 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
322 canvasCssSelector_("#" + canvasId), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
323 #else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
324 canvasCssSelector_(canvasId), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
325 #endif |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
326 interactor_(new DefaultViewportInteractor), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
327 enableEmscriptenMouseEvents_(enableEmscriptenMouseEvents), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
328 canvasWidth_(0), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
329 canvasHeight_(0) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
330 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
331 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
332 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
333 void WebAssemblyViewport::PostConstructor() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
334 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
335 boost::shared_ptr<IViewport> viewport = shared_from_this(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
336 controller_.reset(new ViewportController(viewport)); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
337 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
338 LOG(INFO) << "Initializing Stone viewport on HTML canvas: " |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
339 << canvasId_; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
340 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
341 if (canvasId_.empty() || |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
342 canvasId_[0] == '#') |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
343 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
345 "The canvas identifier must not start with '#'"); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
346 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
347 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
348 // Disable right-click on the canvas (i.e. context menu) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
349 EM_ASM({ |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
350 document.getElementById(UTF8ToString($0)).oncontextmenu = |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
351 function(event) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
352 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
353 event.preventDefault(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
354 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
355 }, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
356 canvasId_.c_str() // $0 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
357 ); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
358 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
359 // It is not possible to monitor the resizing of individual |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
360 // canvas, so we track the full window of the browser |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
361 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
362 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
363 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
364 OnResize); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
365 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
366 if (enableEmscriptenMouseEvents_) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
367 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
368 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
369 // if any of this function causes an error in the console, please |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
370 // make sure you are using the new (as of 1.39.x) version of |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
371 // emscripten element lookup rules( pass |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
372 // "-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1" to the linker. |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
373 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
374 emscripten_set_mousedown_callback(canvasCssSelector_.c_str(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
375 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
376 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
377 OnMouseDown); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
378 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
379 emscripten_set_mousemove_callback(canvasCssSelector_.c_str(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
380 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
381 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
382 OnMouseMove); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
383 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
384 emscripten_set_mouseup_callback(canvasCssSelector_.c_str(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
385 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
386 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
387 OnMouseUp); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
388 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
389 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
390 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
391 WebAssemblyViewport::~WebAssemblyViewport() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
392 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
393 LOG(TRACE) << "WebAssemblyViewport::~WebAssemblyViewport()\n"; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
394 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
395 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
396 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
397 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
398 NULL); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
399 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
400 if (enableEmscriptenMouseEvents_) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
401 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
402 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
403 emscripten_set_mousedown_callback(canvasCssSelector_.c_str(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
404 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
405 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
406 NULL); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
407 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
408 emscripten_set_mousemove_callback(canvasCssSelector_.c_str(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
409 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
410 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
411 NULL); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
412 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
413 emscripten_set_mouseup_callback(canvasCssSelector_.c_str(), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
414 reinterpret_cast<void*>(this), |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
415 false, |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
416 NULL); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
417 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
418 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
419 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
420 IViewport::ILock* WebAssemblyViewport::Lock() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
421 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
422 return new WasmLock(*this); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
423 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
424 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
425 void WebAssemblyViewport::AcquireInteractor(IViewportInteractor* interactor) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
426 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
427 if (interactor == NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
428 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
429 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
430 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
431 else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
432 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
433 interactor_.reset(interactor); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
434 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
435 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
436 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
437 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
438 void WebAssemblyViewport::RefreshCanvasSize() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
439 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
440 double w = -1, h = -1; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
441 EMSCRIPTEN_RESULT result = |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
442 emscripten_get_element_css_size(GetCanvasCssSelector().c_str(), &w, &h); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
443 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
444 if (result != EMSCRIPTEN_RESULT_SUCCESS) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
445 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
446 LOG(WARNING) << "WebAssemblyViewport::RefreshCanvasSize failed to " |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
447 << "retrieve CSS size for " << GetCanvasCssSelector(); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
448 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
449 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
450 /** |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
451 * Emscripten has the function emscripten_get_element_css_size() |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
452 * to query the width and height of a named HTML element. I'm |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
453 * calling this first to get the initial size of the canvas DOM |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
454 * element, and then call emscripten_set_canvas_size() to |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
455 * initialize the framebuffer size of the canvas to the same |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
456 * size as its DOM element. |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
457 * https://floooh.github.io/2017/02/22/emsc-html.html |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
458 **/ |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
459 if (w > 0 && |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
460 h > 0) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
461 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
462 canvasWidth_ = static_cast<unsigned int>(boost::math::iround(w)); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
463 canvasHeight_ = static_cast<unsigned int>(boost::math::iround(h)); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
464 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
465 else |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
466 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
467 canvasWidth_ = 0; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
468 canvasHeight_ = 0; |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
469 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
470 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
471 emscripten_set_canvas_element_size(GetCanvasCssSelector().c_str(), canvasWidth_, canvasHeight_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
472 |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
473 if (compositor_.get() != NULL) |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
474 { |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
475 compositor_->SetCanvasSize(canvasWidth_, canvasHeight_); |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
476 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
477 } |
917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
478 } |