23 CurveMode::CurveMode (GLRenderer* renderer) : |
23 CurveMode::CurveMode (GLRenderer* renderer) : |
24 Super (renderer) {} |
24 Super (renderer) {} |
25 |
25 |
26 void CurveMode::render (QPainter& painter) const |
26 void CurveMode::render (QPainter& painter) const |
27 { |
27 { |
28 if (length(m_drawedVerts) >= 1) |
28 if (countof(m_drawedVerts) >= 1) |
29 { |
29 { |
30 Vertex curve[4]; |
30 Vertex curve[4]; |
31 QPoint curve2d[4]; |
31 QPoint curve2d[4]; |
32 |
32 |
33 for (int i = 0; i < qMin (length(curve), length(m_drawedVerts)); ++i) |
33 for (int i = 0; i < qMin (countof(curve), countof(m_drawedVerts)); ++i) |
34 curve[i] = m_drawedVerts[i]; |
34 curve[i] = m_drawedVerts[i]; |
35 |
35 |
36 // Factor the cursor into the preview |
36 // Factor the cursor into the preview |
37 if (length(m_drawedVerts) < 4) |
37 if (countof(m_drawedVerts) < 4) |
38 curve[length(m_drawedVerts)] = getCursorVertex(); |
38 curve[countof(m_drawedVerts)] = getCursorVertex(); |
39 |
39 |
40 // Default the control points to the first vertex position |
40 // Default the control points to the first vertex position |
41 if (length(m_drawedVerts) < 2) |
41 if (countof(m_drawedVerts) < 2) |
42 curve[2] = curve[0]; |
42 curve[2] = curve[0]; |
43 |
43 |
44 if (length(m_drawedVerts) < 3) |
44 if (countof(m_drawedVerts) < 3) |
45 curve[3] = curve[2]; |
45 curve[3] = curve[2]; |
46 |
46 |
47 for (int i = 0; i < length(curve); ++i) |
47 for (int i = 0; i < countof(curve); ++i) |
48 curve2d[i] = renderer()->convert3dTo2d (curve[i]); |
48 curve2d[i] = renderer()->convert3dTo2d (curve[i]); |
49 |
49 |
50 painter.setPen (QColor (0, 112, 112)); |
50 painter.setPen (QColor (0, 112, 112)); |
51 if (length(m_drawedVerts) >= 2) |
51 if (countof(m_drawedVerts) >= 2) |
52 painter.drawLine (curve2d[0], curve2d[2]); |
52 painter.drawLine (curve2d[0], curve2d[2]); |
53 |
53 |
54 if (length(m_drawedVerts) >= 3) |
54 if (countof(m_drawedVerts) >= 3) |
55 painter.drawLine (curve2d[1], curve2d[3]); |
55 painter.drawLine (curve2d[1], curve2d[3]); |
56 |
56 |
57 for (int i = 0; i < qMin (length(curve), length(m_drawedVerts) + 1); ++i) |
57 for (int i = 0; i < qMin (countof(curve), countof(m_drawedVerts) + 1); ++i) |
58 { |
58 { |
59 if (i < 2) |
59 if (i < 2) |
60 renderer()->drawPoint (painter, curve2d[i]); |
60 renderer()->drawPoint (painter, curve2d[i]); |
61 else |
61 else |
62 // Give control points a different color |
62 // Give control points a different color |
82 return EditModeType::Curve; |
82 return EditModeType::Curve; |
83 } |
83 } |
84 |
84 |
85 void CurveMode::endDraw() |
85 void CurveMode::endDraw() |
86 { |
86 { |
87 if (length(m_drawedVerts) == 4) |
87 if (countof(m_drawedVerts) == 4) |
88 { |
88 { |
89 LDObjectList objs; |
89 LDObjectList objs; |
90 objs << LDSpawn<LDBezierCurve> (m_drawedVerts[0], m_drawedVerts[1], m_drawedVerts[2], m_drawedVerts[3]); |
90 objs << LDSpawn<LDBezierCurve> (m_drawedVerts[0], m_drawedVerts[1], m_drawedVerts[2], m_drawedVerts[3]); |
91 finishDraw (objs); |
91 finishDraw (objs); |
92 } |
92 } |