22 #include "../ldObject.h" |
22 #include "../ldObject.h" |
23 #include "../glRenderer.h" |
23 #include "../glRenderer.h" |
24 |
24 |
25 RectangleMode::RectangleMode (GLRenderer* renderer) : |
25 RectangleMode::RectangleMode (GLRenderer* renderer) : |
26 Super (renderer), |
26 Super (renderer), |
27 _rectangleVerts (QVector<Vertex>(4)) {} |
27 m_rectangleVerts (QVector<Vertex>(4)) {} |
28 |
28 |
29 EditModeType RectangleMode::type() const |
29 EditModeType RectangleMode::type() const |
30 { |
30 { |
31 return EditModeType::Rectangle; |
31 return EditModeType::Rectangle; |
32 } |
32 } |
33 |
33 |
34 void RectangleMode::render (QPainter& painter) const |
34 void RectangleMode::render (QPainter& painter) const |
35 { |
35 { |
36 renderPolygon (painter, (_drawedVerts.size() > 0) ? _rectangleVerts : |
36 renderPolygon (painter, (m_drawedVerts.size() > 0) ? m_rectangleVerts : |
37 QVector<Vertex> ({renderer()->position3D()}), false); |
37 QVector<Vertex> ({renderer()->position3D()}), false); |
38 } |
38 } |
39 |
39 |
40 bool RectangleMode::mouseReleased (MouseEventData const& data) |
40 bool RectangleMode::mouseReleased (MouseEventData const& data) |
41 { |
41 { |
42 if (Super::mouseReleased (data)) |
42 if (Super::mouseReleased (data)) |
43 return true; |
43 return true; |
44 |
44 |
45 if (data.releasedButtons & Qt::LeftButton) |
45 if (data.releasedButtons & Qt::LeftButton) |
46 { |
46 { |
47 if (_drawedVerts.size() == 2) |
47 if (m_drawedVerts.size() == 2) |
48 { |
48 { |
49 LDQuadPtr quad (spawn<LDQuad>()); |
49 LDQuadPtr quad (LDSpawn<LDQuad>()); |
50 updateRectVerts(); |
50 updateRectVerts(); |
51 |
51 |
52 for (int i = 0; i < quad->numVertices(); ++i) |
52 for (int i = 0; i < quad->numVertices(); ++i) |
53 quad->setVertex (i, _rectangleVerts[i]); |
53 quad->setVertex (i, m_rectangleVerts[i]); |
54 |
54 |
55 quad->setColor (maincolor()); |
55 quad->setColor (MainColor()); |
56 finishDraw (LDObjectList ({quad})); |
56 finishDraw (LDObjectList ({quad})); |
57 return true; |
57 return true; |
58 } |
58 } |
59 |
59 |
60 addDrawnVertex (renderer()->position3D()); |
60 addDrawnVertex (renderer()->position3D()); |
73 return false; |
73 return false; |
74 } |
74 } |
75 |
75 |
76 void RectangleMode::updateRectVerts() |
76 void RectangleMode::updateRectVerts() |
77 { |
77 { |
78 if (_drawedVerts.isEmpty()) |
78 if (m_drawedVerts.isEmpty()) |
79 { |
79 { |
80 for (int i = 0; i < 4; ++i) |
80 for (int i = 0; i < 4; ++i) |
81 _rectangleVerts[i] = renderer()->position3D(); |
81 m_rectangleVerts[i] = renderer()->position3D(); |
82 |
82 |
83 return; |
83 return; |
84 } |
84 } |
85 |
85 |
86 Vertex v0 = _drawedVerts[0], |
86 Vertex v0 = m_drawedVerts[0], |
87 v1 = (_drawedVerts.size() >= 2) ? _drawedVerts[1] : renderer()->position3D(); |
87 v1 = (m_drawedVerts.size() >= 2) ? m_drawedVerts[1] : renderer()->position3D(); |
88 |
88 |
89 const Axis localx = renderer()->getCameraAxis (false), |
89 const Axis localx = renderer()->getCameraAxis (false), |
90 localy = renderer()->getCameraAxis (true), |
90 localy = renderer()->getCameraAxis (true), |
91 localz = (Axis) (3 - localx - localy); |
91 localz = (Axis) (3 - localx - localy); |
92 |
92 |
93 for (int i = 0; i < 4; ++i) |
93 for (int i = 0; i < 4; ++i) |
94 _rectangleVerts[i].setCoordinate (localz, renderer()->getDepthValue()); |
94 m_rectangleVerts[i].setCoordinate (localz, renderer()->getDepthValue()); |
95 |
95 |
96 _rectangleVerts[0].setCoordinate (localx, v0[localx]); |
96 m_rectangleVerts[0].setCoordinate (localx, v0[localx]); |
97 _rectangleVerts[0].setCoordinate (localy, v0[localy]); |
97 m_rectangleVerts[0].setCoordinate (localy, v0[localy]); |
98 _rectangleVerts[1].setCoordinate (localx, v1[localx]); |
98 m_rectangleVerts[1].setCoordinate (localx, v1[localx]); |
99 _rectangleVerts[1].setCoordinate (localy, v0[localy]); |
99 m_rectangleVerts[1].setCoordinate (localy, v0[localy]); |
100 _rectangleVerts[2].setCoordinate (localx, v1[localx]); |
100 m_rectangleVerts[2].setCoordinate (localx, v1[localx]); |
101 _rectangleVerts[2].setCoordinate (localy, v1[localy]); |
101 m_rectangleVerts[2].setCoordinate (localy, v1[localy]); |
102 _rectangleVerts[3].setCoordinate (localx, v0[localx]); |
102 m_rectangleVerts[3].setCoordinate (localx, v0[localx]); |
103 _rectangleVerts[3].setCoordinate (localy, v1[localy]); |
103 m_rectangleVerts[3].setCoordinate (localy, v1[localy]); |
104 } |
104 } |