173 painter.setPen(Qt::white); |
173 painter.setPen(Qt::white); |
174 painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); |
174 painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); |
175 } |
175 } |
176 { |
176 { |
177 QPainter painter{this}; |
177 QPainter painter{this}; |
|
178 painter.setRenderHint(QPainter::Antialiasing); |
178 QFont font; |
179 QFont font; |
179 //font.setStyle(QFont::StyleItalic); |
180 //font.setStyle(QFont::StyleItalic); |
180 painter.setFont(font); |
181 painter.setFont(font); |
181 QFontMetrics fontMetrics{font}; |
182 QFontMetrics fontMetrics{font}; |
182 const auto renderText = [&](const QString& text, const geom::PointOnRectagle& intersection) |
183 const auto renderText = [&](const QString& text, const geom::PointOnRectagle& intersection) |
225 if (intersection.has_value()) |
226 if (intersection.has_value()) |
226 { |
227 { |
227 renderText(axis.text, *intersection); |
228 renderText(axis.text, *intersection); |
228 } |
229 } |
229 } |
230 } |
230 for (const PreviewLayer& previewLayer : this->previewLayers) |
231 if (this->overpaintCallback != nullptr) |
231 { |
232 { |
232 for (const PreviewLayer::Polygon& polygon3d : previewLayer.polygons) |
233 this->overpaintCallback(this, &painter); |
233 { |
|
234 painter.setBrush(polygon3d.brush); |
|
235 painter.setPen(polygon3d.pen); |
|
236 QVector<QPointF> points2d; |
|
237 points2d.reserve(polygon3d.geometry.points.size()); |
|
238 for (const glm::vec3& point : polygon3d.geometry.points) |
|
239 { |
|
240 points2d.push_back(this->modelToScreenCoordinates(point)); |
|
241 } |
|
242 painter.drawPolygon(QPolygonF{points2d}); |
|
243 } |
|
244 for (const PreviewLayer::Point& point : previewLayer.points) |
|
245 { |
|
246 const geom::CircleF circle = { |
|
247 this->modelToScreenCoordinates(point.location), |
|
248 5.0, |
|
249 }; |
|
250 painter.setBrush(point.brush); |
|
251 painter.setPen(point.pen); |
|
252 painter.drawEllipse(geom::inscribe(circle)); |
|
253 } |
|
254 } |
234 } |
255 } |
235 } |
256 } |
236 } |
|
237 } |
|
238 |
|
239 void Canvas::drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3> &points) |
|
240 { |
|
241 QVector<QPointF> points2d; |
|
242 points2d.reserve(points.size()); |
|
243 for (const glm::vec3& point : points) |
|
244 { |
|
245 points2d.push_back(this->modelToScreenCoordinates(point)); |
|
246 } |
|
247 painter->drawPolygon(QPolygonF{points2d}); |
|
248 } |
|
249 |
|
250 void Canvas::drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const |
|
251 { |
|
252 const QPointF center = this->modelToScreenCoordinates(worldPoint); |
|
253 painter->drawEllipse(geom::inscribe(geom::CircleF{center, 5})); |
257 } |
254 } |
258 |
255 |
259 void Canvas::updateGridMatrix() |
256 void Canvas::updateGridMatrix() |
260 { |
257 { |
261 const geom::Triangle triangle { |
258 const geom::Triangle triangle { |
290 // and the grid is perpendicular to the screen. |
287 // and the grid is perpendicular to the screen. |
291 const float dot = glm::dot(glm::normalize(this->gridPlane.normal), glm::normalize(cameraDirection)); |
288 const float dot = glm::dot(glm::normalize(this->gridPlane.normal), glm::normalize(cameraDirection)); |
292 return std::abs(dot) < threshold; |
289 return std::abs(dot) < threshold; |
293 } |
290 } |
294 |
291 |
295 const Canvas::PreviewLayer& Canvas::getPreviewLayer(PreviewLayerName name) const |
|
296 { |
|
297 return previewLayers[static_cast<unsigned int>(name)]; |
|
298 } |
|
299 |
|
300 Canvas::PreviewLayer& Canvas::modifyPreviewLayer(PreviewLayerName name) |
|
301 { |
|
302 return previewLayers[static_cast<unsigned int>(name)]; |
|
303 } |
|
304 |
|
305 void Canvas::clearSelection() |
292 void Canvas::clearSelection() |
306 { |
293 { |
307 this->selection.clear(); |
294 this->selection.clear(); |
308 this->compiler->setSelectedObjects(this->selection); |
295 this->compiler->setSelectedObjects(this->selection); |
309 emit selectionChanged(this->selection); |
296 emit selectionChanged(this->selection); |