comparison Framework/Scene2DViewport/ViewportController.cpp @ 1307:8a28a9bf8876 broker

ViewportController now gets a ref to its parent viewport for proper lock usage
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 04 Mar 2020 10:07:37 +0100
parents 7ec8fea061b9
children 1f877e0846fe
comparison
equal deleted inserted replaced
1306:fef1ec42a7db 1307:8a28a9bf8876
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( 35 IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(
36 boost::shared_ptr<ViewportController> controller, 36 IViewport& viewport,
37 const PointerEvent& event, 37 const PointerEvent& event,
38 unsigned int viewportWidth, 38 unsigned int viewportWidth,
39 unsigned int viewportHeight) 39 unsigned int viewportHeight)
40 { 40 {
41 switch (event.GetMouseButton()) 41 switch (event.GetMouseButton())
42 { 42 {
43 case MouseButton_Left: 43 case MouseButton_Left:
44 return new RotateSceneTracker(controller, event); 44 return new RotateSceneTracker(viewport, event);
45 45
46 case MouseButton_Middle: 46 case MouseButton_Middle:
47 return new PanSceneTracker(controller, event); 47 return new PanSceneTracker(viewport, event);
48 48
49 case MouseButton_Right: 49 case MouseButton_Right:
50 { 50 {
51 if (viewportWidth != 0) 51 if (viewportWidth != 0)
52 { 52 {
53 return new ZoomSceneTracker(controller, event, viewportWidth); 53 return new ZoomSceneTracker(viewport, event, viewportWidth);
54 } 54 }
55 else 55 else
56 { 56 {
57 return NULL; 57 return NULL;
58 } 58 }
62 return NULL; 62 return NULL;
63 } 63 }
64 } 64 }
65 65
66 66
67 ViewportController::ViewportController() : 67 ViewportController::ViewportController(IViewport& viewport)
68 undoStackW_(boost::make_shared<OrthancStone::UndoStack>()), 68 : viewport_(viewport)
69 scene_(new Scene2D), 69 , undoStackW_(boost::make_shared<OrthancStone::UndoStack>())
70 canvasToSceneFactor_(1) 70 , scene_(new Scene2D)
71 { 71 , canvasToSceneFactor_(1)
72 } 72 {
73 73 }
74 ViewportController::ViewportController(const Scene2D& scene) : 74
75 undoStackW_(boost::make_shared<OrthancStone::UndoStack>()), 75 ViewportController::ViewportController(IViewport& viewport,
76 scene_(scene.Clone()), 76 const Scene2D& scene)
77 canvasToSceneFactor_(1) 77 : viewport_(viewport)
78 { 78 , undoStackW_(boost::make_shared<OrthancStone::UndoStack>())
79 } 79 , scene_(scene.Clone())
80 80 , canvasToSceneFactor_(1)
81 ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW) : 81 {
82 undoStackW_(undoStackW), 82 }
83 scene_(new Scene2D), 83
84 canvasToSceneFactor_(1) 84 ViewportController::ViewportController(IViewport& viewport,
85 boost::weak_ptr<UndoStack> undoStackW)
86 : viewport_(viewport)
87 , undoStackW_(undoStackW)
88 , scene_(new Scene2D)
89 , canvasToSceneFactor_(1)
85 { 90 {
86 } 91 }
87 92
88 ViewportController::~ViewportController() 93 ViewportController::~ViewportController()
89 { 94 {
272 return; 277 return;
273 } 278 }
274 } 279 }
275 280
276 // No measure tool, create new tracker from the interactor 281 // No measure tool, create new tracker from the interactor
277 activeTracker_.reset(interactor.CreateTracker(shared_from_this(), event, viewportWidth, viewportHeight)); 282 activeTracker_.reset(interactor.CreateTracker(viewport_, event, viewportWidth, viewportHeight));
278 } 283 }
279 } 284 }
280 285
281 bool ViewportController::HandleMouseMove(const PointerEvent& event) 286 bool ViewportController::HandleMouseMove(const PointerEvent& event)
282 { 287 {