comparison Samples/Common/AngleMeasureTool.cpp @ 656:002d9562c8f5

Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this might also be needed on macos and GNU/Linux ?) + fixed text info overlay pos for angle measure (this requires the app to be aware of the compositor)
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 14 May 2019 16:54:13 +0200
parents 462a5074f914
children cb3b76d16234
comparison
equal deleted inserted replaced
655:1e26bb5f2a02 656:002d9562c8f5
85 85
86 void AngleMeasureTool::RefreshScene() 86 void AngleMeasureTool::RefreshScene()
87 { 87 {
88 if (IsEnabled()) 88 if (IsEnabled())
89 { 89 {
90
91 // get the scaling factor 90 // get the scaling factor
92 const double pixelToScene = 91 const double pixelToScene =
93 GetScene().GetCanvasToSceneTransform().ComputeZoom(); 92 GetScene().GetCanvasToSceneTransform().ComputeZoom();
94 93
95 if (!layersCreated) 94 if (!layersCreated)
158 157
159 // arc 158 // arc
160 { 159 {
161 PolylineSceneLayer::Chain chain; 160 PolylineSceneLayer::Chain chain;
162 161
162 const double ARC_RADIUS_CANVAS_COORD = 20.0;
163 AddShortestArc(chain, GetScene(), side1End_, center_, side2End_, 163 AddShortestArc(chain, GetScene(), side1End_, center_, side2End_,
164 20.0*pixelToScene); 164 ARC_RADIUS_CANVAS_COORD*pixelToScene);
165 polylineLayer->AddChain(chain, false); 165 polylineLayer->AddChain(chain, false);
166 } 166 }
167 } 167 }
168 { 168 {
169 // Set the text layer proporeties 169 // Set the text layer
170 170
171 // the angle is measured in a clockwise way between the points 171 double p1cAngle = atan2(
172 double angleRad = MeasureAngle(side1End_, center_, side2End_); 172 side1End_.GetY() - center_.GetY(),
173 double angleDeg = RadiansToDegrees(angleRad); 173 side1End_.GetX() - center_.GetX());
174 174 double p2cAngle = atan2(
175 side2End_.GetY() - center_.GetY(),
176 side2End_.GetX() - center_.GetX());
177 double delta = NormalizeAngle(p2cAngle - p1cAngle);
178 double theta = delta/2;
179
180 const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 40.0;
181
182 double offsetX = TEXT_CENTER_DISTANCE_CANVAS_COORD * cos(theta);
183 double offsetY = TEXT_CENTER_DISTANCE_CANVAS_COORD * sin(theta);
184 double pointX = center_.GetX() + offsetX;
185 double pointY = center_.GetY() + offsetY;
186
175 TextSceneLayer* textLayer = GetTextLayer(); 187 TextSceneLayer* textLayer = GetTextLayer();
176 188
177 char buf[64]; 189 char buf[64];
190 double angleDeg = RadiansToDegrees(delta);
178 sprintf(buf, "%0.02f deg", angleDeg); 191 sprintf(buf, "%0.02f deg", angleDeg);
179 textLayer->SetText(buf); 192 textLayer->SetText(buf);
180 textLayer->SetColor(0, 223, 21); 193 textLayer->SetColor(0, 223, 21);
181 194
182 ScenePoint2D textAnchor; 195 ScenePoint2D textAnchor;
183 GetPositionOnBisectingLine( 196 //GetPositionOnBisectingLine(
184 textAnchor, side1End_, center_, side2End_, 40.0*pixelToScene); 197 // textAnchor, side1End_, center_, side2End_, 40.0*pixelToScene);
185 textLayer->SetPosition(textAnchor.GetX(), textAnchor.GetY()); 198 textLayer->SetPosition(pointX, pointY);
186 } 199 }
187 } 200 }
188 else 201 else
189 { 202 {
190 if (layersCreated) 203 if (layersCreated)