| 154 } |
154 } |
| 155 } |
155 } |
| 156 return result; |
156 return result; |
| 157 } |
157 } |
| 158 |
158 |
| |
159 namespace { |
| |
160 struct Pens |
| |
161 { |
| |
162 const QBrush pointBrush; |
| |
163 const QPen pointPen; |
| |
164 const QPen polygonPen; |
| |
165 const QPen badPolygonPen; |
| |
166 const QBrush greenPolygonBrush; |
| |
167 const QBrush redPolygonBrush; |
| |
168 }; |
| |
169 } |
| |
170 |
| |
171 static const Pens brightPens{ |
| |
172 .pointBrush = {Qt::white}, |
| |
173 .pointPen = {QBrush{Qt::black}, 2.0}, |
| |
174 .polygonPen = {QBrush{Qt::black}, 2.0, Qt::DashLine}, |
| |
175 .greenPolygonBrush = {QColor{64, 255, 128, 192}}, |
| |
176 .redPolygonBrush = {QColor{255, 96, 96, 192}}, |
| |
177 }; |
| |
178 |
| |
179 static const Pens darkPens{ |
| |
180 .pointBrush = {Qt::black}, |
| |
181 .pointPen = {QBrush{Qt::white}, 2.0}, |
| |
182 .polygonPen = {QBrush{Qt::white}, 2.0, Qt::DashLine}, |
| |
183 .greenPolygonBrush = {QColor{64, 255, 128, 192}}, |
| |
184 .redPolygonBrush = {QColor{255, 96, 96, 192}}, |
| |
185 }; |
| |
186 |
| 159 void EditTools::overpaint(QPainter* painter) |
187 void EditTools::overpaint(QPainter* painter) |
| 160 { |
188 { |
| 161 struct Pens |
|
| 162 { |
|
| 163 const QBrush pointBrush; |
|
| 164 const QPen pointPen; |
|
| 165 const QPen polygonPen; |
|
| 166 const QPen badPolygonPen; |
|
| 167 const QBrush greenPolygonBrush; |
|
| 168 const QBrush redPolygonBrush; |
|
| 169 }; |
|
| 170 static const Pens brightPens{ |
|
| 171 .pointBrush = {Qt::white}, |
|
| 172 .pointPen = {QBrush{Qt::black}, 2.0}, |
|
| 173 .polygonPen = {QBrush{Qt::black}, 2.0, Qt::DashLine}, |
|
| 174 .greenPolygonBrush = {QColor{64, 255, 128, 192}}, |
|
| 175 .redPolygonBrush = {QColor{255, 96, 96, 192}}, |
|
| 176 }; |
|
| 177 static const Pens darkPens{ |
|
| 178 .pointBrush = {Qt::black}, |
|
| 179 .pointPen = {QBrush{Qt::white}, 2.0}, |
|
| 180 .polygonPen = {QBrush{Qt::white}, 2.0, Qt::DashLine}, |
|
| 181 .greenPolygonBrush = {QColor{64, 255, 128, 192}}, |
|
| 182 .redPolygonBrush = {QColor{255, 96, 96, 192}}, |
|
| 183 }; |
|
| 184 const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens); |
189 const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens); |
| 185 switch(this->mode) { |
190 this->renderPreview(painter, &pens); |
| 186 case SelectMode: |
|
| 187 break; |
|
| 188 case DrawMode: |
|
| 189 painter->setPen(pens.polygonPen); |
|
| 190 for (const ModelAction& action : this->actions()) { |
|
| 191 const std::vector<glm::vec3> points = modelActionPoints(action).value_or(std::vector<glm::vec3>{}); |
|
| 192 if (points.size() == 2) { |
|
| 193 drawWorldPolyline(painter, points, renderer); |
|
| 194 } |
|
| 195 else { |
|
| 196 if (worldPolygonWinding(points, this->renderer) == Winding::Clockwise) { |
|
| 197 painter->setBrush(pens.greenPolygonBrush); |
|
| 198 } |
|
| 199 else { |
|
| 200 painter->setBrush(pens.redPolygonBrush); |
|
| 201 } |
|
| 202 drawWorldPolygon(painter, points, this->renderer); |
|
| 203 } |
|
| 204 } |
|
| 205 //drawWorldPolyline(painter, this->previewPolygon, this->renderer); |
|
| 206 painter->setBrush(pens.pointBrush); |
|
| 207 painter->setPen(pens.pointPen); |
|
| 208 for (const glm::vec3& point : this->polygon) { |
|
| 209 drawWorldPoint(painter, point, this->renderer); |
|
| 210 } |
|
| 211 break; |
|
| 212 } |
|
| 213 if (this->worldPosition.has_value()) |
191 if (this->worldPosition.has_value()) |
| 214 { |
192 { |
| 215 painter->setRenderHint(QPainter::Antialiasing); |
193 painter->setRenderHint(QPainter::Antialiasing); |
| 216 painter->setPen(Qt::white); |
194 painter->setPen(Qt::white); |
| 217 painter->setBrush(Qt::green); |
195 painter->setBrush(Qt::green); |
| 218 const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition); |
196 const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition); |
| 219 painter->drawEllipse(pos, 5, 5); |
197 painter->drawEllipse(pos, 5, 5); |
| 220 painter->drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); |
198 painter->drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); |
| |
199 } |
| |
200 } |
| |
201 |
| |
202 void EditTools::renderPreview(QPainter* painter, const void* pensptr) |
| |
203 { |
| |
204 const Pens& pens = *reinterpret_cast<const Pens*>(pensptr); |
| |
205 painter->setPen(pens.polygonPen); |
| |
206 for (const ModelAction& action : this->actions()) { |
| |
207 const std::vector<glm::vec3> points = modelActionPoints(action).value_or(std::vector<glm::vec3>{}); |
| |
208 if (points.size() == 2) { |
| |
209 drawWorldPolyline(painter, points, renderer); |
| |
210 } |
| |
211 else { |
| |
212 if (worldPolygonWinding(points, this->renderer) == Winding::Clockwise) { |
| |
213 painter->setBrush(pens.greenPolygonBrush); |
| |
214 } |
| |
215 else { |
| |
216 painter->setBrush(pens.redPolygonBrush); |
| |
217 } |
| |
218 drawWorldPolygon(painter, points, this->renderer); |
| |
219 } |
| |
220 } |
| |
221 painter->setBrush(pens.pointBrush); |
| |
222 painter->setPen(pens.pointPen); |
| |
223 for (const glm::vec3& point : this->polygon) { |
| |
224 drawWorldPoint(painter, point, this->renderer); |
| 221 } |
225 } |
| 222 } |
226 } |
| 223 |
227 |
| 224 void EditTools::removeLastPoint() |
228 void EditTools::removeLastPoint() |
| 225 { |
229 { |