comparison Framework/Scene2DViewport/ViewportController.cpp @ 1214:741201eab130 broker

removing pointer to viewport from ViewportController
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Dec 2019 19:12:08 +0100
parents 86a8266b8888
children 9efa66d8d3f8
comparison
equal deleted inserted replaced
1213:86a8266b8888 1214:741201eab130
30 30
31 #include <boost/make_shared.hpp> 31 #include <boost/make_shared.hpp>
32 32
33 namespace OrthancStone 33 namespace OrthancStone
34 { 34 {
35 IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(boost::shared_ptr<ViewportController> controller, 35 IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(
36 const PointerEvent& event) 36 boost::shared_ptr<ViewportController> controller,
37 IViewport& viewport,
38 const PointerEvent& event)
37 { 39 {
38 switch (event.GetMouseButton()) 40 switch (event.GetMouseButton())
39 { 41 {
40 case MouseButton_Left: 42 case MouseButton_Left:
41 return new RotateSceneTracker(controller, event); 43 return new RotateSceneTracker(controller, event);
43 case MouseButton_Middle: 45 case MouseButton_Middle:
44 return new PanSceneTracker(controller, event); 46 return new PanSceneTracker(controller, event);
45 47
46 case MouseButton_Right: 48 case MouseButton_Right:
47 { 49 {
48 std::auto_ptr<IViewport::ILock> lock(controller->GetViewport().Lock()); 50 std::auto_ptr<IViewport::ILock> lock(viewport.Lock());
49 if (lock->HasCompositor()) 51 if (lock->HasCompositor())
50 { 52 {
51 return new ZoomSceneTracker(controller, event, lock->GetCompositor().GetCanvasWidth()); 53 return new ZoomSceneTracker(controller, event, lock->GetCompositor().GetCanvasWidth());
52 } 54 }
53 else 55 else
60 return NULL; 62 return NULL;
61 } 63 }
62 } 64 }
63 65
64 66
65 ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW, 67 ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW)
66 boost::shared_ptr<IViewport> viewport)
67 : undoStackW_(undoStackW) 68 : undoStackW_(undoStackW)
68 , viewport_(viewport)
69 , canvasToSceneFactor_(1) 69 , canvasToSceneFactor_(1)
70 { 70 {
71 if (viewport.get() == NULL)
72 {
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
74 }
75 } 71 }
76 72
77 ViewportController::~ViewportController() 73 ViewportController::~ViewportController()
78 { 74 {
79 } 75 }
183 179
184 canvasToSceneFactor_ = scene_.GetCanvasToSceneTransform().ComputeZoom(); 180 canvasToSceneFactor_ = scene_.GetCanvasToSceneTransform().ComputeZoom();
185 BroadcastMessage(SceneTransformChanged(*this)); 181 BroadcastMessage(SceneTransformChanged(*this));
186 } 182 }
187 183
188 void ViewportController::FitContent() 184 void ViewportController::FitContent(IViewport& viewport)
189 { 185 {
190 { 186 {
191 std::auto_ptr<IViewport::ILock> lock(viewport_->Lock()); 187 std::auto_ptr<IViewport::ILock> lock(viewport.Lock());
192 lock->FitContent(scene_); 188 lock->FitContent(scene_);
193 } 189 }
194 190
195 canvasToSceneFactor_ = scene_.GetCanvasToSceneTransform().ComputeZoom(); 191 canvasToSceneFactor_ = scene_.GetCanvasToSceneTransform().ComputeZoom();
196 BroadcastMessage(SceneTransformChanged(*this)); 192 BroadcastMessage(SceneTransformChanged(*this));
236 { 232 {
237 return TEXT_CENTER_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor(); 233 return TEXT_CENTER_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor();
238 } 234 }
239 235
240 236
241 void ViewportController::HandleMousePress(IViewportInteractor& interactor, 237 void ViewportController::HandleMousePress(IViewport& viewport,
238 IViewportInteractor& interactor,
242 const PointerEvent& event) 239 const PointerEvent& event)
243 { 240 {
244 if (activeTracker_) 241 if (activeTracker_)
245 { 242 {
246 // We are dealing with a multi-stage tracker (that is made of several interactions) 243 // We are dealing with a multi-stage tracker (that is made of several interactions)
262 return; 259 return;
263 } 260 }
264 } 261 }
265 262
266 // No measure tool, create new tracker from the interactor 263 // No measure tool, create new tracker from the interactor
267 activeTracker_.reset(interactor.CreateTracker(shared_from_this(), event)); 264 activeTracker_.reset(interactor.CreateTracker(shared_from_this(), viewport, event));
268 } 265 }
269 } 266 }
270 267
271 void ViewportController::HandleMouseMove(const PointerEvent& event) 268 void ViewportController::HandleMouseMove(const PointerEvent& event)
272 { 269 {