comparison 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
comparison
equal deleted inserted replaced
761:07adcffba38c 774:66ac7a2d1e3a
70 start_ = start; 70 start_ = start;
71 end_ = end; 71 end_ = end;
72 RefreshScene(); 72 RefreshScene();
73 } 73 }
74 74
75
76
77 bool LineMeasureTool::HitTest(ScenePoint2D p) const
78 {
79 const double pixelToScene =
80 GetScene()->GetCanvasToSceneTransform().ComputeZoom();
81
82 // the hit test will return true if the supplied point (in scene coords)
83 // is close to the handle or to the line.
84
85 // since the handle is small, a nice approximation is to defined this
86 // as a threshold on the distance between the point and the handle center.
87
88 // this threshold is defined as a constant value in CANVAS units.
89
90
91 // line equation from two points (non-normalized)
92 // (y0-y1)*x + (x1-x0)*xy + (x0*y1 - x1*y0) = 0
93 //
94 return false;
95 }
96
75 void LineMeasureTool::RefreshScene() 97 void LineMeasureTool::RefreshScene()
76 { 98 {
77 if (IsSceneAlive()) 99 if (IsSceneAlive())
78 { 100 {
79 if (IsEnabled()) 101 if (IsEnabled())
80 { 102 {
81 // get the scaling factor
82 const double pixelToScene =
83 GetScene()->GetCanvasToSceneTransform().ComputeZoom();
84
85 layerHolder_->CreateLayersIfNeeded(); 103 layerHolder_->CreateLayersIfNeeded();
86 104
87 { 105 {
88 // Fill the polyline layer with the measurement line 106 // Fill the polyline layer with the measurement line
89 107
90 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0); 108 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0);
91 polylineLayer->ClearAllChains(); 109 polylineLayer->ClearAllChains();
92 polylineLayer->SetColor(0, 223, 21); 110 polylineLayer->SetColor(
111 TOOL_LINES_COLOR_RED,
112 TOOL_LINES_COLOR_GREEN,
113 TOOL_LINES_COLOR_BLUE);
93 114
94 { 115 {
95 PolylineSceneLayer::Chain chain; 116 PolylineSceneLayer::Chain chain;
96 chain.push_back(start_); 117 chain.push_back(start_);
97 chain.push_back(end_); 118 chain.push_back(end_);
98 polylineLayer->AddChain(chain, false); 119 polylineLayer->AddChain(chain, false);
99 } 120 }
100 121
101 // handles 122 // handles
102 { 123 {
103 //void AddSquare(PolylineSceneLayer::Chain& chain,const Scene2D& scene,const ScenePoint2D& centerS,const double& sideLength)
104
105 { 124 {
106 PolylineSceneLayer::Chain chain; 125 PolylineSceneLayer::Chain chain;
107 126
108 //TODO: take DPI into account 127 //TODO: take DPI into account
109 AddSquare(chain, GetScene(), start_, 10.0 * pixelToScene); 128 AddSquare(chain, GetScene(), start_,
129 GetController()->GetHandleSideLengthS());
110 130
111 polylineLayer->AddChain(chain, true); 131 polylineLayer->AddChain(chain, true);
112 } 132 }
113 133
114 { 134 {
115 PolylineSceneLayer::Chain chain; 135 PolylineSceneLayer::Chain chain;
116 136
117 //TODO: take DPI into account 137 //TODO: take DPI into account
118 AddSquare(chain, GetScene(), end_, 10.0 * pixelToScene); 138 AddSquare(chain, GetScene(), end_,
139 GetController()->GetHandleSideLengthS());
119 140
120 polylineLayer->AddChain(chain, true); 141 polylineLayer->AddChain(chain, true);
121 } 142 }
122 } 143 }
123 144
124 } 145 }
125 { 146 {
126 // Set the text layer proporeties 147 // Set the text layer propreties
127
128 double deltaX = end_.GetX() - start_.GetX(); 148 double deltaX = end_.GetX() - start_.GetX();
129 double deltaY = end_.GetY() - start_.GetY(); 149 double deltaY = end_.GetY() - start_.GetY();
130 double squareDist = deltaX * deltaX + deltaY * deltaY; 150 double squareDist = deltaX * deltaX + deltaY * deltaY;
131 double dist = sqrt(squareDist); 151 double dist = sqrt(squareDist);
132 char buf[64]; 152 char buf[64];