annotate Samples/WebAssembly/dev.h @ 863:23701fbf228e am-dev

first rendering of a 2DScene in Qt widget
author Alain Mazy <alain@mazy.be>
date Mon, 24 Jun 2019 16:29:49 +0200
parents 2de01660debe
children 5cfb479fdbde 77c96ba899f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../../Framework/OpenGL/WebAssemblyOpenGLContext.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../../Framework/Scene2D/OpenGLCompositor.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../../Framework/Scene2D/PanSceneTracker.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../../Framework/Scene2D/RotateSceneTracker.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../Framework/Scene2D/ZoomSceneTracker.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../../Framework/Scene2DViewport/ViewportController.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <Core/OrthancException.h>
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <emscripten/html5.h>
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static const unsigned int FONT_SIZE = 32;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace OrthancStone
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 class WebAssemblyViewport : public boost::noncopyable
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 private:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 // the construction order is important because compositor_
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 // will hold a reference to the scene that belong to the
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 // controller_ object
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 OpenGL::WebAssemblyOpenGLContext context_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 boost::shared_ptr<ViewportController> controller_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 OpenGLCompositor compositor_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 void SetupEvents(const std::string& canvas);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 public:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 WebAssemblyViewport(MessageBroker& broker,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const std::string& canvas) :
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 context_(canvas),
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 controller_(new ViewportController(broker)),
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 compositor_(context_, *controller_->GetScene())
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 compositor_.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 FONT_SIZE, Orthanc::Encoding_Latin1);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 SetupEvents(canvas);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 Scene2D& GetScene()
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 return *controller_->GetScene();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const boost::shared_ptr<ViewportController>& GetController()
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 return controller_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 void UpdateSize()
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 context_.UpdateSize();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 compositor_.UpdateSize();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 Refresh();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 void Refresh()
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 compositor_.Refresh();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 void FitContent()
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 GetScene().FitContent(context_.GetCanvasWidth(), context_.GetCanvasHeight());
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 const std::string& GetCanvasIdentifier() const
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 return context_.GetCanvasIdentifier();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ScenePoint2D GetPixelCenterCoordinates(int x, int y) const
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 return compositor_.GetPixelCenterCoordinates(x, y);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 unsigned int GetCanvasWidth() const
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return context_.GetCanvasWidth();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 unsigned int GetCanvasHeight() const
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return context_.GetCanvasHeight();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 };
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 class ActiveTracker : public boost::noncopyable
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 private:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 boost::shared_ptr<IFlexiblePointerTracker> tracker_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 std::string canvasIdentifier_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 bool insideCanvas_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 public:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ActiveTracker(const boost::shared_ptr<IFlexiblePointerTracker>& tracker,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 const WebAssemblyViewport& viewport) :
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 tracker_(tracker),
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 canvasIdentifier_(viewport.GetCanvasIdentifier()),
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 insideCanvas_(true)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 if (tracker_.get() == NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 bool IsAlive() const
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 return tracker_->IsAlive();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 void PointerMove(const PointerEvent& event)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 tracker_->PointerMove(event);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 void PointerUp(const PointerEvent& event)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 tracker_->PointerUp(event);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 };
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 static OrthancStone::PointerEvent* ConvertMouseEvent(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 const EmscriptenMouseEvent& source,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 OrthancStone::WebAssemblyViewport& viewport)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 std::auto_ptr<OrthancStone::PointerEvent> target(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 new OrthancStone::PointerEvent);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 target->AddPosition(viewport.GetPixelCenterCoordinates(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 source.targetX, source.targetY));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 target->SetAltModifier(source.altKey);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 target->SetControlModifier(source.ctrlKey);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 target->SetShiftModifier(source.shiftKey);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 return target.release();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 std::auto_ptr<OrthancStone::ActiveTracker> tracker_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 EM_BOOL OnMouseEvent(int eventType,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 const EmscriptenMouseEvent *mouseEvent,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 void *userData)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 if (mouseEvent != NULL &&
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 userData != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 OrthancStone::WebAssemblyViewport& viewport =
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 *reinterpret_cast<OrthancStone::WebAssemblyViewport*>(userData);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 switch (eventType)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 case EMSCRIPTEN_EVENT_CLICK:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 static unsigned int count = 0;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 char buf[64];
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 sprintf(buf, "click %d", count++);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 layer->SetText(buf);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 viewport.GetScene().SetLayer(100, layer.release());
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 viewport.Refresh();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 case EMSCRIPTEN_EVENT_MOUSEDOWN:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 std::auto_ptr<OrthancStone::PointerEvent> event(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ConvertMouseEvent(*mouseEvent, viewport));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 switch (mouseEvent->button)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 case 0: // Left button
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 emscripten_console_log("Creating RotateSceneTracker");
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 t.reset(new OrthancStone::RotateSceneTracker(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 viewport.GetController(), *event));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 case 1: // Middle button
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 emscripten_console_log("Creating PanSceneTracker");
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 LOG(INFO) << "Creating PanSceneTracker" ;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 t.reset(new OrthancStone::PanSceneTracker(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 viewport.GetController(), *event));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 case 2: // Right button
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 emscripten_console_log("Creating ZoomSceneTracker");
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 t.reset(new OrthancStone::ZoomSceneTracker(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 viewport.GetController(), *event, viewport.GetCanvasWidth()));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 default:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 if (t.get() != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 tracker_.reset(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 new OrthancStone::ActiveTracker(t, viewport));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 viewport.Refresh();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 case EMSCRIPTEN_EVENT_MOUSEMOVE:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if (tracker_.get() != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 std::auto_ptr<OrthancStone::PointerEvent> event(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 ConvertMouseEvent(*mouseEvent, viewport));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 tracker_->PointerMove(*event);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 viewport.Refresh();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 case EMSCRIPTEN_EVENT_MOUSEUP:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 if (tracker_.get() != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 std::auto_ptr<OrthancStone::PointerEvent> event(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 ConvertMouseEvent(*mouseEvent, viewport));
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 tracker_->PointerUp(*event);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 viewport.Refresh();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (!tracker_->IsAlive())
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 tracker_.reset();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 default:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 return true;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 void OrthancStone::WebAssemblyViewport::SetupEvents(const std::string& canvas)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 emscripten_set_mousedown_callback(canvas.c_str(), this, false, OnMouseEvent);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 emscripten_set_mousemove_callback(canvas.c_str(), this, false, OnMouseEvent);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 emscripten_set_mouseup_callback(canvas.c_str(), this, false, OnMouseEvent);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }