src/editmodes/linePathMode.cpp

Wed, 03 Sep 2014 01:44:51 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 03 Sep 2014 01:44:51 +0300
changeset 876
f040f0fb3795
parent 875
src/editmodes/lineLoopMode.cpp@ce8e9b37d44f
child 941
f895379d7fab
child 945
c310073e4f22
permissions
-rw-r--r--

- renamed line loop to line path, updated changelog

876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
1 #include "linePathMode.h"
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 #include "../glRenderer.h"
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
3 #include "../mainWindow.h"
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
4 #include <QKeyEvent>
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
6 LinePathMode::LinePathMode (GLRenderer *renderer) :
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 Super (renderer) {}
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
9 void LinePathMode::render (QPainter& painter) const
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 {
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 QVector<QPointF> points;
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
12 QList<Vertex> points3d (m_drawedVerts);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
13 points3d << renderer()->position3D();
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
15 for (Vertex const& vrt : points3d)
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 points << renderer()->coordconv3_2 (vrt);
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 painter.setPen (renderer()->textPen());
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
19 assert (points.size() == points3d.size());
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 for (int i = 0; i < points.size() - 1; ++i)
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
22 {
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 painter.drawLine (QLineF (points[i], points[i + 1]));
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
24 drawLength (painter, points3d[i], points3d[i + 1], points[i], points[i + 1]);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
25 }
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 for (QPointF const& point : points)
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 renderer()->drawBlip (painter, point);
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 }
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
31 bool LinePathMode::mouseReleased (MouseEventData const& data)
874
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 {
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 if (Super::mouseReleased (data))
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 return true;
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 if (data.releasedButtons & Qt::LeftButton)
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 addDrawnVertex (renderer()->position3D());
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 return true;
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 }
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 return false;
ba75c789667e - added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 }
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
44
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
45 bool LinePathMode::preAddVertex (Vertex const& pos)
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
46 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
47 // If we picked an the last vertex, stop drawing
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
48 if (not m_drawedVerts.isEmpty() and pos == m_drawedVerts.last())
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
49 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
50 endDraw();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
51 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
52 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
53
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
54 return false;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
55 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
56
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
57 void LinePathMode::endDraw()
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
58 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
59 LDObjectList objs;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
60
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
61 for (int i = 0; i < m_drawedVerts.size() - 1; ++i)
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
62 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
63 LDLinePtr line = LDSpawn<LDLine>();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
64 line->setVertex (0, m_drawedVerts[i]);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
65 line->setVertex (1, m_drawedVerts[i + 1]);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
66 objs << line;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
67 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
68
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
69 finishDraw (objs);
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
70 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
71
876
f040f0fb3795 - renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
72 bool LinePathMode::keyReleased (QKeyEvent* ev)
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
73 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
74 if (Super::keyReleased (ev))
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
75 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
76
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
77 if (ev->key() == Qt::Key_Enter or ev->key() == Qt::Key_Return)
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
78 {
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
79 endDraw();
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
80 return true;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
81 }
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
82
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
83 return false;
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 874
diff changeset
84 }

mercurial