comparison Framework/Viewport/WidgetViewport.cpp @ 53:c2dc924f1a63 wasm

removing threading out of the framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Apr 2017 16:57:49 +0200
parents 25befef48c35
children 01aa453d4d5b
comparison
equal deleted inserted replaced
52:37e504582af6 53:c2dc924f1a63
48 } 48 }
49 49
50 50
51 void WidgetViewport::SetStatusBar(IStatusBar& statusBar) 51 void WidgetViewport::SetStatusBar(IStatusBar& statusBar)
52 { 52 {
53 boost::mutex::scoped_lock lock(mutex_);
54
55 statusBar_ = &statusBar; 53 statusBar_ = &statusBar;
56 54
57 if (centralWidget_.get() != NULL) 55 if (centralWidget_.get() != NULL)
58 { 56 {
59 centralWidget_->SetStatusBar(statusBar); 57 centralWidget_->SetStatusBar(statusBar);
61 } 59 }
62 60
63 61
64 void WidgetViewport::ResetStatusBar() 62 void WidgetViewport::ResetStatusBar()
65 { 63 {
66 boost::mutex::scoped_lock lock(mutex_);
67
68 statusBar_ = NULL; 64 statusBar_ = NULL;
69 65
70 if (centralWidget_.get() != NULL) 66 if (centralWidget_.get() != NULL)
71 { 67 {
72 centralWidget_->ResetStatusBar(); 68 centralWidget_->ResetStatusBar();
78 { 74 {
79 if (started_) 75 if (started_)
80 { 76 {
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
82 } 78 }
83
84 boost::mutex::scoped_lock lock(mutex_);
85 79
86 if (widget == NULL) 80 if (widget == NULL)
87 { 81 {
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 82 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
89 } 83 }
115 } 109 }
116 110
117 111
118 void WidgetViewport::Start() 112 void WidgetViewport::Start()
119 { 113 {
120 boost::mutex::scoped_lock lock(mutex_);
121
122 if (centralWidget_.get() != NULL) 114 if (centralWidget_.get() != NULL)
123 { 115 {
124 centralWidget_->Start(); 116 centralWidget_->Start();
125 } 117 }
126 118
128 } 120 }
129 121
130 122
131 void WidgetViewport::Stop() 123 void WidgetViewport::Stop()
132 { 124 {
133 boost::mutex::scoped_lock lock(mutex_);
134
135 started_ = false; 125 started_ = false;
136 126
137 if (centralWidget_.get() != NULL) 127 if (centralWidget_.get() != NULL)
138 { 128 {
139 centralWidget_->Stop(); 129 centralWidget_->Stop();
142 132
143 133
144 void WidgetViewport::SetSize(unsigned int width, 134 void WidgetViewport::SetSize(unsigned int width,
145 unsigned int height) 135 unsigned int height)
146 { 136 {
147 boost::mutex::scoped_lock lock(mutex_);
148
149 background_.SetSize(width, height); 137 background_.SetSize(width, height);
150 138
151 if (centralWidget_.get() != NULL) 139 if (centralWidget_.get() != NULL)
152 { 140 {
153 centralWidget_->SetSize(width, height); 141 centralWidget_->SetSize(width, height);
157 } 145 }
158 146
159 147
160 bool WidgetViewport::Render(Orthanc::ImageAccessor& surface) 148 bool WidgetViewport::Render(Orthanc::ImageAccessor& surface)
161 { 149 {
162 boost::mutex::scoped_lock lock(mutex_);
163
164 if (!started_ || 150 if (!started_ ||
165 centralWidget_.get() == NULL) 151 centralWidget_.get() == NULL)
166 { 152 {
167 return false; 153 return false;
168 } 154 }
199 void WidgetViewport::MouseDown(MouseButton button, 185 void WidgetViewport::MouseDown(MouseButton button,
200 int x, 186 int x,
201 int y, 187 int y,
202 KeyboardModifiers modifiers) 188 KeyboardModifiers modifiers)
203 { 189 {
204 boost::mutex::scoped_lock lock(mutex_);
205
206 if (!started_) 190 if (!started_)
207 { 191 {
208 return; 192 return;
209 } 193 }
210 194
224 } 208 }
225 209
226 210
227 void WidgetViewport::MouseUp() 211 void WidgetViewport::MouseUp()
228 { 212 {
229 boost::mutex::scoped_lock lock(mutex_);
230
231 if (!started_) 213 if (!started_)
232 { 214 {
233 return; 215 return;
234 } 216 }
235 217
243 225
244 226
245 void WidgetViewport::MouseMove(int x, 227 void WidgetViewport::MouseMove(int x,
246 int y) 228 int y)
247 { 229 {
248 boost::mutex::scoped_lock lock(mutex_);
249
250 if (!started_) 230 if (!started_)
251 { 231 {
252 return; 232 return;
253 } 233 }
254 234
265 } 245 }
266 246
267 247
268 void WidgetViewport::MouseEnter() 248 void WidgetViewport::MouseEnter()
269 { 249 {
270 boost::mutex::scoped_lock lock(mutex_);
271 isMouseOver_ = true; 250 isMouseOver_ = true;
272 observers_.NotifyChange(this); 251 observers_.NotifyChange(this);
273 } 252 }
274 253
275 254
276 void WidgetViewport::MouseLeave() 255 void WidgetViewport::MouseLeave()
277 { 256 {
278 boost::mutex::scoped_lock lock(mutex_);
279 isMouseOver_ = false; 257 isMouseOver_ = false;
280 258
281 if (started_ && 259 if (started_ &&
282 mouseTracker_.get() != NULL) 260 mouseTracker_.get() != NULL)
283 { 261 {
292 void WidgetViewport::MouseWheel(MouseWheelDirection direction, 270 void WidgetViewport::MouseWheel(MouseWheelDirection direction,
293 int x, 271 int x,
294 int y, 272 int y,
295 KeyboardModifiers modifiers) 273 KeyboardModifiers modifiers)
296 { 274 {
297 boost::mutex::scoped_lock lock(mutex_);
298
299 if (!started_) 275 if (!started_)
300 { 276 {
301 return; 277 return;
302 } 278 }
303 279
310 286
311 287
312 void WidgetViewport::KeyPressed(char key, 288 void WidgetViewport::KeyPressed(char key,
313 KeyboardModifiers modifiers) 289 KeyboardModifiers modifiers)
314 { 290 {
315 boost::mutex::scoped_lock lock(mutex_);
316
317 if (centralWidget_.get() != NULL && 291 if (centralWidget_.get() != NULL &&
318 mouseTracker_.get() == NULL) 292 mouseTracker_.get() == NULL)
319 { 293 {
320 centralWidget_->KeyPressed(key, modifiers); 294 centralWidget_->KeyPressed(key, modifiers);
321 } 295 }
322 } 296 }
323 297
324 298
325 bool WidgetViewport::HasUpdateContent() 299 bool WidgetViewport::HasUpdateContent()
326 { 300 {
327 boost::mutex::scoped_lock lock(mutex_);
328
329 if (centralWidget_.get() != NULL) 301 if (centralWidget_.get() != NULL)
330 { 302 {
331 return centralWidget_->HasUpdateContent(); 303 return centralWidget_->HasUpdateContent();
332 } 304 }
333 else 305 else
337 } 309 }
338 310
339 311
340 void WidgetViewport::UpdateContent() 312 void WidgetViewport::UpdateContent()
341 { 313 {
342 boost::mutex::scoped_lock lock(mutex_);
343
344 if (centralWidget_.get() != NULL) 314 if (centralWidget_.get() != NULL)
345 { 315 {
346 centralWidget_->UpdateContent(); 316 centralWidget_->UpdateContent();
347 } 317 }
348 } 318 }