src/ui/canvas.cpp

changeset 109
40a1cf2f38f5
parent 108
94c92c923713
child 110
d922431eacf7
--- a/src/ui/canvas.cpp	Sun Jul 25 13:49:37 2021 +0300
+++ b/src/ui/canvas.cpp	Sun Jul 25 16:26:38 2021 +0300
@@ -175,6 +175,7 @@
 		}
 		{
 			QPainter painter{this};
+			painter.setRenderHint(QPainter::Antialiasing);
 			QFont font;
 			//font.setStyle(QFont::StyleItalic);
 			painter.setFont(font);
@@ -227,35 +228,31 @@
 					renderText(axis.text, *intersection);
 				}
 			}
-			for (const PreviewLayer& previewLayer : this->previewLayers)
+			if (this->overpaintCallback != nullptr)
 			{
-				for (const PreviewLayer::Polygon& polygon3d : previewLayer.polygons)
-				{
-					painter.setBrush(polygon3d.brush);
-					painter.setPen(polygon3d.pen);
-					QVector<QPointF> points2d;
-					points2d.reserve(polygon3d.geometry.points.size());
-					for (const glm::vec3& point : polygon3d.geometry.points)
-					{
-						points2d.push_back(this->modelToScreenCoordinates(point));
-					}
-					painter.drawPolygon(QPolygonF{points2d});
-				}
-				for (const PreviewLayer::Point& point : previewLayer.points)
-				{
-					const geom::CircleF circle = {
-						this->modelToScreenCoordinates(point.location),
-						5.0,
-					};
-					painter.setBrush(point.brush);
-					painter.setPen(point.pen);
-					painter.drawEllipse(geom::inscribe(circle));
-				}
+				this->overpaintCallback(this, &painter);
 			}
 		}
 	}
 }
 
+void Canvas::drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3> &points)
+{
+	QVector<QPointF> points2d;
+	points2d.reserve(points.size());
+	for (const glm::vec3& point : points)
+	{
+		points2d.push_back(this->modelToScreenCoordinates(point));
+	}
+	painter->drawPolygon(QPolygonF{points2d});
+}
+
+void Canvas::drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const
+{
+	const QPointF center = this->modelToScreenCoordinates(worldPoint);
+	painter->drawEllipse(geom::inscribe(geom::CircleF{center, 5}));
+}
+
 void Canvas::updateGridMatrix()
 {
 	const geom::Triangle triangle {
@@ -292,16 +289,6 @@
 	return std::abs(dot) < threshold;
 }
 
-const Canvas::PreviewLayer& Canvas::getPreviewLayer(PreviewLayerName name) const
-{
-	return previewLayers[static_cast<unsigned int>(name)];
-}
-
-Canvas::PreviewLayer& Canvas::modifyPreviewLayer(PreviewLayerName name)
-{
-	return previewLayers[static_cast<unsigned int>(name)];
-}
-
 void Canvas::clearSelection()
 {
 	this->selection.clear();
@@ -317,3 +304,8 @@
 	emit selectionChanged(this->selection);
 	this->update();
 }
+
+void Canvas::setOverpaintCallback(Canvas::OverpaintCallback fn)
+{
+	this->overpaintCallback = fn;
+}

mercurial