src/tools/drawtool.cpp

changeset 122
b54b350dff5d
parent 121
000781318c36
child 123
e3fe3617b631
equal deleted inserted replaced
121:000781318c36 122:b54b350dff5d
8 8
9 static const QBrush pointBrush = {Qt::white}; 9 static const QBrush pointBrush = {Qt::white};
10 static const QPen polygonPen = {QBrush{Qt::black}, 2.0, Qt::DashLine}; 10 static const QPen polygonPen = {QBrush{Qt::black}, 2.0, Qt::DashLine};
11 static const QPen pointPen = {QBrush{Qt::black}, 2.0}; 11 static const QPen pointPen = {QBrush{Qt::black}, 2.0};
12 static const QBrush polygonBrush = {QColor{64, 255, 128, 192}}; 12 static const QBrush polygonBrush = {QColor{64, 255, 128, 192}};
13 static const QBrush badPolygonBrush = {QColor{255, 96, 96, 192}};
13 14
14 DrawTool::DrawTool(QObject* parent) : 15 DrawTool::DrawTool(QObject* parent) :
15 BaseTool{parent} {} 16 BaseTool{parent} {}
16 17
17 QString DrawTool::name() const 18 QString DrawTool::name() const
81 82
82 void DrawTool::updatePreviewPolygon() 83 void DrawTool::updatePreviewPolygon()
83 { 84 {
84 this->previewPolygon.resize(this->polygon.size() + 1); 85 this->previewPolygon.resize(this->polygon.size() + 1);
85 this->previewPolygon.back() = this->previewPoint; 86 this->previewPolygon.back() = this->previewPoint;
87 if (this->previewPolygon.size() > 2)
88 {
89 this->isconcave = not geom::convex(this->previewPolygon);
90 }
86 } 91 }
87 92
88 void DrawTool::reset() 93 void DrawTool::reset()
89 { 94 {
90 this->polygon.clear(); 95 this->polygon.clear();
91 } 96 }
92 97
93 void DrawTool::overpaint(Canvas* canvas, QPainter* painter) const 98 void DrawTool::overpaint(Canvas* canvas, QPainter* painter) const
94 { 99 {
95 painter->setBrush(::polygonBrush); 100 painter->setBrush(this->isconcave ? ::badPolygonBrush : ::polygonBrush);
96 painter->setPen(::polygonPen); 101 painter->setPen(::polygonPen);
97 canvas->drawWorldPolygon(painter, this->previewPolygon); 102 canvas->drawWorldPolygon(painter, this->previewPolygon);
98 painter->setBrush(::pointBrush); 103 painter->setBrush(::pointBrush);
99 painter->setPen(::pointPen); 104 painter->setPen(::pointPen);
100 for (const glm::vec3& point : this->polygon) 105 for (const glm::vec3& point : this->polygon)

mercurial