Sun, 06 Sep 2015 16:08:22 +0300
Refactor PartDownloadRequest
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" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
958
diff
changeset
|
3 | #include "../mainwindow.h" |
875
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) |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
16 | points << renderer()->convert3dTo2d (vrt); |
874
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()); |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
20 | if (points.size() == points3d.size()) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
21 | { |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
22 | for (int i = 0; i < points.size() - 1; ++i) |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
23 | { |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
24 | painter.drawLine (QLineF (points[i], points[i + 1])); |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
25 | drawLength (painter, points3d[i], points3d[i + 1], points[i], points[i + 1]); |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
26 | } |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
27 | |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
28 | for (QPointF const& point : points) |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
945
diff
changeset
|
29 | renderer()->drawBlip (painter, point); |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
30 | } |
874
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | } |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
876
f040f0fb3795
- renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents:
875
diff
changeset
|
33 | 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
|
34 | { |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | if (Super::mouseReleased (data)) |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | return true; |
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 | if (data.releasedButtons & Qt::LeftButton) |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | addDrawnVertex (renderer()->position3D()); |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | return true; |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | } |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | return false; |
ba75c789667e
- added line loop mode (doesn't actually create anything yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | } |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
46 | |
876
f040f0fb3795
- renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents:
875
diff
changeset
|
47 | bool LinePathMode::preAddVertex (Vertex const& pos) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
48 | { |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
49 | // If we picked an the last vertex, stop drawing |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
50 | if (not m_drawedVerts.isEmpty() and pos == m_drawedVerts.last()) |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
51 | { |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
52 | endDraw(); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
53 | return true; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
54 | } |
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 | return false; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
57 | } |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
58 | |
876
f040f0fb3795
- renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents:
875
diff
changeset
|
59 | void LinePathMode::endDraw() |
875
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 | LDObjectList objs; |
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 | for (int i = 0; i < m_drawedVerts.size() - 1; ++i) |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
64 | { |
945
c310073e4f22
More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents:
876
diff
changeset
|
65 | LDLine* line = LDSpawn<LDLine>(); |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
66 | line->setVertex (0, m_drawedVerts[i]); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
67 | line->setVertex (1, m_drawedVerts[i + 1]); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
68 | objs << line; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
69 | } |
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 | finishDraw (objs); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
72 | } |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
73 | |
876
f040f0fb3795
- renamed line loop to line path, updated changelog
Teemu Piippo <crimsondusk64@gmail.com>
parents:
875
diff
changeset
|
74 | bool LinePathMode::keyReleased (QKeyEvent* ev) |
875
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
75 | { |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
76 | if (Super::keyReleased (ev)) |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
77 | return true; |
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 | 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
|
80 | { |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
81 | endDraw(); |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
82 | return true; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
83 | } |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
84 | |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
85 | return false; |
ce8e9b37d44f
- finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
874
diff
changeset
|
86 | } |