From ad6afbe68a6ecf069adfaf3849b6bcc4d99a7d07 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 27 Jul 2021 13:13:14 -0600 Subject: [PATCH] canvas: use Item::bb_clean() to mark _bounding_box_dirty false --- libs/canvas/arc.cc | 2 +- libs/canvas/arrow.cc | 2 +- libs/canvas/box.cc | 4 ++-- libs/canvas/canvas/item.h | 8 +++++++- libs/canvas/constraint_packer.cc | 2 +- libs/canvas/grid.cc | 4 ++-- libs/canvas/image.cc | 2 +- libs/canvas/item.cc | 7 +++++++ libs/canvas/line.cc | 2 +- libs/canvas/line_set.cc | 2 +- libs/canvas/meter.cc | 4 ++-- libs/canvas/pixbuf.cc | 2 +- libs/canvas/poly_item.cc | 2 +- libs/canvas/rectangle.cc | 3 ++- libs/canvas/step_button.cc | 2 +- libs/canvas/text.cc | 4 ++-- libs/canvas/widget.cc | 2 +- libs/canvas/xfade_curve.cc | 2 +- 18 files changed, 35 insertions(+), 21 deletions(-) diff --git a/libs/canvas/arc.cc b/libs/canvas/arc.cc index 5beece7ce8..d734286531 100644 --- a/libs/canvas/arc.cc +++ b/libs/canvas/arc.cc @@ -64,7 +64,7 @@ Arc::compute_bounding_box () const bbox = bbox.expand (0.5 + (_outline_width / 2)); _bounding_box = bbox; - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/arrow.cc b/libs/canvas/arrow.cc index f95c6ecc8f..742f62a189 100644 --- a/libs/canvas/arrow.cc +++ b/libs/canvas/arrow.cc @@ -79,7 +79,7 @@ Arrow::compute_bounding_box () const _line->x1() + (head_width / 2.0) + outline_pad, _line->y1()); - _bounding_box_dirty = false; + bb_clean (); } /** Set whether to show an arrow head at one end or other diff --git a/libs/canvas/box.cc b/libs/canvas/box.cc index 5d32d34821..6f3a3b2dc0 100644 --- a/libs/canvas/box.cc +++ b/libs/canvas/box.cc @@ -77,7 +77,7 @@ Box::compute_bounding_box () const _bounding_box = Rect(); if (_items.empty()) { - _bounding_box_dirty = false; + bb_clean (); return; } @@ -96,7 +96,7 @@ Box::compute_bounding_box () const 0.0); } - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/canvas/item.h b/libs/canvas/canvas/item.h index 38c3235aa5..d3544585e1 100644 --- a/libs/canvas/canvas/item.h +++ b/libs/canvas/canvas/item.h @@ -159,7 +159,10 @@ public: virtual Duple intrinsic_size() const { return Duple (_intrinsic_width, _intrinsic_height); } virtual void set_intrinsic_size (Distance, Distance); - /** bounding box is the public API to get the size of the item. + /** bounding box is the public API to get the area covered by the item + * (which may differ from its allocation). The returned Rect is in item + * coordinates (i.e. x0,y0 = 0,0 mean that the upper left corner of the + * bounding box is at the item's _position). */ Rect bounding_box () const; @@ -326,6 +329,9 @@ public: mutable Rect _bounding_box; /** true if _bounding_box might be out of date, false if its definitely not */ mutable bool _bounding_box_dirty; + + void bb_clean () const; + Rect _allocation; bool _layout_sensitive; Distance _intrinsic_width; diff --git a/libs/canvas/constraint_packer.cc b/libs/canvas/constraint_packer.cc index d310c883e7..2e65ededfe 100644 --- a/libs/canvas/constraint_packer.cc +++ b/libs/canvas/constraint_packer.cc @@ -92,7 +92,7 @@ void ConstraintPacker::compute_bounding_box () const { _bounding_box = _allocation; - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc index 0955f76f70..b5b2b5bf08 100644 --- a/libs/canvas/grid.cc +++ b/libs/canvas/grid.cc @@ -88,7 +88,7 @@ Grid::compute_bounding_box () const _bounding_box = Rect(); if (_items.empty()) { - _bounding_box_dirty = false; + bb_clean (); return; } @@ -103,7 +103,7 @@ Grid::compute_bounding_box () const outline_width() + left_margin + left_padding); } - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/image.cc b/libs/canvas/image.cc index 4f6e3ad561..fd55c14ba3 100644 --- a/libs/canvas/image.cc +++ b/libs/canvas/image.cc @@ -69,7 +69,7 @@ void Image::compute_bounding_box () const { _bounding_box = Rect (0, 0, _width, _height); - _bounding_box_dirty = false; + bb_clean (); } boost::shared_ptr diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index 51613a58a2..b3b902e070 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -1316,3 +1316,10 @@ Item::set_layout_sensitive (bool yn) { _layout_sensitive = yn; } + +void +Item::bb_clean () const +{ + _bounding_box_dirty = false; +} + diff --git a/libs/canvas/line.cc b/libs/canvas/line.cc index 1dc3623596..832cde0809 100644 --- a/libs/canvas/line.cc +++ b/libs/canvas/line.cc @@ -52,7 +52,7 @@ Line::compute_bounding_box () const bbox = bbox.expand (0.5 + (_outline_width / 2)); _bounding_box = bbox; - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/line_set.cc b/libs/canvas/line_set.cc index 0cb60d9e7c..2efbfff5a0 100644 --- a/libs/canvas/line_set.cc +++ b/libs/canvas/line_set.cc @@ -71,7 +71,7 @@ LineSet::compute_bounding_box () const } } - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/meter.cc b/libs/canvas/meter.cc index 3f7c980e23..c6e1fe33f1 100644 --- a/libs/canvas/meter.cc +++ b/libs/canvas/meter.cc @@ -170,13 +170,13 @@ Meter::compute_bounding_box () const { if (!_canvas) { _bounding_box = Rect (); - _bounding_box_dirty = false; + bb_clean (); return; } Rect r (0, 0, pixwidth + 2, pixheight + 2); _bounding_box = r; - _bounding_box_dirty = false; + bb_clean (); } diff --git a/libs/canvas/pixbuf.cc b/libs/canvas/pixbuf.cc index 3ad66d31fa..7b1384ebb8 100644 --- a/libs/canvas/pixbuf.cc +++ b/libs/canvas/pixbuf.cc @@ -52,7 +52,7 @@ Pixbuf::compute_bounding_box () const _bounding_box = Rect (); } - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc index 539506d251..0e65f96b40 100644 --- a/libs/canvas/poly_item.cc +++ b/libs/canvas/poly_item.cc @@ -63,7 +63,7 @@ PolyItem::compute_bounding_box () const _bounding_box = Rect (); } - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/rectangle.cc b/libs/canvas/rectangle.cc index adcca99252..9d48762db3 100644 --- a/libs/canvas/rectangle.cc +++ b/libs/canvas/rectangle.cc @@ -176,10 +176,11 @@ void Rectangle::compute_bounding_box () const { if (!_rect.empty()) { + // _bounding_box = _rect.fix().expand (1.0 + _outline_width * 0.5); _bounding_box = _rect.fix().expand (_outline_width * 0.5); } - _bounding_box_dirty = false; + bb_clean (); } void diff --git a/libs/canvas/step_button.cc b/libs/canvas/step_button.cc index b1afaa6a5e..289da2b43a 100644 --- a/libs/canvas/step_button.cc +++ b/libs/canvas/step_button.cc @@ -69,7 +69,7 @@ StepButton::compute_bounding_box () const add_child_bounding_boxes (); - _bounding_box_dirty = false; + bb_clean (); } #define CORNER_RADIUS 5 diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index 5d445ec657..592f3e609f 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -239,7 +239,7 @@ Text::compute_bounding_box () const { if (!_canvas || _text.empty()) { _bounding_box = Rect (); - _bounding_box_dirty = false; + bb_clean (); return; } @@ -253,7 +253,7 @@ Text::compute_bounding_box () const _redraw (); } _bounding_box = Rect (0, 0, min (_clamped_width, (double) _image->get_width() * retina_factor), _image->get_height() * retina_factor); - _bounding_box_dirty = false; + bb_clean (); } } diff --git a/libs/canvas/widget.cc b/libs/canvas/widget.cc index 8645a05b10..08a39bdb36 100644 --- a/libs/canvas/widget.cc +++ b/libs/canvas/widget.cc @@ -143,5 +143,5 @@ Widget::compute_bounding_box () const _widget.size_allocate (alloc); - _bounding_box_dirty = false; + bb_clean (); } diff --git a/libs/canvas/xfade_curve.cc b/libs/canvas/xfade_curve.cc index 87b6709a5e..1d5eda3512 100644 --- a/libs/canvas/xfade_curve.cc +++ b/libs/canvas/xfade_curve.cc @@ -115,7 +115,7 @@ XFadeCurve::compute_bounding_box () const _bounding_box = Rect (); } - _bounding_box_dirty = false; + bb_clean (); } void