Tue, 22 Sep 2015 00:59:21 +0300
LDVertexObject stuff (ultimately not worth it)
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
968 | 3 | * Copyright (C) 2013 - 2015 Teemu Piippo |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
19 | #include <QMouseEvent> |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
20 | #include "magicWandMode.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
21 | #include "../ldDocument.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
22 | #include "../mainwindow.h" |
827 | 23 | #include "../glRenderer.h" |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
25 | MagicWandMode::MagicWandMode (GLRenderer* renderer) : |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
26 | Super (renderer) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | { |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | // Get vertex<->object data |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
977
diff
changeset
|
29 | for (LDObject* obj : currentDocument()->objects()) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | // Note: this deliberately only takes vertex-objects into account. |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | // The magic wand does not process subparts. |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
33 | if (obj->hasVertices()) |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
34 | { |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
35 | LDVertexObject* vo = static_cast<LDVertexObject*> (obj); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
36 | for (int i = 0; i < vo->numVertices(); ++i) |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
37 | m_vertices[vo->vertex (i)] << vo; |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
38 | } |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
42 | EditModeType MagicWandMode::type() const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
43 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
44 | return EditModeType::MagicWand; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
45 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
46 | |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
47 | void MagicWandMode::fillBoundaries (LDVertexObject* obj, Boundaries& boundaries, Candidates& candidates) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | { |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | // All boundaries obviously share vertices with the object, therefore they're all in the list |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | // of candidates. |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
51 | for (LDVertexObject* candidate : candidates) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | { |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
53 | if (not isOneOf (candidate->type(), OBJ_Line, OBJ_CondLine) or candidate->vertex (0) == candidate->vertex (1)) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | continue; |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | int matches = 0; |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | for (int i = 0; i < obj->numVertices(); ++i) |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | { |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
60 | if (not isOneOf (obj->vertex (i), candidate->vertex (0), candidate->vertex (1))) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | continue; |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | if (++matches == 2) |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | { |
833
ad681d97d341
- magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
65 | // Boundary found. If it's an edgeline, add it to the boundaries list, if a |
ad681d97d341
- magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
66 | // conditional line, select it. |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
67 | if (candidate->type() == OBJ_CondLine) |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
68 | m_selection << candidate; |
833
ad681d97d341
- magic wand: when flood-selecting surfaces, also pick any matching conditional lines
Santeri Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
69 | else |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
70 | boundaries.append (std::make_tuple (candidate->vertex (0), candidate->vertex (1))); |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | break; |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
77 | void MagicWandMode::doMagic (LDObject* input, MagicType type) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | { |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
79 | if (input == nullptr or not input->hasVertices()) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | { |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | if (type == Set) |
819
e3d59b6bf053
- update the object list when the magic wand empties the selection when clicking on background
Santeri Piippo <crimsondusk64@gmail.com>
parents:
818
diff
changeset
|
82 | { |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
977
diff
changeset
|
83 | currentDocument()->clearSelection(); |
981
5d5d84ab2c48
Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
84 | m_window->buildObjectList(); |
819
e3d59b6bf053
- update the object list when the magic wand empties the selection when clicking on background
Santeri Piippo <crimsondusk64@gmail.com>
parents:
818
diff
changeset
|
85 | } |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | return; |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
90 | LDVertexObject* obj = static_cast<LDVertexObject*> (input); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
91 | int matchesneeded = (obj->numVertices() == 2) ? 1 : 2; |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
92 | Boundaries boundaries; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | LDObjectType objtype = obj->type(); |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | if (type != InternalRecursion) |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | { |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
97 | m_selection.clear(); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
98 | m_selection.append (obj); |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
101 | Candidates candidates; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // Get the list of objects that touch this object, i.e. share a vertex |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | // with this. |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | for (int i = 0; i < obj->numVertices(); ++i) |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
106 | candidates += m_vertices[obj->vertex (i)]; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
108 | removeDuplicates (candidates); |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | // If we're dealing with surfaces, get a list of boundaries. |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | if (matchesneeded > 1) |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | fillBoundaries (obj, boundaries, candidates); |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
114 | for (LDVertexObject* candidate : candidates) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | { |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
116 | // If we're doing this on lines, we need exact type match. Surface types (quads and |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
117 | // triangles) can be mixed. Also don't consider self a candidate, and don't consider |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
118 | // objects we have already processed. |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
119 | if ((candidate == obj) or |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
120 | (candidate->color() != obj->color()) or |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
121 | (m_selection.contains (candidate)) or |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
122 | (matchesneeded == 1 and (candidate->type() != objtype)) or |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
123 | ((candidate->numVertices() > 2) ^ (matchesneeded == 2))) |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | { |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | continue; |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | } |
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
127 | |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
128 | // Now ensure the two objects share enough vertices. |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
129 | QSet<Vertex> matches = obj->vertexSet(); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
130 | matches.intersect (candidate->vertexSet()); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
131 | |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
132 | if (matches.size() < matchesneeded) |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
133 | goto skipthis; // Not enough matches. |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
134 | |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
135 | // Check if a boundary gets in between the objects. |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
136 | for (const Boundary& boundary : boundaries) |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
137 | { |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
138 | if (matches.contains (std::get<0>(boundary)) and matches.contains (std::get<1>(boundary))) |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
139 | goto skipthis; |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
140 | } |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
141 | |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
142 | m_selection.append (candidate); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
143 | doMagic (candidate, InternalRecursion); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
144 | skipthis: |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
145 | continue; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | switch (type) |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | { |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
150 | case Set: |
978
4603d8fd063e
Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents:
977
diff
changeset
|
151 | currentDocument()->clearSelection(); |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
152 | case Additive: |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
153 | for (LDObject* obj : m_selection) |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
154 | obj->select(); |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
155 | break; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
157 | case Subtractive: |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
158 | for (LDObject* obj : m_selection) |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
159 | obj->deselect(); |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
160 | break; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
162 | case InternalRecursion: |
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
163 | break; |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | } |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | |
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | if (type != InternalRecursion) |
981
5d5d84ab2c48
Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
167 | m_window->buildObjectList(); |
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
169 | |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
170 | bool MagicWandMode::mouseReleased (MouseEventData const& data) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
171 | { |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
172 | if (Super::mouseReleased (data)) |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
173 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
174 | |
840
d077dd19bf9a
- changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
833
diff
changeset
|
175 | if (data.releasedButtons & Qt::LeftButton and not data.mouseMoved) |
827 | 176 | { |
177 | MagicType wandtype = MagicWandMode::Set; | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
178 | |
827 | 179 | if (data.keymods & Qt::ShiftModifier) |
180 | wandtype = MagicWandMode::Additive; | |
967 | 181 | else if (data.keymods & Qt::ControlModifier) |
827 | 182 | wandtype = MagicWandMode::Subtractive; |
183 | ||
996
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
184 | LDObject* obj = renderer()->pickOneObject (data.ev->x(), data.ev->y()); |
9ecc878c7dea
LDVertexObject stuff (ultimately not worth it)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
185 | doMagic (obj, wandtype); |
827 | 186 | return true; |
187 | } | |
188 | ||
189 | return false; | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
819
diff
changeset
|
190 | } |