diff 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
line wrap: on
line diff
--- a/Framework/Scene2DViewport/ViewportController.cpp	Wed Mar 04 10:07:14 2020 +0100
+++ b/Framework/Scene2DViewport/ViewportController.cpp	Wed Mar 04 10:07:37 2020 +0100
@@ -33,24 +33,24 @@
 namespace OrthancStone
 {
   IFlexiblePointerTracker* DefaultViewportInteractor::CreateTracker(
-    boost::shared_ptr<ViewportController> controller,
+    IViewport&          viewport,
     const PointerEvent& event,
-    unsigned int viewportWidth,
-    unsigned int viewportHeight)
+    unsigned int        viewportWidth,
+    unsigned int        viewportHeight)
   {
     switch (event.GetMouseButton())
     {
       case MouseButton_Left:
-        return new RotateSceneTracker(controller, event);
+        return new RotateSceneTracker(viewport, event);
 
       case MouseButton_Middle:
-        return new PanSceneTracker(controller, event);
+        return new PanSceneTracker(viewport, event);
       
       case MouseButton_Right:
       {
         if (viewportWidth != 0)
         {
-          return new ZoomSceneTracker(controller, event, viewportWidth);
+          return new ZoomSceneTracker(viewport, event, viewportWidth);
         }
         else
         {
@@ -64,24 +64,29 @@
   }
 
 
-  ViewportController::ViewportController() :
-    undoStackW_(boost::make_shared<OrthancStone::UndoStack>()),
-    scene_(new Scene2D),
-    canvasToSceneFactor_(1)
+  ViewportController::ViewportController(IViewport& viewport) 
+    : viewport_(viewport)
+    , undoStackW_(boost::make_shared<OrthancStone::UndoStack>())
+    , scene_(new Scene2D)
+    , canvasToSceneFactor_(1)
   {
   }
 
-  ViewportController::ViewportController(const Scene2D& scene) : 
-    undoStackW_(boost::make_shared<OrthancStone::UndoStack>()),
-    scene_(scene.Clone()),
-    canvasToSceneFactor_(1)
+  ViewportController::ViewportController(IViewport& viewport,
+                                         const Scene2D& scene)
+    : viewport_(viewport)
+    , undoStackW_(boost::make_shared<OrthancStone::UndoStack>())
+    , scene_(scene.Clone())
+    , canvasToSceneFactor_(1)
   {
   }
 
-  ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW) :
-    undoStackW_(undoStackW),
-    scene_(new Scene2D),
-    canvasToSceneFactor_(1)
+  ViewportController::ViewportController(IViewport& viewport, 
+                                         boost::weak_ptr<UndoStack> undoStackW)
+    : viewport_(viewport)
+    , undoStackW_(undoStackW)
+    , scene_(new Scene2D)
+    , canvasToSceneFactor_(1)
   {
   }
  
@@ -274,7 +279,7 @@
       }
 
       // No measure tool, create new tracker from the interactor
-      activeTracker_.reset(interactor.CreateTracker(shared_from_this(), event, viewportWidth, viewportHeight));
+      activeTracker_.reset(interactor.CreateTracker(viewport_, event, viewportWidth, viewportHeight));
     }
   }