From 8a204bcf51e8142b9155968cab2d0cbdb99b5c97 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 22 Jun 2023 08:39:41 -0600 Subject: [PATCH] lollis: draw stems in fill color (optionally) --- libs/canvas/canvas/lollipop.h | 1 + libs/canvas/lollipop.cc | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libs/canvas/canvas/lollipop.h b/libs/canvas/canvas/lollipop.h index 4b6545924f..1447ea309e 100644 --- a/libs/canvas/canvas/lollipop.h +++ b/libs/canvas/canvas/lollipop.h @@ -61,6 +61,7 @@ public: Coord _radius; Coord _length; Item* bounding_parent; + bool line_color_is_fill; }; } diff --git a/libs/canvas/lollipop.cc b/libs/canvas/lollipop.cc index c2335e62f8..9aa3e7bd75 100644 --- a/libs/canvas/lollipop.cc +++ b/libs/canvas/lollipop.cc @@ -34,6 +34,7 @@ Lollipop::Lollipop (Canvas* c) , _radius (8) , _length (0) , bounding_parent (0) + , line_color_is_fill (true) { } @@ -42,6 +43,7 @@ Lollipop::Lollipop (Item* parent) , _radius (8) , _length (0) , bounding_parent (0) + , line_color_is_fill (true) { } @@ -62,8 +64,6 @@ Lollipop::compute_bounding_box () const void Lollipop::render (Rect const & area, Cairo::RefPtr context) const { - setup_outline_context (context); - Duple p = _parent->item_to_window (Duple (_center.x, _center.y)); Duple l (p); @@ -72,11 +72,14 @@ Lollipop::render (Rect const & area, Cairo::RefPtr context) cons l = l.translate (half_a_pixel); } - /* the line */ + setup_outline_context (context); - context->move_to (l.x, l.y + _radius); - context->line_to (l.x, l.y + _length); - context->stroke (); + if (!line_color_is_fill) { + /* draw line in outline color */ + context->move_to (l.x, l.y + _radius); + context->line_to (l.x, l.y + _length); + context->stroke (); + } /* the circle: clip to avoid weirdness at top and bottom of parent */ @@ -89,6 +92,7 @@ Lollipop::render (Rect const & area, Cairo::RefPtr context) cons context->arc (p.x, p.y, _radius, 0.0 * (M_PI/180.0), 360.0 * (M_PI/180.0)); + if (fill()) { setup_fill_context (context); if (outline()) { @@ -103,6 +107,14 @@ Lollipop::render (Rect const & area, Cairo::RefPtr context) cons context->stroke (); } + if (line_color_is_fill) { + setup_fill_context (context); + /* draw line in fill color */ + context->move_to (l.x, l.y + _radius); + context->line_to (l.x, l.y + _length); + context->stroke (); + } + if (bounding_parent) { context->restore (); } @@ -172,3 +184,4 @@ Lollipop::covers (Duple const & point) const return false; } +