src/tools/drawtool.cpp

changeset 106
128efb9d148b
parent 104
cd4df75924b7
child 108
94c92c923713
--- a/src/tools/drawtool.cpp	Mon Jul 19 23:41:52 2021 +0300
+++ b/src/tools/drawtool.cpp	Tue Jul 20 01:22:01 2021 +0300
@@ -18,7 +18,30 @@
 
 bool DrawTool::mouseClick(const Canvas::MouseClickInfo& info)
 {
-	static_cast<void>(info);
-	QMessageBox::information(nullptr, "hleelo", "it works");
+	if (info.worldPosition.has_value())
+	{
+		const glm::vec3& pos = info.worldPosition.value();
+		const auto isCloseToPos = [&](const glm::vec3& x){return geom::isclose(x, pos);};
+		if (any(this->polygon, isCloseToPos))
+		{
+			QMessageBox::information(nullptr, "test", "close the polygon");
+		}
+		else
+		{
+			this->polygon.push_back(pos);
+			auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview).polygons;
+			previewLayer.clear();
+			previewLayer.push_back({this->polygon});
+			if (this->polygon.size() == 4)
+			{
+				QMessageBox::information(nullptr, "test", "close the polygon");
+			}
+		}
+	}
 	return true;
 }
+
+void DrawTool::reset()
+{
+	this->polygon.clear();
+}

mercurial