Factor out Style::Stroke.

This commit is contained in:
EvilSpirit 2016-06-30 21:54:35 +06:00 committed by whitequark
parent 1108a6f37d
commit df83ee4c8f
6 changed files with 37 additions and 34 deletions

View File

@ -650,10 +650,8 @@ void GraphicsWindow::Draw(Canvas *canvas) {
c.Draw(Constraint::DrawAs::DEFAULT, canvas); c.Draw(Constraint::DrawAs::DEFAULT, canvas);
} }
Canvas::Stroke strokeAnalyze = {}; Canvas::Stroke strokeAnalyze = Style::Stroke(Style::ANALYZE);
strokeAnalyze.layer = Canvas::Layer::FRONT; strokeAnalyze.layer = Canvas::Layer::FRONT;
strokeAnalyze.color = Style::Color(Style::ANALYZE);
strokeAnalyze.width = Style::Width(Style::ANALYZE);
Canvas::hStroke hcsAnalyze = canvas->GetStroke(strokeAnalyze); Canvas::hStroke hcsAnalyze = canvas->GetStroke(strokeAnalyze);
// Draw the traced path, if one exists // Draw the traced path, if one exists
@ -662,9 +660,8 @@ void GraphicsWindow::Draw(Canvas *canvas) {
canvas->DrawEdges(tracedEdges, hcsAnalyze); canvas->DrawEdges(tracedEdges, hcsAnalyze);
tracedEdges.Clear(); tracedEdges.Clear();
Canvas::Stroke strokeError = {}; Canvas::Stroke strokeError = Style::Stroke(Style::DRAW_ERROR);
strokeError.layer = Canvas::Layer::FRONT; strokeError.layer = Canvas::Layer::FRONT;
strokeError.color = Style::Color(Style::DRAW_ERROR);
strokeError.width = 12; strokeError.width = 12;
Canvas::hStroke hcsError = canvas->GetStroke(strokeError); Canvas::hStroke hcsError = canvas->GetStroke(strokeError);
@ -681,9 +678,8 @@ void GraphicsWindow::Draw(Canvas *canvas) {
} }
SK.GetGroup(activeGroup)->DrawMesh(Group::DrawMeshAs::SELECTED, canvas); SK.GetGroup(activeGroup)->DrawMesh(Group::DrawMeshAs::SELECTED, canvas);
Canvas::Stroke strokeDatum = {}; Canvas::Stroke strokeDatum = Style::Stroke(Style::DATUM);
strokeDatum.layer = Canvas::Layer::FRONT; strokeDatum.layer = Canvas::Layer::FRONT;
strokeDatum.color = Style::Color(Style::DATUM);
strokeDatum.width = 1; strokeDatum.width = 1;
Canvas::hStroke hcsDatum = canvas->GetStroke(strokeDatum); Canvas::hStroke hcsDatum = canvas->GetStroke(strokeDatum);

View File

@ -509,11 +509,9 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
case DrawAs::HOVERED: color = Style::Color(Style::HOVERED); break; case DrawAs::HOVERED: color = Style::Color(Style::HOVERED); break;
case DrawAs::SELECTED: color = Style::Color(Style::SELECTED); break; case DrawAs::SELECTED: color = Style::Color(Style::SELECTED); break;
} }
Canvas::Stroke stroke = Style::Stroke(GetStyle());
Canvas::Stroke stroke = {};
stroke.layer = Canvas::Layer::FRONT; stroke.layer = Canvas::Layer::FRONT;
stroke.color = color; stroke.color = color;
stroke.width = Style::Width(GetStyle());
stroke.zIndex = 4; stroke.zIndex = 4;
Canvas::hStroke hcs = canvas->GetStroke(stroke); Canvas::hStroke hcs = canvas->GetStroke(stroke);

View File

@ -464,13 +464,9 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
} }
Canvas::Stroke stroke = {}; Canvas::Stroke stroke = {};
stroke.zIndex = zIndex;
stroke.color = Style::Color(hs);
stroke.width = Style::Width(hs);
stroke.stipplePattern = Style::PatternType(hs);
stroke.stippleScale = Style::StippleScaleMm(hs);
switch(how) { switch(how) {
case DrawAs::DEFAULT: case DrawAs::DEFAULT:
stroke = Style::Stroke(hs);
stroke.layer = Canvas::Layer::NORMAL; stroke.layer = Canvas::Layer::NORMAL;
break; break;
@ -479,21 +475,23 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
break; break;
case DrawAs::HIDDEN: case DrawAs::HIDDEN:
stroke = Style::Stroke(Style::HIDDEN_EDGE);
stroke.layer = Canvas::Layer::OCCLUDED; stroke.layer = Canvas::Layer::OCCLUDED;
stroke.stipplePattern = Style::PatternType({ Style::HIDDEN_EDGE });
stroke.stippleScale = Style::StippleScaleMm({ Style::HIDDEN_EDGE });
break; break;
case DrawAs::HOVERED: case DrawAs::HOVERED:
stroke = Style::Stroke(hs);
stroke.layer = Canvas::Layer::FRONT; stroke.layer = Canvas::Layer::FRONT;
stroke.color = Style::Color(Style::HOVERED); stroke.color = Style::Color(Style::HOVERED);
break; break;
case DrawAs::SELECTED: case DrawAs::SELECTED:
stroke = Style::Stroke(hs);
stroke.layer = Canvas::Layer::FRONT; stroke.layer = Canvas::Layer::FRONT;
stroke.color = Style::Color(Style::SELECTED); stroke.color = Style::Color(Style::SELECTED);
break; break;
} }
stroke.zIndex = zIndex;
Canvas::hStroke hcs = canvas->GetStroke(stroke); Canvas::hStroke hcs = canvas->GetStroke(stroke);
Canvas::Stroke pointStroke = {}; Canvas::Stroke pointStroke = {};
@ -529,8 +527,7 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
free = pu->free || pv->free; free = pu->free || pv->free;
} }
if(free) { if(free) {
Canvas::Stroke analyzeStroke = pointStroke; Canvas::Stroke analyzeStroke = Style::Stroke(Style::ANALYZE);
analyzeStroke.color = Style::Color(Style::ANALYZE);
analyzeStroke.width = 14.0; analyzeStroke.width = 14.0;
Canvas::hStroke hcsAnalyze = canvas->GetStroke(analyzeStroke); Canvas::hStroke hcsAnalyze = canvas->GetStroke(analyzeStroke);

View File

@ -529,10 +529,8 @@ void Group::Draw(Canvas *canvas) {
DrawMesh(DrawMeshAs::DEFAULT, canvas); DrawMesh(DrawMeshAs::DEFAULT, canvas);
if(SS.GW.showEdges) { if(SS.GW.showEdges) {
Canvas::Stroke strokeEdge = {}; Canvas::Stroke strokeEdge = Style::Stroke(Style::SOLID_EDGE);
strokeEdge.zIndex = 1; strokeEdge.zIndex = 1;
strokeEdge.color = Style::Color(Style::SOLID_EDGE);
strokeEdge.width = Style::Width(Style::SOLID_EDGE);
Canvas::hStroke hcsEdge = canvas->GetStroke(strokeEdge); Canvas::hStroke hcsEdge = canvas->GetStroke(strokeEdge);
canvas->DrawOutlines(displayOutlines, hcsEdge, canvas->DrawOutlines(displayOutlines, hcsEdge,
@ -541,11 +539,8 @@ void Group::Draw(Canvas *canvas) {
: Canvas::DrawOutlinesAs::EMPHASIZED_AND_CONTOUR); : Canvas::DrawOutlinesAs::EMPHASIZED_AND_CONTOUR);
if(SS.GW.drawOccludedAs == GraphicsWindow::DrawOccludedAs::STIPPLED) { if(SS.GW.drawOccludedAs == GraphicsWindow::DrawOccludedAs::STIPPLED) {
Canvas::Stroke strokeHidden = strokeEdge; Canvas::Stroke strokeHidden = Style::Stroke(Style::HIDDEN_EDGE);
strokeHidden.layer = Canvas::Layer::OCCLUDED; strokeHidden.layer = Canvas::Layer::OCCLUDED;
strokeHidden.width = Style::Width(Style::HIDDEN_EDGE);
strokeHidden.stipplePattern = Style::PatternType({ Style::HIDDEN_EDGE });
strokeHidden.stippleScale = Style::StippleScaleMm({ Style::HIDDEN_EDGE });
Canvas::hStroke hcsHidden = canvas->GetStroke(strokeHidden); Canvas::hStroke hcsHidden = canvas->GetStroke(strokeHidden);
canvas->DrawOutlines(displayOutlines, hcsHidden, canvas->DrawOutlines(displayOutlines, hcsHidden,
@ -568,14 +563,13 @@ void Group::Draw(Canvas *canvas) {
void Group::DrawPolyError(Canvas *canvas) { void Group::DrawPolyError(Canvas *canvas) {
const Camera &camera = canvas->GetCamera(); const Camera &camera = canvas->GetCamera();
Canvas::Stroke strokeUnclosed = {}; Canvas::Stroke strokeUnclosed = Style::Stroke(Style::DRAW_ERROR);
strokeUnclosed.color = Style::Color(Style::DRAW_ERROR).WithAlpha(50); strokeUnclosed.color = strokeUnclosed.color.WithAlpha(50);
strokeUnclosed.width = Style::Width(Style::DRAW_ERROR);
Canvas::hStroke hcsUnclosed = canvas->GetStroke(strokeUnclosed); Canvas::hStroke hcsUnclosed = canvas->GetStroke(strokeUnclosed);
Canvas::Stroke strokeError = {}; Canvas::Stroke strokeError = Style::Stroke(Style::DRAW_ERROR);
strokeError.layer = Canvas::Layer::FRONT; strokeError.layer = Canvas::Layer::FRONT;
strokeError.color = Style::Color(Style::DRAW_ERROR); strokeError.width = 0.0f;
Canvas::hStroke hcsError = canvas->GetStroke(strokeError); Canvas::hStroke hcsError = canvas->GetStroke(strokeError);
double textHeight = Style::DefaultTextHeight() / camera.scale; double textHeight = Style::DefaultTextHeight() / camera.scale;

View File

@ -813,13 +813,15 @@ public:
static Style *Get(hStyle hs); static Style *Get(hStyle hs);
static RgbaColor Color(hStyle hs, bool forExport=false); static RgbaColor Color(hStyle hs, bool forExport=false);
static RgbaColor Color(int hs, bool forExport=false);
static RgbaColor FillColor(hStyle hs, bool forExport=false); static RgbaColor FillColor(hStyle hs, bool forExport=false);
static double Width(hStyle hs); static double Width(hStyle hs);
static RgbaColor Color(int hs, bool forExport=false);
static double Width(int hs); static double Width(int hs);
static double WidthMm(int hs); static double WidthMm(int hs);
static double TextHeight(hStyle hs); static double TextHeight(hStyle hs);
static double DefaultTextHeight(); static double DefaultTextHeight();
static Canvas::Stroke Stroke(hStyle hs);
static Canvas::Stroke Stroke(int hs);
static bool Exportable(int hs); static bool Exportable(int hs);
static hStyle ForEntity(hEntity he); static hStyle ForEntity(hEntity he);
static StipplePattern PatternType(hStyle hs); static StipplePattern PatternType(hStyle hs);

View File

@ -281,6 +281,23 @@ double Style::DefaultTextHeight() {
return TextHeight(hs); return TextHeight(hs);
} }
//-----------------------------------------------------------------------------
// Return the parameters of this style, as a canvas stroke.
//-----------------------------------------------------------------------------
Canvas::Stroke Style::Stroke(hStyle hs) {
Canvas::Stroke stroke = {};
Style *style = Style::Get(hs);
stroke.color = style->color;
stroke.stipplePattern = style->stippleType;
stroke.stippleScale = Style::StippleScaleMm(hs);
stroke.width = Style::Width(hs.v);
return stroke;
}
Canvas::Stroke Style::Stroke(int hsv) {
return Style::Stroke(hStyle{hsv});
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Should lines and curves from this style appear in the output file? Only // Should lines and curves from this style appear in the output file? Only
// if it's both shown and exportable. // if it's both shown and exportable.
@ -892,4 +909,3 @@ void TextWindow::ShowStyleInfo() {
void TextWindow::ScreenAssignSelectionToStyle(int link, uint32_t v) { void TextWindow::ScreenAssignSelectionToStyle(int link, uint32_t v) {
Style::AssignSelectionToStyle(v); Style::AssignSelectionToStyle(v);
} }