diff Framework/Scene2D/RotateSceneTracker.cpp @ 700:059e1fd05fd6 refactor-viewport-controller

Introduced the ViewportController that sits between the application and the Scene2D to handle the trackers and measuring tools. This is a work in progress. The Scene2D is no longer an observable. Message sending is managed by the ViewportController. Move some refs to shared and weak to prevent lifetime issues.
author Benjamin Golinvaux <bgo@osimis.io>
date Sun, 19 May 2019 16:26:17 +0200
parents 7efa2543699d
children c0fcb2757b0a
line wrap: on
line diff
--- a/Framework/Scene2D/RotateSceneTracker.cpp	Fri May 17 09:20:46 2019 +0200
+++ b/Framework/Scene2D/RotateSceneTracker.cpp	Sun May 19 16:26:17 2019 +0200
@@ -18,23 +18,22 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  **/
 
-
 #include "RotateSceneTracker.h"
+#include <Framework/Scene2DViewport/ViewportController.h>
 
 namespace OrthancStone
 {
-  RotateSceneTracker::RotateSceneTracker(Scene2D& scene,
-                                         const PointerEvent& event) :
-    scene_(scene),
-    click_(event.GetMainPosition()),
-    aligner_(scene, click_),
-    isFirst_(true),
-    originalSceneToCanvas_(scene.GetSceneToCanvasTransform())
+  RotateSceneTracker::RotateSceneTracker(ViewportControllerWPtr controllerW,
+                                         const PointerEvent& event)
+    : OneGesturePointerTracker(controllerW)
+    , click_(event.GetMainPosition())
+    , aligner_(controllerW, click_)
+    , isFirst_(true)
+    , originalSceneToCanvas_(GetController()->GetSceneToCanvasTransform())
   {
   }
-
-
-  void RotateSceneTracker::Update(const PointerEvent& event)
+  
+  void RotateSceneTracker::PointerMove(const PointerEvent& event)
   {
     ScenePoint2D p = event.GetMainPosition();
     double dx = p.GetX() - click_.GetX();
@@ -51,7 +50,7 @@
         isFirst_ = false;
       }
 
-      scene_.SetSceneToCanvasTransform(
+      GetController()->SetSceneToCanvasTransform(
         AffineTransform2D::Combine(
           AffineTransform2D::CreateRotation(a - referenceAngle_),
           originalSceneToCanvas_));
@@ -59,4 +58,10 @@
       aligner_.Apply();
     }
   }
+
+  void RotateSceneTracker::Cancel()
+  {
+    GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_);
+  }
+
 }