From c75ceb31abb1934fe72dc0efb1ee2b80966eae7f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 26 Apr 2022 21:57:39 -0600 Subject: [PATCH] canvas: when an item has its bbox marked dirty, this should propagate to all parents --- libs/canvas/arc.cc | 10 +++++----- libs/canvas/arrow.cc | 16 ++++++++-------- libs/canvas/canvas/item.h | 8 +++++--- libs/canvas/grid.cc | 4 ++-- libs/canvas/item.cc | 37 ++++++++++++++++++++++++------------- libs/canvas/line.cc | 12 ++++++------ libs/canvas/line_set.cc | 6 +++--- libs/canvas/outline.cc | 4 ++-- libs/canvas/pixbuf.cc | 2 +- libs/canvas/poly_item.cc | 2 +- libs/canvas/poly_line.cc | 2 +- libs/canvas/polygon.cc | 2 +- libs/canvas/rectangle.cc | 10 +++++----- libs/canvas/step_button.cc | 2 +- libs/canvas/text.cc | 10 +++++----- libs/canvas/xfade_curve.cc | 2 +- 16 files changed, 71 insertions(+), 58 deletions(-) diff --git a/libs/canvas/arc.cc b/libs/canvas/arc.cc index 0d8d014e4c..9f45f5b39a 100644 --- a/libs/canvas/arc.cc +++ b/libs/canvas/arc.cc @@ -102,7 +102,7 @@ Arc::set_center (Duple const & c) _center = c; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -113,7 +113,7 @@ Arc::set_radius (Coord r) _radius = r; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -124,7 +124,7 @@ Arc::set_arc (double deg) _arc_degrees = deg; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -136,7 +136,7 @@ Arc::set_start (double deg) _start_degrees = deg; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -166,5 +166,5 @@ Arc::_size_allocate (Rect const & r) _radius = min (r.width(),r.height()) / 2.0; _center = Duple ((r.width()/2.), (r.height() /2.)); - _bounding_box_dirty = true; + set_bbox_dirty (); } diff --git a/libs/canvas/arrow.cc b/libs/canvas/arrow.cc index 742f62a189..7a4678e60b 100644 --- a/libs/canvas/arrow.cc +++ b/libs/canvas/arrow.cc @@ -101,7 +101,7 @@ Arrow::set_show_head (int which, bool show) setup_polygon (which); } - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -121,7 +121,7 @@ Arrow::set_head_outward (int which, bool outward) _heads[which].outward = outward; setup_polygon (which); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -139,7 +139,7 @@ Arrow::set_head_height (int which, Distance height) _heads[which].height = height; setup_polygon (which); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -157,7 +157,7 @@ Arrow::set_head_width (int which, Distance width) _heads[which].width = width; setup_polygon (which); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -174,7 +174,7 @@ Arrow::set_outline_width (Distance width) if (_heads[1].polygon) { _heads[1].polygon->set_outline_width (width); } - _bounding_box_dirty = true; + set_bbox_dirty (); } /** Set the x position of our line. @@ -190,7 +190,7 @@ Arrow::set_x (Coord x) _heads[i].polygon->set_x_position (x - _heads[i].width / 2); } } - _bounding_box_dirty = true; + set_bbox_dirty (); } /** Set the y position of end 0 of our line. @@ -203,7 +203,7 @@ Arrow::set_y0 (Coord y0) if (_heads[0].polygon) { _heads[0].polygon->set_y_position (y0); } - _bounding_box_dirty = true; + set_bbox_dirty (); } /** Set the y position of end 1 of our line. @@ -216,7 +216,7 @@ Arrow::set_y1 (Coord y1) if (_heads[1].polygon) { _heads[1].polygon->set_y_position (y1 - _heads[1].height); } - _bounding_box_dirty = true; + set_bbox_dirty (); } /** @return x position of our line in pixels (in our coordinate system) */ diff --git a/libs/canvas/canvas/item.h b/libs/canvas/canvas/item.h index 2c74c23fa4..a65eae7b4e 100644 --- a/libs/canvas/canvas/item.h +++ b/libs/canvas/canvas/item.h @@ -333,11 +333,11 @@ public: /** our bounding box; may be out of date if _bounding_box_dirty is true */ mutable Rect _bounding_box; - /** true if _bounding_box might be out of date, false if its definitely not */ - mutable bool _bounding_box_dirty; PackOptions _pack_options; void bb_clean () const; + void set_bbox_dirty () const; + bool bbox_dirty() const { return _bounding_box_dirty; } Rect _allocation; bool _layout_sensitive; @@ -373,7 +373,9 @@ private: std::string _tooltip; bool _ignore_events; bool _scroll_translation; - + /** true if _bounding_box might be out of date, false if its definitely not */ + mutable bool _bounding_box_dirty; + void find_scroll_parent (); void propagate_show_hide (); }; diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc index 5b76894945..100a666ee9 100644 --- a/libs/canvas/grid.cc +++ b/libs/canvas/grid.cc @@ -161,7 +161,7 @@ Grid::set_margin (double t, double r, double b, double l) void Grid::reset_bg () { - if (_bounding_box_dirty) { + if (bbox_dirty()) { (void) bounding_box (); } @@ -331,7 +331,7 @@ Grid::reposition_children () (*i)->set_position (Duple (col_dimens[c->second.x], row_dimens[c->second.y])); } - _bounding_box_dirty = true; + set_bbox_dirty (); reset_bg (); } diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index 5f20be6ab3..cc9a9b38ec 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -26,6 +26,7 @@ #include "canvas/canvas.h" #include "canvas/debug.h" #include "canvas/item.h" +#include "canvas/root_group.h" #include "canvas/scroll_group.h" using namespace std; @@ -41,7 +42,6 @@ Item::Item (Canvas* canvas) , _parent (0) , _scroll_parent (0) , _visible (true) - , _bounding_box_dirty (true) , _pack_options (PackOptions (0)) , _layout_sensitive (false) , _lut (0) @@ -50,6 +50,7 @@ Item::Item (Canvas* canvas) , _requested_height (-1) , _ignore_events (false) , _scroll_translation (true) + , _bounding_box_dirty (true) { DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); } @@ -61,7 +62,6 @@ Item::Item (Item* parent) , _parent (parent) , _scroll_parent (0) , _visible (true) - , _bounding_box_dirty (true) , _pack_options (PackOptions (0)) , _layout_sensitive (false) , _lut (0) @@ -70,6 +70,7 @@ Item::Item (Item* parent) , _requested_height (-1) , _ignore_events (false) , _scroll_translation (true) + , _bounding_box_dirty (true) { DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); @@ -88,7 +89,6 @@ Item::Item (Item* parent, Duple const& p) , _scroll_parent (0) , _position (p) , _visible (true) - , _bounding_box_dirty (true) , _pack_options (PackOptions (0)) , _layout_sensitive (false) , _requested_width (-1.) @@ -97,6 +97,7 @@ Item::Item (Item* parent, Duple const& p) , _resize_queued (false) , _ignore_events (false) , _scroll_translation (true) + , _bounding_box_dirty (true) { DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); @@ -607,7 +608,7 @@ Item::size_allocate (Rect const & r) { begin_change (); _size_allocate (r); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -661,7 +662,7 @@ Item::set_size_request (double w, double h) begin_change (); _requested_width = w; _requested_height = h; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -709,7 +710,7 @@ Item::set_size_request_to_display_given_text (const std::vector& st ArdourCanvas::Rect Item::bounding_box () const { - if (_bounding_box_dirty) { + if (bbox_dirty()) { compute_bounding_box (); assert (!_bounding_box_dirty); add_child_bounding_boxes (); @@ -848,7 +849,7 @@ Item::covers (Duple const & point) const { Duple p = window_to_item (point); - if (_bounding_box_dirty) { + if (bbox_dirty()) { (void) bounding_box (); } @@ -1055,7 +1056,7 @@ Item::add (Item* i) _items.push_back (i); i->reparent (this, true); invalidate_lut (); - _bounding_box_dirty = true; + set_bbox_dirty (); } void @@ -1066,7 +1067,7 @@ Item::add_front (Item* i) _items.push_front (i); i->reparent (this, true); invalidate_lut (); - _bounding_box_dirty = true; + set_bbox_dirty(); } void @@ -1093,7 +1094,7 @@ Item::remove (Item* i) i->set_layout_sensitive (false); _items.remove (i); invalidate_lut (); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -1106,8 +1107,7 @@ Item::clear (bool with_delete) clear_items (with_delete); invalidate_lut (); - _bounding_box_dirty = true; - + set_bbox_dirty (); end_change (); } @@ -1207,7 +1207,7 @@ Item::child_changed (bool bbox_changed) invalidate_lut (); if (bbox_changed) { - _bounding_box_dirty = true; + set_bbox_dirty (); } if (_parent) { @@ -1339,6 +1339,17 @@ Item::bb_clean () const _bounding_box_dirty = false; } +void +Item::set_bbox_dirty () const +{ + _bounding_box_dirty = true; + Item* i = _parent; + while (i) { + i->set_bbox_dirty (); + i = i->parent (); + } +} + void Item::set_pack_options (PackOptions po) { diff --git a/libs/canvas/line.cc b/libs/canvas/line.cc index 832cde0809..86b4d5af86 100644 --- a/libs/canvas/line.cc +++ b/libs/canvas/line.cc @@ -86,7 +86,7 @@ Line::set (Duple a, Duple b) _points[0] = a; _points[1] = b; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -100,7 +100,7 @@ Line::set_x (Coord x0, Coord x1) _points[0].x = x0; _points[1].x = x1; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -113,7 +113,7 @@ Line::set_x0 (Coord x0) _points[0].x = x0; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -126,7 +126,7 @@ Line::set_y0 (Coord y0) _points[0].y = y0; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -141,7 +141,7 @@ Line::set_x1 (Coord x1) _points[1].x = x1; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -154,7 +154,7 @@ Line::set_y1 (Coord y1) _points[1].y = y1; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } diff --git a/libs/canvas/line_set.cc b/libs/canvas/line_set.cc index 2efbfff5a0..bebf1f0100 100644 --- a/libs/canvas/line_set.cc +++ b/libs/canvas/line_set.cc @@ -80,7 +80,7 @@ LineSet::set_extent (Distance e) begin_change (); _extent = e; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -138,7 +138,7 @@ LineSet::add_coord (Coord y, Distance width, Gtkmm2ext::Color color) _lines.push_back (Line (y, width, color)); sort (_lines.begin(), _lines.end(), LineSorter()); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -147,7 +147,7 @@ LineSet::clear () { begin_change (); _lines.clear (); - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } diff --git a/libs/canvas/outline.cc b/libs/canvas/outline.cc index ff62c3db91..08a92a5cac 100644 --- a/libs/canvas/outline.cc +++ b/libs/canvas/outline.cc @@ -53,7 +53,7 @@ Outline::set_outline_width (Distance width) if (width != _outline_width) { _self.begin_change (); _outline_width = width; - _self._bounding_box_dirty = true; + _self.set_bbox_dirty (); _self.end_change (); } } @@ -64,7 +64,7 @@ Outline::set_outline (bool outline) if (outline != _outline) { _self.begin_change (); _outline = outline; - _self._bounding_box_dirty = true; + _self.set_bbox_dirty (); _self.end_change (); } } diff --git a/libs/canvas/pixbuf.cc b/libs/canvas/pixbuf.cc index 7b1384ebb8..48b6f05154 100644 --- a/libs/canvas/pixbuf.cc +++ b/libs/canvas/pixbuf.cc @@ -61,7 +61,7 @@ Pixbuf::set (Glib::RefPtr pixbuf) begin_change (); _pixbuf = pixbuf; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc index 0e65f96b40..dcffa153f0 100644 --- a/libs/canvas/poly_item.cc +++ b/libs/canvas/poly_item.cc @@ -135,7 +135,7 @@ PolyItem::set (Points const& points) _points = points; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } diff --git a/libs/canvas/poly_line.cc b/libs/canvas/poly_line.cc index a315f76174..2c9a61aa00 100644 --- a/libs/canvas/poly_line.cc +++ b/libs/canvas/poly_line.cc @@ -57,7 +57,7 @@ void PolyLine::set_fill_y1 (double y1) { begin_change (); - _bounding_box_dirty = true; + set_bbox_dirty (); _y1 = y1; end_change (); } diff --git a/libs/canvas/polygon.cc b/libs/canvas/polygon.cc index 6751a1851f..5b08cf47dc 100644 --- a/libs/canvas/polygon.cc +++ b/libs/canvas/polygon.cc @@ -128,7 +128,7 @@ Polygon::covers (Duple const & point) const Points::size_type j = npoints -1; bool oddNodes = false; - if (_bounding_box_dirty) { + if (bbox_dirty()) { (void) bounding_box (); } diff --git a/libs/canvas/rectangle.cc b/libs/canvas/rectangle.cc index 224a7e8dee..b03a310a53 100644 --- a/libs/canvas/rectangle.cc +++ b/libs/canvas/rectangle.cc @@ -191,7 +191,7 @@ Rectangle::set (Rect const & r) _rect = r; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -204,7 +204,7 @@ Rectangle::set_x0 (Coord x0) _rect.x0 = x0; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -217,7 +217,7 @@ Rectangle::set_y0 (Coord y0) _rect.y0 = y0; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change(); } } @@ -230,7 +230,7 @@ Rectangle::set_x1 (Coord x1) _rect.x1 = x1; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } @@ -243,7 +243,7 @@ Rectangle::set_y1 (Coord y1) _rect.y1 = y1; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } } diff --git a/libs/canvas/step_button.cc b/libs/canvas/step_button.cc index 3692d95b3f..12b237c2d4 100644 --- a/libs/canvas/step_button.cc +++ b/libs/canvas/step_button.cc @@ -107,7 +107,7 @@ StepButton::set_size (double w, double h) width = w; height = h; - _bounding_box_dirty = true; + set_bbox_dirty (); create_patterns (); diff --git a/libs/canvas/text.cc b/libs/canvas/text.cc index e30373df5d..3d44f36968 100644 --- a/libs/canvas/text.cc +++ b/libs/canvas/text.cc @@ -92,7 +92,7 @@ Text::set (string const & text) _text = text; _need_redraw = true; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -245,7 +245,7 @@ Text::clamp_width (double w) } begin_change (); _clamped_width = w; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -258,7 +258,7 @@ Text::compute_bounding_box () const return; } - if (_bounding_box_dirty) { + if (bbox_dirty()) { #ifdef __APPLE__ const float retina_factor = 0.5; #else @@ -283,7 +283,7 @@ Text::set_alignment (Pango::Alignment alignment) _alignment = alignment; _need_redraw = true; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } @@ -296,7 +296,7 @@ Text::set_font_description (Pango::FontDescription font_description) _need_redraw = true; _width_correction = -1.0; - _bounding_box_dirty = true; + set_bbox_dirty (); end_change (); } diff --git a/libs/canvas/xfade_curve.cc b/libs/canvas/xfade_curve.cc index 1d5eda3512..d770cf3e67 100644 --- a/libs/canvas/xfade_curve.cc +++ b/libs/canvas/xfade_curve.cc @@ -127,7 +127,7 @@ XFadeCurve::set_inout (Points const & in, Points const & out) begin_change (); _in.points = in; _out.points = out; - _bounding_box_dirty = true; + set_bbox_dirty (); interpolate (); end_change (); }