diff Framework/Scene2DViewport/LineMeasureTool.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 712ff6ff3c19
children 61ba4b504e9a
line wrap: on
line diff
--- a/Framework/Scene2DViewport/LineMeasureTool.cpp	Thu May 23 10:25:48 2019 +0200
+++ b/Framework/Scene2DViewport/LineMeasureTool.cpp	Fri May 24 15:59:51 2019 +0200
@@ -72,16 +72,34 @@
     RefreshScene();
   }
 
+  
+
+  bool LineMeasureTool::HitTest(ScenePoint2D p) const
+  {
+    const double pixelToScene =
+      GetScene()->GetCanvasToSceneTransform().ComputeZoom();
+
+    // the hit test will return true if the supplied point (in scene coords)
+    // is close to the handle or to the line.
+
+    // since the handle is small, a nice approximation is to defined this
+    // as a threshold on the distance between the point and the handle center.
+
+    // this threshold is defined as a constant value in CANVAS units.
+
+
+    // line equation from two points (non-normalized)
+    // (y0-y1)*x + (x1-x0)*xy + (x0*y1 - x1*y0) = 0
+    // 
+    return false;
+  }
+
   void LineMeasureTool::RefreshScene()
   {
     if (IsSceneAlive())
     {
       if (IsEnabled())
       {
-        // get the scaling factor 
-        const double pixelToScene =
-          GetScene()->GetCanvasToSceneTransform().ComputeZoom();
-
         layerHolder_->CreateLayersIfNeeded();
 
         {
@@ -89,7 +107,10 @@
 
           PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0);
           polylineLayer->ClearAllChains();
-          polylineLayer->SetColor(0, 223, 21);
+          polylineLayer->SetColor(
+            TOOL_LINES_COLOR_RED, 
+            TOOL_LINES_COLOR_GREEN, 
+            TOOL_LINES_COLOR_BLUE);
 
           {
             PolylineSceneLayer::Chain chain;
@@ -100,13 +121,12 @@
 
           // handles
           {
-            //void AddSquare(PolylineSceneLayer::Chain& chain,const Scene2D& scene,const ScenePoint2D& centerS,const double& sideLength)
-
             {
               PolylineSceneLayer::Chain chain;
               
               //TODO: take DPI into account
-              AddSquare(chain, GetScene(), start_, 10.0 * pixelToScene);
+              AddSquare(chain, GetScene(), start_, 
+                GetController()->GetHandleSideLengthS());
               
               polylineLayer->AddChain(chain, true);
             }
@@ -115,7 +135,8 @@
               PolylineSceneLayer::Chain chain;
               
               //TODO: take DPI into account
-              AddSquare(chain, GetScene(), end_, 10.0 * pixelToScene);
+              AddSquare(chain, GetScene(), end_, 
+                GetController()->GetHandleSideLengthS());
               
               polylineLayer->AddChain(chain, true);
             }
@@ -123,8 +144,7 @@
 
         }
         {
-          // Set the text layer proporeties
-
+          // Set the text layer propreties
           double deltaX = end_.GetX() - start_.GetX();
           double deltaY = end_.GetY() - start_.GetY();
           double squareDist = deltaX * deltaX + deltaY * deltaY;
@@ -147,4 +167,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}