src/tools/drawtool.cpp

changeset 168
24590af32ad6
parent 164
8305e2f968fb
child 185
a38a0eb007b0
equal deleted inserted replaced
167:c1ff4f107569 168:24590af32ad6
6 #include "drawtool.h" 6 #include "drawtool.h"
7 #include "modeleditor.h" 7 #include "modeleditor.h"
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 badPolygonPen = {QBrush{Qt::red}, 2.0, Qt::DashLine};
11 static const QPen pointPen = {QBrush{Qt::black}, 2.0}; 12 static const QPen pointPen = {QBrush{Qt::black}, 2.0};
12 static const QBrush polygonBrush = {QColor{64, 255, 128, 192}}; 13 static const QBrush greenPolygonBrush = {QColor{64, 255, 128, 192}};
13 static const QBrush badPolygonBrush = {QColor{255, 96, 96, 192}}; 14 static const QBrush redPolygonBrush = {QColor{255, 96, 96, 192}};
14 15
15 DrawTool::DrawTool(Document* document) : 16 DrawTool::DrawTool(Document* document) :
16 BaseTool{document} 17 BaseTool{document}
17 { 18 {
18 } 19 }
112 this->polygon.clear(); 113 this->polygon.clear();
113 } 114 }
114 115
115 void DrawTool::overpaint(Canvas* canvas, QPainter* painter) const 116 void DrawTool::overpaint(Canvas* canvas, QPainter* painter) const
116 { 117 {
117 painter->setBrush(this->isconcave ? ::badPolygonBrush : ::polygonBrush); 118 painter->setPen(this->isconcave ? ::badPolygonPen : ::polygonPen);
118 painter->setPen(::polygonPen); 119 if (this->previewPolygon.size() > 2 and not this->isconcave)
119 if (this->previewPolygon.size() > 2)
120 { 120 {
121 if (canvas->worldPolygonWinding(this->previewPolygon) == Winding::Clockwise)
122 {
123 painter->setBrush(::greenPolygonBrush);
124 }
125 else
126 {
127 painter->setBrush(::redPolygonBrush);
128 }
121 canvas->drawWorldPolygon(painter, this->previewPolygon); 129 canvas->drawWorldPolygon(painter, this->previewPolygon);
122 } 130 }
123 else 131 else
124 { 132 {
125 canvas->drawWorldPolyline(painter, this->previewPolygon); 133 canvas->drawWorldPolyline(painter, this->previewPolygon);

mercurial