Mercurial > hg > orthanc-stone
annotate Framework/Viewport/WidgetViewport.cpp @ 275:58e23e0dd86a am-2
renaming
author | am@osimis.io |
---|---|
date | Fri, 24 Aug 2018 13:58:06 +0200 |
parents | 84844649a8fd |
children | a38465cc909f |
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 | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
39 void WidgetViewport::SetDefaultView() |
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 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
43 centralWidget_->SetDefaultView(); |
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; | |
91 | 77 observers_.Apply(*this, &IObserver::NotifyChange); |
0 | 78 |
79 return *widget; | |
80 } | |
81 | |
82 | |
83 void WidgetViewport::NotifyChange(const IWidget& widget) | |
84 { | |
85 backgroundChanged_ = true; | |
91 | 86 observers_.Apply(*this, &IObserver::NotifyChange); |
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 | |
91 | 100 observers_.Apply(*this, &IObserver::NotifyChange); |
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 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
111 Orthanc::ImageAccessor background = background_.GetAccessor(); |
0 | 112 |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
113 if (backgroundChanged_ && |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
114 !centralWidget_->Render(background)) |
0 | 115 { |
116 return false; | |
117 } | |
118 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
119 if (background.GetWidth() != surface.GetWidth() || |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
120 background.GetHeight() != surface.GetHeight()) |
0 | 121 { |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
122 return false; |
0 | 123 } |
124 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
125 Orthanc::ImageProcessing::Convert(surface, background); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
126 |
0 | 127 if (mouseTracker_.get() != NULL) |
128 { | |
129 mouseTracker_->Render(surface); | |
130 } | |
131 else if (isMouseOver_) | |
132 { | |
133 centralWidget_->RenderMouseOver(surface, lastMouseX_, lastMouseY_); | |
134 } | |
135 | |
136 return true; | |
137 } | |
138 | |
139 | |
140 void WidgetViewport::MouseDown(MouseButton button, | |
141 int x, | |
142 int y, | |
143 KeyboardModifiers modifiers) | |
144 { | |
145 lastMouseX_ = x; | |
146 lastMouseY_ = y; | |
147 | |
148 if (centralWidget_.get() != NULL) | |
149 { | |
150 mouseTracker_.reset(centralWidget_->CreateMouseTracker(button, x, y, modifiers)); | |
151 } | |
152 else | |
153 { | |
154 mouseTracker_.reset(NULL); | |
155 } | |
156 | |
91 | 157 observers_.Apply(*this, &IObserver::NotifyChange); |
0 | 158 } |
159 | |
160 | |
161 void WidgetViewport::MouseUp() | |
162 { | |
163 if (mouseTracker_.get() != NULL) | |
164 { | |
165 mouseTracker_->MouseUp(); | |
166 mouseTracker_.reset(NULL); | |
91 | 167 observers_.Apply(*this, &IObserver::NotifyChange); |
0 | 168 } |
169 } | |
170 | |
171 | |
172 void WidgetViewport::MouseMove(int x, | |
173 int y) | |
174 { | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
175 if (centralWidget_.get() == NULL) |
0 | 176 { |
177 return; | |
178 } | |
179 | |
180 lastMouseX_ = x; | |
181 lastMouseY_ = y; | |
182 | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
183 bool repaint = false; |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
184 |
0 | 185 if (mouseTracker_.get() != NULL) |
186 { | |
187 mouseTracker_->MouseMove(x, y); | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
188 repaint = true; |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
189 } |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
190 else |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
191 { |
55 | 192 repaint = centralWidget_->HasRenderMouseOver(); |
0 | 193 } |
194 | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
195 if (repaint) |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
196 { |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
197 // The scene must be repainted, notify the observers |
91 | 198 observers_.Apply(*this, &IObserver::NotifyChange); |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
199 } |
0 | 200 } |
201 | |
202 | |
203 void WidgetViewport::MouseEnter() | |
204 { | |
205 isMouseOver_ = true; | |
91 | 206 observers_.Apply(*this, &IObserver::NotifyChange); |
0 | 207 } |
208 | |
209 | |
210 void WidgetViewport::MouseLeave() | |
211 { | |
212 isMouseOver_ = false; | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
213 |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
55
diff
changeset
|
214 if (mouseTracker_.get() != NULL) |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
215 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
216 mouseTracker_->MouseUp(); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
217 mouseTracker_.reset(NULL); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
218 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
219 |
91 | 220 observers_.Apply(*this, &IObserver::NotifyChange); |
0 | 221 } |
222 | |
223 | |
224 void WidgetViewport::MouseWheel(MouseWheelDirection direction, | |
225 int x, | |
226 int y, | |
227 KeyboardModifiers modifiers) | |
228 { | |
229 if (centralWidget_.get() != NULL && | |
230 mouseTracker_.get() == NULL) | |
231 { | |
232 centralWidget_->MouseWheel(direction, x, y, modifiers); | |
233 } | |
234 } | |
235 | |
236 | |
237 void WidgetViewport::KeyPressed(char key, | |
238 KeyboardModifiers modifiers) | |
239 { | |
240 if (centralWidget_.get() != NULL && | |
241 mouseTracker_.get() == NULL) | |
242 { | |
243 centralWidget_->KeyPressed(key, modifiers); | |
244 } | |
245 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
246 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
247 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
248 bool WidgetViewport::HasUpdateContent() |
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 if (centralWidget_.get() != NULL) |
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 return centralWidget_->HasUpdateContent(); |
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 else |
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 return false; |
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 } |
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 void WidgetViewport::UpdateContent() |
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 if (centralWidget_.get() != NULL) |
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 centralWidget_->UpdateContent(); |
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 } |
0 | 268 } |