diff Framework/Scene2DViewport/ViewportController.cpp @ 774:66ac7a2d1e3a

A few renames and cleanups + moved GUI constants to controller + start work on hit tests for measure tools and mouse hover.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 24 May 2019 15:59:51 +0200
parents 07adcffba38c
children e42b491f1fb2
line wrap: on
line diff
--- a/Framework/Scene2DViewport/ViewportController.cpp	Thu May 23 10:25:48 2019 +0200
+++ b/Framework/Scene2DViewport/ViewportController.cpp	Fri May 24 15:59:51 2019 +0200
@@ -30,10 +30,16 @@
   ViewportController::ViewportController(MessageBroker& broker)
     : IObservable(broker)
     , numAppliedCommands_(0)
+    , canvasToSceneFactor_(0.0)
   {
     scene_ = boost::make_shared<Scene2D>();
   }
 
+  Scene2DConstPtr ViewportController::GetScene() const
+  {
+    return scene_;
+  }
+
   Scene2DPtr ViewportController::GetScene()
   {
     return scene_;
@@ -49,11 +55,11 @@
   {
     std::vector<MeasureToolPtr> ret;
     
-
-    //for (size_t i = 0; i < measureTools_.size(); ++i)
-    //{
-
-    //}
+    for (size_t i = 0; i < measureTools_.size(); ++i)
+    {
+      if (measureTools_[i]->HitTest(p))
+        ret.push_back(measureTools_[i]);
+    }
     return ret;
   }
 
@@ -72,6 +78,10 @@
   {
     scene_->SetSceneToCanvasTransform(transform);
     BroadcastMessage(SceneTransformChanged(*this));
+    
+    // update the canvas to scene factor
+    canvasToSceneFactor_ = 0.0;
+    canvasToSceneFactor_ = GetCanvasToSceneFactor();
   }
 
   void ViewportController::FitContent(
@@ -132,5 +142,36 @@
       std::remove(measureTools_.begin(), measureTools_.end(), measureTool), 
       measureTools_.end());
   }
+
+
+  double ViewportController::GetCanvasToSceneFactor() const
+  {
+    if (canvasToSceneFactor_ == 0)
+    {
+      canvasToSceneFactor_ =
+        GetScene()->GetCanvasToSceneTransform().ComputeZoom();
+    }
+    return canvasToSceneFactor_;
+  }
+
+  double ViewportController::GetHandleSideLengthS() const
+  {
+    return HANDLE_SIDE_LENGTH_CANVAS_COORD * GetCanvasToSceneFactor();
+  }
+
+  double ViewportController::GetAngleToolArcRadiusS() const
+  {
+    return ARC_RADIUS_CANVAS_COORD * GetCanvasToSceneFactor();
+  }
+
+  double ViewportController::GetHitTestMaximumDistanceS() const
+  {
+    return HIT_TEST_MAX_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor();
+  }
+
+  double ViewportController::GetAngleTopTextLabelDistanceS() const
+  {
+    return TEXT_CENTER_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor();
+  }
 }