src/tools/circletool.cpp

changeset 188
64ea7282611e
parent 187
30204975694a
--- a/src/tools/circletool.cpp	Mon May 16 01:40:49 2022 +0300
+++ b/src/tools/circletool.cpp	Tue May 24 16:11:10 2022 +0300
@@ -1,4 +1,5 @@
 #include "circletool.h"
+#include "document.h"
 
 CircleTool::CircleTool(Document *document) :
 	AbstractDrawTool{document}
@@ -36,7 +37,7 @@
 		painter->setPen(QPen{Qt::green, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin});
 		canvas->drawWorldPolyline(painter, {this->previewPolygon[0], this->previewPolygon[1]});
 		const float size = glm::distance(this->previewPolygon[1], this->previewPolygon[0]);
-		glm::mat4 matrix = size * canvas->getGridMatrix();
+		glm::mat4 matrix = size * this->baseGridMatrix;
 		matrix[3] = {this->previewPolygon[0], 1};
 		std::vector<glm::vec3> points = circle(16);
 		for (std::size_t i = 0; i < points.size(); ++i) {
@@ -45,6 +46,10 @@
 		painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin});
 		canvas->drawWorldPolyline(painter, points);
 	}
+	if (this->previewPolygon.size() >= 3)
+	{
+
+	}
 }
 
 QString CircleTool::iconName() const
@@ -52,7 +57,23 @@
 	return ":/icons/linetype-circularprimitive.png";
 }
 
+void CircleTool::addPoint(const glm::vec3 &pos)
+{
+	AbstractDrawTool::addPoint(pos);
+	if (this->polygon.size() >= 2)
+	{
+		const glm::mat4& grid = this->document->currentGrid();
+		const glm::mat4 newGrid = {grid[1], grid[2], grid[0], {this->polygon[0], 1}};
+		Q_EMIT this->desiredGridChange(newGrid);
+	}
+}
+
 void CircleTool::closeShape()
 {
 	
 }
+
+void CircleTool::reset()
+{
+	this->baseGridMatrix = this->document->currentGrid();
+}

mercurial