src/editmodes/circleMode.cpp

changeset 1030
d931a7547578
parent 1026
fb320996cce0
child 1045
f726f8f49c7e
equal deleted inserted replaced
1029:9fc4c7d7c859 1030:d931a7547578
29 #include "../grid.h" 29 #include "../grid.h"
30 30
31 CircleMode::CircleMode (GLRenderer* renderer) : 31 CircleMode::CircleMode (GLRenderer* renderer) :
32 Super (renderer) {} 32 Super (renderer) {}
33 33
34
34 EditModeType CircleMode::type() const 35 EditModeType CircleMode::type() const
35 { 36 {
36 return EditModeType::Circle; 37 return EditModeType::Circle;
37 } 38 }
39
38 40
39 double CircleMode::getCircleDrawDist (int pos) const 41 double CircleMode::getCircleDrawDist (int pos) const
40 { 42 {
41 if (m_drawedVerts.size() >= pos + 1) 43 if (m_drawedVerts.size() >= pos + 1)
42 { 44 {
55 } 57 }
56 58
57 return 0.0; 59 return 0.0;
58 } 60 }
59 61
62
60 Matrix CircleMode::getCircleDrawMatrix (double scale) 63 Matrix CircleMode::getCircleDrawMatrix (double scale)
61 { 64 {
62 // Matrix templates. 2 is substituted with the scale value, 1 is inverted to -1 if needed. 65 // Matrix templates. 2 is substituted with the scale value, 1 is inverted to -1 if needed.
63 static const Matrix templates[3] = 66 static const Matrix templates[3] =
64 { 67 {
78 } 81 }
79 82
80 return transform; 83 return transform;
81 } 84 }
82 85
83 void CircleMode::buildCircle() 86
87 void CircleMode::endDraw()
84 { 88 {
85 LDObjectList objs; 89 LDObjectList objs;
86 PrimitiveSpec spec; 90 PrimitiveSpec spec;
87 spec.segments = m_window->ringToolSegments(); 91 spec.segments = m_window->ringToolSegments();
88 spec.divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution; 92 spec.divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution;
192 } 196 }
193 197
194 finishDraw (objs); 198 finishDraw (objs);
195 } 199 }
196 200
201
197 double CircleMode::getAngleOffset() const 202 double CircleMode::getAngleOffset() const
198 { 203 {
199 if (m_drawedVerts.isEmpty()) 204 if (m_drawedVerts.isEmpty())
200 return 0.0; 205 return 0.0;
201 206
209 angleoffset *= ((2 * pi) / divisions); // convert to radians 214 angleoffset *= ((2 * pi) / divisions); // convert to radians
210 angleoffset *= renderer()->depthNegateFactor(); // negate based on camera 215 angleoffset *= renderer()->depthNegateFactor(); // negate based on camera
211 return angleoffset; 216 return angleoffset;
212 } 217 }
213 218
219
214 void CircleMode::render (QPainter& painter) const 220 void CircleMode::render (QPainter& painter) const
215 { 221 {
216 QFontMetrics metrics = QFontMetrics (QFont()); 222 QFontMetrics metrics = QFontMetrics (QFont());
217 223
218 // If we have not specified the center point of the circle yet, preview it on the screen. 224 // If we have not specified the center point of the circle yet, preview it on the screen.
307 painter.drawText (origin.x() - (metrics.width (label) / 2), 313 painter.drawText (origin.x() - (metrics.width (label) / 2),
308 origin.y() + metrics.height(), QString::number (outerdistance)); 314 origin.y() + metrics.height(), QString::number (outerdistance));
309 } 315 }
310 } 316 }
311 317
312 bool CircleMode::mouseReleased (MouseEventData const& data)
313 {
314 if (Super::mouseReleased (data))
315 return true;
316
317 if (data.releasedButtons & Qt::LeftButton)
318 {
319 if (m_drawedVerts.size() < 3)
320 addDrawnVertex (renderer()->position3D());
321 else
322 buildCircle();
323
324 return true;
325 }
326
327 return false;
328 }
329 318
330 bool CircleMode::preAddVertex (const Vertex&) 319 bool CircleMode::preAddVertex (const Vertex&)
331 { 320 {
332 m_angleOffset = getAngleOffset(); 321 m_angleOffset = getAngleOffset();
333 return false; 322 return false;
334 } 323 }
324
325
326 int CircleMode::maxVertices() const
327 {
328 return 3;
329 }

mercurial