From a6c1a3d9d0af4aefa73178272c470fd35b57b68d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 21 Jun 2023 16:18:14 -0600 Subject: [PATCH] lollis: potentially clip circle with a bounding parent --- libs/canvas/canvas/lollipop.h | 3 +++ libs/canvas/lollipop.cc | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libs/canvas/canvas/lollipop.h b/libs/canvas/canvas/lollipop.h index 714fb89404..4b6545924f 100644 --- a/libs/canvas/canvas/lollipop.h +++ b/libs/canvas/canvas/lollipop.h @@ -54,10 +54,13 @@ public: Coord y0 () const { return _center.y; } Coord y1 () const { return _center.y + _length; } + void set_bounding_parent (Item*); + private: Duple _center; Coord _radius; Coord _length; + Item* bounding_parent; }; } diff --git a/libs/canvas/lollipop.cc b/libs/canvas/lollipop.cc index 140a3455fa..c2335e62f8 100644 --- a/libs/canvas/lollipop.cc +++ b/libs/canvas/lollipop.cc @@ -33,6 +33,7 @@ Lollipop::Lollipop (Canvas* c) : Item (c) , _radius (8) , _length (0) + , bounding_parent (0) { } @@ -40,9 +41,16 @@ Lollipop::Lollipop (Item* parent) : Item (parent) , _radius (8) , _length (0) + , bounding_parent (0) { } +void +Lollipop::set_bounding_parent (Item* bp) +{ + bounding_parent = bp; +} + void Lollipop::compute_bounding_box () const { @@ -67,10 +75,17 @@ Lollipop::render (Rect const & area, Cairo::RefPtr context) cons /* the line */ context->move_to (l.x, l.y + _radius); - context->line_to (l.x, l.y + _length - _radius); + context->line_to (l.x, l.y + _length); context->stroke (); - /* the circle */ + /* the circle: clip to avoid weirdness at top and bottom of parent */ + + if (bounding_parent) { + context->save (); + Rect b (bounding_parent->item_to_window (bounding_parent->bounding_box())); + context->rectangle (b.x0, b.y0, b.width(), b.height()); + context->clip(); + } context->arc (p.x, p.y, _radius, 0.0 * (M_PI/180.0), 360.0 * (M_PI/180.0)); @@ -88,6 +103,10 @@ Lollipop::render (Rect const & area, Cairo::RefPtr context) cons context->stroke (); } + if (bounding_parent) { + context->restore (); + } + render_children (area, context); }