diff --git a/src/draw.cpp b/src/draw.cpp index a772987..0256f45 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -650,10 +650,8 @@ void GraphicsWindow::Draw(Canvas *canvas) { c.Draw(Constraint::DrawAs::DEFAULT, canvas); } - Canvas::Stroke strokeAnalyze = {}; + Canvas::Stroke strokeAnalyze = Style::Stroke(Style::ANALYZE); strokeAnalyze.layer = Canvas::Layer::FRONT; - strokeAnalyze.color = Style::Color(Style::ANALYZE); - strokeAnalyze.width = Style::Width(Style::ANALYZE); Canvas::hStroke hcsAnalyze = canvas->GetStroke(strokeAnalyze); // Draw the traced path, if one exists @@ -662,9 +660,8 @@ void GraphicsWindow::Draw(Canvas *canvas) { canvas->DrawEdges(tracedEdges, hcsAnalyze); tracedEdges.Clear(); - Canvas::Stroke strokeError = {}; + Canvas::Stroke strokeError = Style::Stroke(Style::DRAW_ERROR); strokeError.layer = Canvas::Layer::FRONT; - strokeError.color = Style::Color(Style::DRAW_ERROR); strokeError.width = 12; Canvas::hStroke hcsError = canvas->GetStroke(strokeError); @@ -681,9 +678,8 @@ void GraphicsWindow::Draw(Canvas *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.color = Style::Color(Style::DATUM); strokeDatum.width = 1; Canvas::hStroke hcsDatum = canvas->GetStroke(strokeDatum); diff --git a/src/drawconstraint.cpp b/src/drawconstraint.cpp index b744805..8828802 100644 --- a/src/drawconstraint.cpp +++ b/src/drawconstraint.cpp @@ -509,11 +509,9 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas, case DrawAs::HOVERED: color = Style::Color(Style::HOVERED); break; case DrawAs::SELECTED: color = Style::Color(Style::SELECTED); break; } - - Canvas::Stroke stroke = {}; + Canvas::Stroke stroke = Style::Stroke(GetStyle()); stroke.layer = Canvas::Layer::FRONT; stroke.color = color; - stroke.width = Style::Width(GetStyle()); stroke.zIndex = 4; Canvas::hStroke hcs = canvas->GetStroke(stroke); diff --git a/src/drawentity.cpp b/src/drawentity.cpp index 47e632c..f48682d 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -464,13 +464,9 @@ void Entity::Draw(DrawAs how, Canvas *canvas) { } 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) { case DrawAs::DEFAULT: + stroke = Style::Stroke(hs); stroke.layer = Canvas::Layer::NORMAL; break; @@ -479,21 +475,23 @@ void Entity::Draw(DrawAs how, Canvas *canvas) { break; case DrawAs::HIDDEN: + stroke = Style::Stroke(Style::HIDDEN_EDGE); stroke.layer = Canvas::Layer::OCCLUDED; - stroke.stipplePattern = Style::PatternType({ Style::HIDDEN_EDGE }); - stroke.stippleScale = Style::StippleScaleMm({ Style::HIDDEN_EDGE }); break; case DrawAs::HOVERED: + stroke = Style::Stroke(hs); stroke.layer = Canvas::Layer::FRONT; stroke.color = Style::Color(Style::HOVERED); break; case DrawAs::SELECTED: + stroke = Style::Stroke(hs); stroke.layer = Canvas::Layer::FRONT; stroke.color = Style::Color(Style::SELECTED); break; } + stroke.zIndex = zIndex; Canvas::hStroke hcs = canvas->GetStroke(stroke); Canvas::Stroke pointStroke = {}; @@ -529,8 +527,7 @@ void Entity::Draw(DrawAs how, Canvas *canvas) { free = pu->free || pv->free; } if(free) { - Canvas::Stroke analyzeStroke = pointStroke; - analyzeStroke.color = Style::Color(Style::ANALYZE); + Canvas::Stroke analyzeStroke = Style::Stroke(Style::ANALYZE); analyzeStroke.width = 14.0; Canvas::hStroke hcsAnalyze = canvas->GetStroke(analyzeStroke); diff --git a/src/groupmesh.cpp b/src/groupmesh.cpp index e01afa7..8880c91 100644 --- a/src/groupmesh.cpp +++ b/src/groupmesh.cpp @@ -529,10 +529,8 @@ void Group::Draw(Canvas *canvas) { DrawMesh(DrawMeshAs::DEFAULT, canvas); if(SS.GW.showEdges) { - Canvas::Stroke strokeEdge = {}; + Canvas::Stroke strokeEdge = Style::Stroke(Style::SOLID_EDGE); strokeEdge.zIndex = 1; - strokeEdge.color = Style::Color(Style::SOLID_EDGE); - strokeEdge.width = Style::Width(Style::SOLID_EDGE); Canvas::hStroke hcsEdge = canvas->GetStroke(strokeEdge); canvas->DrawOutlines(displayOutlines, hcsEdge, @@ -541,11 +539,8 @@ void Group::Draw(Canvas *canvas) { : Canvas::DrawOutlinesAs::EMPHASIZED_AND_CONTOUR); 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.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->DrawOutlines(displayOutlines, hcsHidden, @@ -568,14 +563,13 @@ void Group::Draw(Canvas *canvas) { void Group::DrawPolyError(Canvas *canvas) { const Camera &camera = canvas->GetCamera(); - Canvas::Stroke strokeUnclosed = {}; - strokeUnclosed.color = Style::Color(Style::DRAW_ERROR).WithAlpha(50); - strokeUnclosed.width = Style::Width(Style::DRAW_ERROR); + Canvas::Stroke strokeUnclosed = Style::Stroke(Style::DRAW_ERROR); + strokeUnclosed.color = strokeUnclosed.color.WithAlpha(50); Canvas::hStroke hcsUnclosed = canvas->GetStroke(strokeUnclosed); - Canvas::Stroke strokeError = {}; - strokeError.layer = Canvas::Layer::FRONT; - strokeError.color = Style::Color(Style::DRAW_ERROR); + Canvas::Stroke strokeError = Style::Stroke(Style::DRAW_ERROR); + strokeError.layer = Canvas::Layer::FRONT; + strokeError.width = 0.0f; Canvas::hStroke hcsError = canvas->GetStroke(strokeError); double textHeight = Style::DefaultTextHeight() / camera.scale; diff --git a/src/sketch.h b/src/sketch.h index 1ca5710..7af9c8f 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -813,13 +813,15 @@ public: static Style *Get(hStyle hs); 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 double Width(hStyle hs); - static RgbaColor Color(int hs, bool forExport=false); static double Width(int hs); static double WidthMm(int hs); static double TextHeight(hStyle hs); static double DefaultTextHeight(); + static Canvas::Stroke Stroke(hStyle hs); + static Canvas::Stroke Stroke(int hs); static bool Exportable(int hs); static hStyle ForEntity(hEntity he); static StipplePattern PatternType(hStyle hs); diff --git a/src/style.cpp b/src/style.cpp index 9d8ffae..c8fb33e 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -281,6 +281,23 @@ double Style::DefaultTextHeight() { 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 // if it's both shown and exportable. @@ -892,4 +909,3 @@ void TextWindow::ShowStyleInfo() { void TextWindow::ScreenAssignSelectionToStyle(int link, uint32_t v) { Style::AssignSelectionToStyle(v); } -