27 QMessageBox::information(nullptr, "test", "close the polygon"); |
31 QMessageBox::information(nullptr, "test", "close the polygon"); |
28 } |
32 } |
29 else |
33 else |
30 { |
34 { |
31 this->polygon.push_back(pos); |
35 this->polygon.push_back(pos); |
32 auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview).polygons; |
36 auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview); |
33 previewLayer.clear(); |
37 previewLayer.points.resize(this->polygon.size()); |
34 previewLayer.push_back({this->polygon}); |
38 previewLayer.points.back() = {pos, brush, pen}; |
|
39 previewLayer.polygons.clear(); |
|
40 previewLayer.polygons.push_back({geom::NPolygon{this->polygon}, polygonBrush, pen}); |
35 if (this->polygon.size() == 4) |
41 if (this->polygon.size() == 4) |
36 { |
42 { |
37 QMessageBox::information(nullptr, "test", "close the polygon"); |
43 QMessageBox::information(nullptr, "test", "close the polygon"); |
38 } |
44 } |
39 } |
45 } |
40 } |
46 } |
41 return true; |
47 return true; |
42 } |
48 } |
43 |
49 |
|
50 bool DrawTool::mouseMove(const Canvas::MouseMoveInfo& info) |
|
51 { |
|
52 if (this->polygon.size() < 4 and info.worldPosition.has_value()) |
|
53 { |
|
54 auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview); |
|
55 previewLayer.points.resize(this->polygon.size() + 1); |
|
56 previewLayer.points.back() = {info.worldPosition.value(), brush, pen}; |
|
57 if (previewLayer.polygons.size() > 0) |
|
58 { |
|
59 auto& polygon = previewLayer.polygons.back(); |
|
60 polygon.geometry.points.resize(this->polygon.size() + 1); |
|
61 polygon.geometry.points.back() = info.worldPosition.value(); |
|
62 } |
|
63 return true; |
|
64 } |
|
65 else |
|
66 { |
|
67 return false; |
|
68 } |
|
69 } |
|
70 |
44 void DrawTool::reset() |
71 void DrawTool::reset() |
45 { |
72 { |
46 this->polygon.clear(); |
73 this->polygon.clear(); |
47 } |
74 } |