annotate Samples/WebAssembly/dev.h @ 1199:922d2e61aa5d

RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
author Alain Mazy <alain@mazy.be>
date Thu, 28 Nov 2019 18:28:15 +0100
parents 9c2f6d6b9f4a
children 2d8ab34c8c91
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
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
24 #include "../../Framework/Viewport/WebAssemblyViewport.h"
826
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"
890
77c96ba899f9 removing OpenGLCompositor::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
29 #include "../../Framework/Scene2DViewport/UndoStack.h"
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../Framework/Scene2DViewport/ViewportController.h"
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <Core/OrthancException.h>
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <emscripten/html5.h>
890
77c96ba899f9 removing OpenGLCompositor::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
35 #include <boost/make_shared.hpp>
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static const unsigned int FONT_SIZE = 32;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancStone
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 class ActiveTracker : public boost::noncopyable
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 private:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 boost::shared_ptr<IFlexiblePointerTracker> tracker_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 std::string canvasIdentifier_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 bool insideCanvas_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 public:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ActiveTracker(const boost::shared_ptr<IFlexiblePointerTracker>& tracker,
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
50 const std::string& canvasId) :
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 tracker_(tracker),
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
52 canvasIdentifier_(canvasId),
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 insideCanvas_(true)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (tracker_.get() == NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 bool IsAlive() const
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 return tracker_->IsAlive();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 void PointerMove(const PointerEvent& event)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 tracker_->PointerMove(event);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 void PointerUp(const PointerEvent& event)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 tracker_->PointerUp(event);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 };
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 static OrthancStone::PointerEvent* ConvertMouseEvent(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 const EmscriptenMouseEvent& source,
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
80 OrthancStone::IViewport& viewport)
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 std::auto_ptr<OrthancStone::PointerEvent> target(
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 new OrthancStone::PointerEvent);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 target->AddPosition(viewport.GetPixelCenterCoordinates(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
86 source.targetX, source.targetY));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 target->SetAltModifier(source.altKey);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 target->SetControlModifier(source.ctrlKey);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 target->SetShiftModifier(source.shiftKey);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 return target.release();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::auto_ptr<OrthancStone::ActiveTracker> tracker_;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 EM_BOOL OnMouseEvent(int eventType,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 const EmscriptenMouseEvent *mouseEvent,
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 void *userData)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (mouseEvent != NULL &&
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 userData != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
103 boost::shared_ptr<OrthancStone::ViewportController>& controller =
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
104 *reinterpret_cast<boost::shared_ptr<OrthancStone::ViewportController>*>(userData);
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 switch (eventType)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 case EMSCRIPTEN_EVENT_CLICK:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 static unsigned int count = 0;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 char buf[64];
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 sprintf(buf, "click %d", count++);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer);
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 layer->SetText(buf);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
116 controller->GetViewport().GetScene().SetLayer(100, layer.release());
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
117 controller->GetViewport().Refresh();
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 case EMSCRIPTEN_EVENT_MOUSEDOWN:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 std::auto_ptr<OrthancStone::PointerEvent> event(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
127 ConvertMouseEvent(*mouseEvent, controller->GetViewport()));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 switch (mouseEvent->button)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 case 0: // Left button
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 emscripten_console_log("Creating RotateSceneTracker");
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 t.reset(new OrthancStone::RotateSceneTracker(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
134 controller, *event));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 case 1: // Middle button
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 emscripten_console_log("Creating PanSceneTracker");
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 LOG(INFO) << "Creating PanSceneTracker" ;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 t.reset(new OrthancStone::PanSceneTracker(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
141 controller, *event));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 case 2: // Right button
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 emscripten_console_log("Creating ZoomSceneTracker");
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 t.reset(new OrthancStone::ZoomSceneTracker(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
147 controller, *event, controller->GetViewport().GetCanvasWidth()));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 default:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 if (t.get() != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 tracker_.reset(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
158 new OrthancStone::ActiveTracker(t, controller->GetViewport().GetCanvasIdentifier()));
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
159 controller->GetViewport().Refresh();
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 case EMSCRIPTEN_EVENT_MOUSEMOVE:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 if (tracker_.get() != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 std::auto_ptr<OrthancStone::PointerEvent> event(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
169 ConvertMouseEvent(*mouseEvent, controller->GetViewport()));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 tracker_->PointerMove(*event);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
171 controller->GetViewport().Refresh();
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 case EMSCRIPTEN_EVENT_MOUSEUP:
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (tracker_.get() != NULL)
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 std::auto_ptr<OrthancStone::PointerEvent> event(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
179 ConvertMouseEvent(*mouseEvent, controller->GetViewport()));
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 tracker_->PointerUp(*event);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
181 controller->GetViewport().Refresh();
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 if (!tracker_->IsAlive())
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 tracker_.reset();
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 break;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 default:
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
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 return true;
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
196 void SetupEvents(const std::string& canvas,
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
197 boost::shared_ptr<OrthancStone::ViewportController>& controller)
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
199 emscripten_set_mousedown_callback(canvas.c_str(), &controller, false, OnMouseEvent);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
200 emscripten_set_mousemove_callback(canvas.c_str(), &controller, false, OnMouseEvent);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
201 emscripten_set_mouseup_callback(canvas.c_str(), &controller, false, OnMouseEvent);
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }