Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Viewport/WidgetViewport.cpp @ 732:c35e98d22764
move Deprecated classes to a separate folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 14:27:35 +0200 |
parents | Framework/Viewport/WidgetViewport.cpp@4f2416d519b4 |
children | e146743f6cdc 4663f158c748 |
comparison
equal
deleted
inserted
replaced
729:529189f399ec | 732:c35e98d22764 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "WidgetViewport.h" | |
23 | |
24 #include <Core/Images/ImageProcessing.h> | |
25 #include <Core/OrthancException.h> | |
26 | |
27 namespace Deprecated | |
28 { | |
29 WidgetViewport::WidgetViewport(OrthancStone::MessageBroker& broker) : | |
30 IViewport(broker), | |
31 statusBar_(NULL), | |
32 isMouseOver_(false), | |
33 lastMouseX_(0), | |
34 lastMouseY_(0), | |
35 backgroundChanged_(false) | |
36 { | |
37 } | |
38 | |
39 | |
40 void WidgetViewport::FitContent() | |
41 { | |
42 if (centralWidget_.get() != NULL) | |
43 { | |
44 centralWidget_->FitContent(); | |
45 } | |
46 } | |
47 | |
48 | |
49 void WidgetViewport::SetStatusBar(IStatusBar& statusBar) | |
50 { | |
51 statusBar_ = &statusBar; | |
52 | |
53 if (centralWidget_.get() != NULL) | |
54 { | |
55 centralWidget_->SetStatusBar(statusBar); | |
56 } | |
57 } | |
58 | |
59 | |
60 IWidget& WidgetViewport::SetCentralWidget(IWidget* widget) | |
61 { | |
62 if (widget == NULL) | |
63 { | |
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
65 } | |
66 | |
67 mouseTracker_.reset(NULL); | |
68 | |
69 centralWidget_.reset(widget); | |
70 centralWidget_->SetViewport(*this); | |
71 | |
72 if (statusBar_ != NULL) | |
73 { | |
74 centralWidget_->SetStatusBar(*statusBar_); | |
75 } | |
76 | |
77 NotifyBackgroundChanged(); | |
78 | |
79 return *widget; | |
80 } | |
81 | |
82 | |
83 void WidgetViewport::NotifyBackgroundChanged() | |
84 { | |
85 backgroundChanged_ = true; | |
86 NotifyContentChanged(); | |
87 } | |
88 | |
89 | |
90 void WidgetViewport::SetSize(unsigned int width, | |
91 unsigned int height) | |
92 { | |
93 background_.SetSize(width, height, false /* no alpha */); | |
94 | |
95 if (centralWidget_.get() != NULL) | |
96 { | |
97 centralWidget_->SetSize(width, height); | |
98 } | |
99 | |
100 NotifyBackgroundChanged(); | |
101 } | |
102 | |
103 | |
104 bool WidgetViewport::Render(Orthanc::ImageAccessor& surface) | |
105 { | |
106 if (centralWidget_.get() == NULL) | |
107 { | |
108 return false; | |
109 } | |
110 | |
111 Orthanc::ImageAccessor background; | |
112 background_.GetWriteableAccessor(background); | |
113 | |
114 if (backgroundChanged_ && | |
115 !centralWidget_->Render(background)) | |
116 { | |
117 return false; | |
118 } | |
119 | |
120 if (background.GetWidth() != surface.GetWidth() || | |
121 background.GetHeight() != surface.GetHeight()) | |
122 { | |
123 return false; | |
124 } | |
125 | |
126 Orthanc::ImageProcessing::Convert(surface, background); | |
127 | |
128 if (mouseTracker_.get() != NULL) | |
129 { | |
130 mouseTracker_->Render(surface); | |
131 } | |
132 else if (isMouseOver_) | |
133 { | |
134 centralWidget_->RenderMouseOver(surface, lastMouseX_, lastMouseY_); | |
135 } | |
136 | |
137 return true; | |
138 } | |
139 | |
140 void WidgetViewport::TouchStart(const std::vector<Touch>& displayTouches) | |
141 { | |
142 MouseDown(OrthancStone::MouseButton_Left, (int)displayTouches[0].x, (int)displayTouches[0].y, OrthancStone::KeyboardModifiers_None, displayTouches); // one touch is equivalent to a mouse tracker without left button -> set the mouse coordinates to the first touch coordinates | |
143 } | |
144 | |
145 void WidgetViewport::TouchMove(const std::vector<Touch>& displayTouches) | |
146 { | |
147 MouseMove((int)displayTouches[0].x, (int)displayTouches[0].y, displayTouches); // one touch is equivalent to a mouse tracker without left button -> set the mouse coordinates to the first touch coordinates | |
148 } | |
149 | |
150 void WidgetViewport::TouchEnd(const std::vector<Touch>& displayTouches) | |
151 { | |
152 // note: TouchEnd is not triggered when a single touch gesture ends (it is only triggered when | |
153 // going from 2 touches to 1 touch, ...) | |
154 MouseUp(); | |
155 } | |
156 | |
157 void WidgetViewport::MouseDown(OrthancStone::MouseButton button, | |
158 int x, | |
159 int y, | |
160 OrthancStone::KeyboardModifiers modifiers, | |
161 const std::vector<Touch>& displayTouches | |
162 ) | |
163 { | |
164 lastMouseX_ = x; | |
165 lastMouseY_ = y; | |
166 | |
167 if (centralWidget_.get() != NULL) | |
168 { | |
169 mouseTracker_.reset(centralWidget_->CreateMouseTracker(button, x, y, modifiers, displayTouches)); | |
170 } | |
171 else | |
172 { | |
173 mouseTracker_.reset(NULL); | |
174 } | |
175 | |
176 NotifyContentChanged(); | |
177 } | |
178 | |
179 | |
180 void WidgetViewport::MouseUp() | |
181 { | |
182 if (mouseTracker_.get() != NULL) | |
183 { | |
184 mouseTracker_->MouseUp(); | |
185 mouseTracker_.reset(NULL); | |
186 NotifyContentChanged(); | |
187 } | |
188 } | |
189 | |
190 | |
191 void WidgetViewport::MouseMove(int x, | |
192 int y, | |
193 const std::vector<Touch>& displayTouches) | |
194 { | |
195 if (centralWidget_.get() == NULL) | |
196 { | |
197 return; | |
198 } | |
199 | |
200 lastMouseX_ = x; | |
201 lastMouseY_ = y; | |
202 | |
203 bool repaint = false; | |
204 | |
205 if (mouseTracker_.get() != NULL) | |
206 { | |
207 mouseTracker_->MouseMove(x, y, displayTouches); | |
208 repaint = true; | |
209 } | |
210 else | |
211 { | |
212 repaint = centralWidget_->HasRenderMouseOver(); | |
213 } | |
214 | |
215 if (repaint) | |
216 { | |
217 // The scene must be repainted, notify the observers | |
218 NotifyContentChanged(); | |
219 } | |
220 } | |
221 | |
222 | |
223 void WidgetViewport::MouseEnter() | |
224 { | |
225 isMouseOver_ = true; | |
226 NotifyContentChanged(); | |
227 } | |
228 | |
229 | |
230 void WidgetViewport::MouseLeave() | |
231 { | |
232 isMouseOver_ = false; | |
233 | |
234 if (mouseTracker_.get() != NULL) | |
235 { | |
236 mouseTracker_->MouseUp(); | |
237 mouseTracker_.reset(NULL); | |
238 } | |
239 | |
240 NotifyContentChanged(); | |
241 } | |
242 | |
243 | |
244 void WidgetViewport::MouseWheel(OrthancStone::MouseWheelDirection direction, | |
245 int x, | |
246 int y, | |
247 OrthancStone::KeyboardModifiers modifiers) | |
248 { | |
249 if (centralWidget_.get() != NULL && | |
250 mouseTracker_.get() == NULL) | |
251 { | |
252 centralWidget_->MouseWheel(direction, x, y, modifiers); | |
253 } | |
254 } | |
255 | |
256 | |
257 void WidgetViewport::KeyPressed(OrthancStone::KeyboardKeys key, | |
258 char keyChar, | |
259 OrthancStone::KeyboardModifiers modifiers) | |
260 { | |
261 if (centralWidget_.get() != NULL && | |
262 mouseTracker_.get() == NULL) | |
263 { | |
264 centralWidget_->KeyPressed(key, keyChar, modifiers); | |
265 } | |
266 } | |
267 | |
268 | |
269 bool WidgetViewport::HasAnimation() | |
270 { | |
271 if (centralWidget_.get() != NULL) | |
272 { | |
273 return centralWidget_->HasAnimation(); | |
274 } | |
275 else | |
276 { | |
277 return false; | |
278 } | |
279 } | |
280 | |
281 | |
282 void WidgetViewport::DoAnimation() | |
283 { | |
284 if (centralWidget_.get() != NULL) | |
285 { | |
286 centralWidget_->DoAnimation(); | |
287 } | |
288 } | |
289 } |