Mercurial > hg > orthanc-stone
annotate Framework/Viewport/WidgetViewport.cpp @ 343:712acc87fa2e am-2
text layer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 22 Oct 2018 14:20:39 +0200 |
parents | 7a364e44fbb4 |
children | 557c8ff1db5c |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "WidgetViewport.h" | |
23 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
24 #include <Core/Images/ImageProcessing.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
25 #include <Core/OrthancException.h> |
0 | 26 |
27 namespace OrthancStone | |
28 { | |
29 WidgetViewport::WidgetViewport() : | |
30 statusBar_(NULL), | |
31 isMouseOver_(false), | |
32 lastMouseX_(0), | |
33 lastMouseY_(0), | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
34 backgroundChanged_(false) |
0 | 35 { |
36 } | |
37 | |
38 | |
330 | 39 void WidgetViewport::FitContent() |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
40 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
41 if (centralWidget_.get() != NULL) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
42 { |
330 | 43 centralWidget_->FitContent(); |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
44 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
45 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
46 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
47 |
0 | 48 void WidgetViewport::SetStatusBar(IStatusBar& statusBar) |
49 { | |
50 statusBar_ = &statusBar; | |
51 | |
52 if (centralWidget_.get() != NULL) | |
53 { | |
54 centralWidget_->SetStatusBar(statusBar); | |
55 } | |
56 } | |
57 | |
58 | |
59 IWidget& WidgetViewport::SetCentralWidget(IWidget* widget) | |
60 { | |
61 if (widget == NULL) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
64 } | |
65 | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
66 mouseTracker_.reset(NULL); |
222 | 67 |
0 | 68 centralWidget_.reset(widget); |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
69 centralWidget_->SetViewport(*this); |
0 | 70 |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
71 if (statusBar_ != NULL) |
0 | 72 { |
73 centralWidget_->SetStatusBar(*statusBar_); | |
74 } | |
75 | |
76 backgroundChanged_ = true; | |
277 | 77 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 78 |
79 return *widget; | |
80 } | |
81 | |
82 | |
278 | 83 void WidgetViewport::NotifyContentChanged(const IWidget& widget) |
0 | 84 { |
85 backgroundChanged_ = true; | |
277 | 86 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 87 } |
88 | |
89 | |
90 void WidgetViewport::SetSize(unsigned int width, | |
91 unsigned int height) | |
92 { | |
93 background_.SetSize(width, height); | |
94 | |
95 if (centralWidget_.get() != NULL) | |
96 { | |
97 centralWidget_->SetSize(width, height); | |
98 } | |
99 | |
277 | 100 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 101 } |
102 | |
103 | |
104 bool WidgetViewport::Render(Orthanc::ImageAccessor& surface) | |
105 { | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
106 if (centralWidget_.get() == NULL) |
0 | 107 { |
108 return false; | |
109 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
110 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
278
diff
changeset
|
111 Orthanc::ImageAccessor background; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
278
diff
changeset
|
112 background_.GetAccessor(background); |
0 | 113 |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
114 if (backgroundChanged_ && |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
115 !centralWidget_->Render(background)) |
0 | 116 { |
117 return false; | |
118 } | |
119 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
120 if (background.GetWidth() != surface.GetWidth() || |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
121 background.GetHeight() != surface.GetHeight()) |
0 | 122 { |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
123 return false; |
0 | 124 } |
125 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
126 Orthanc::ImageProcessing::Convert(surface, background); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
127 |
0 | 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 | |
141 void WidgetViewport::MouseDown(MouseButton button, | |
142 int x, | |
143 int y, | |
144 KeyboardModifiers modifiers) | |
145 { | |
146 lastMouseX_ = x; | |
147 lastMouseY_ = y; | |
148 | |
149 if (centralWidget_.get() != NULL) | |
150 { | |
151 mouseTracker_.reset(centralWidget_->CreateMouseTracker(button, x, y, modifiers)); | |
152 } | |
153 else | |
154 { | |
155 mouseTracker_.reset(NULL); | |
156 } | |
157 | |
277 | 158 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 159 } |
160 | |
161 | |
162 void WidgetViewport::MouseUp() | |
163 { | |
164 if (mouseTracker_.get() != NULL) | |
165 { | |
166 mouseTracker_->MouseUp(); | |
167 mouseTracker_.reset(NULL); | |
277 | 168 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 169 } |
170 } | |
171 | |
172 | |
173 void WidgetViewport::MouseMove(int x, | |
174 int y) | |
175 { | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
176 if (centralWidget_.get() == NULL) |
0 | 177 { |
178 return; | |
179 } | |
180 | |
181 lastMouseX_ = x; | |
182 lastMouseY_ = y; | |
183 | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
184 bool repaint = false; |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
185 |
0 | 186 if (mouseTracker_.get() != NULL) |
187 { | |
188 mouseTracker_->MouseMove(x, y); | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
189 repaint = true; |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
190 } |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
191 else |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
192 { |
55 | 193 repaint = centralWidget_->HasRenderMouseOver(); |
0 | 194 } |
195 | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
196 if (repaint) |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
197 { |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
198 // The scene must be repainted, notify the observers |
277 | 199 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
200 } |
0 | 201 } |
202 | |
203 | |
204 void WidgetViewport::MouseEnter() | |
205 { | |
206 isMouseOver_ = true; | |
277 | 207 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 208 } |
209 | |
210 | |
211 void WidgetViewport::MouseLeave() | |
212 { | |
213 isMouseOver_ = false; | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
214 |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
215 if (mouseTracker_.get() != NULL) |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
216 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
217 mouseTracker_->MouseUp(); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
218 mouseTracker_.reset(NULL); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
219 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
220 |
277 | 221 observers_.Apply(*this, &IObserver::OnViewportContentChanged); |
0 | 222 } |
223 | |
224 | |
225 void WidgetViewport::MouseWheel(MouseWheelDirection direction, | |
226 int x, | |
227 int y, | |
228 KeyboardModifiers modifiers) | |
229 { | |
230 if (centralWidget_.get() != NULL && | |
231 mouseTracker_.get() == NULL) | |
232 { | |
233 centralWidget_->MouseWheel(direction, x, y, modifiers); | |
234 } | |
235 } | |
236 | |
237 | |
327 | 238 void WidgetViewport::KeyPressed(KeyboardKeys key, |
239 char keyChar, | |
0 | 240 KeyboardModifiers modifiers) |
241 { | |
242 if (centralWidget_.get() != NULL && | |
243 mouseTracker_.get() == NULL) | |
244 { | |
327 | 245 centralWidget_->KeyPressed(key, keyChar, modifiers); |
0 | 246 } |
247 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
248 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
249 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
250 bool WidgetViewport::HasUpdateContent() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
251 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
252 if (centralWidget_.get() != NULL) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
253 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
254 return centralWidget_->HasUpdateContent(); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
255 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
256 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
257 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
258 return false; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
259 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
260 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
261 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
262 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
263 void WidgetViewport::UpdateContent() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
264 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
265 if (centralWidget_.get() != NULL) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
266 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
267 centralWidget_->UpdateContent(); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
268 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
269 } |
0 | 270 } |