summaryrefslogtreecommitdiff
path: root/libs/canvas/item.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-12-18 10:30:38 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2014-12-18 10:30:38 -0500
commit74be550698d19758f5ccd0578f2ec4d07edadcb0 (patch)
treecc700125eaa34a7906496f45fe23d0d05cea06d8 /libs/canvas/item.cc
parent09687c171239977021af42a7d706af39d0df0173 (diff)
change Item::visible() to Item::self_visible(); add Item::visible() which returns accurate visibility
Child items will be hidden when their ancestors are hidden. The old ::visible() implementation didn't reflect this. In addition, when changes are made to hidden items (new definition of visible/not visible), don't bother to request redraws, since this will be done when the item becomes visible again.
Diffstat (limited to 'libs/canvas/item.cc')
-rw-r--r--libs/canvas/item.cc90
1 files changed, 71 insertions, 19 deletions
diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc
index 1b0bb0416a..3ec06130b7 100644
--- a/libs/canvas/item.cc
+++ b/libs/canvas/item.cc
@@ -104,6 +104,21 @@ Item::~Item ()
delete _lut;
}
+bool
+Item::visible() const
+{
+ Item const * i = this;
+
+ while (i) {
+ if (!i->self_visible()) {
+ return false;
+ }
+ i = i->parent();
+ }
+
+ return true;
+}
+
Duple
Item::canvas_origin () const
{
@@ -254,10 +269,17 @@ Item::set_position (Duple p)
_position = p;
- _canvas->item_moved (this, pre_change_parent_bounding_box);
+ /* only update canvas and parent if visible. Otherwise, this
+ will be done when ::show() is called.
+ */
+
+ if (visible()) {
+ _canvas->item_moved (this, pre_change_parent_bounding_box);
+
- if (_parent) {
- _parent->child_changed ();
+ if (_parent) {
+ _parent->child_changed ();
+ }
}
}
@@ -303,15 +325,28 @@ Item::hide ()
if (_visible) {
_visible = false;
- /* recompute parent bounding box, which may alter now that this
- * child is hidden.
- */
+ /* children are all hidden because we are hidden, no need
+ to propagate change because our bounding box necessarily
+ includes them all already. thus our being hidden results
+ in (a) a redraw of the entire bounding box (b) no children
+ will be drawn.
- if (_parent) {
- _parent->child_changed ();
+ BUT ... current item in canvas might be one of our children,
+ which is now hidden. So propagate away.
+ */
+
+ for (list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
+
+ if ((*i)->self_visible()) {
+ /* item was visible but is now hidden because
+ we (its parent) are hidden
+ */
+ (*i)->propagate_show_hide ();
+ }
}
- _canvas->item_shown_or_hidden (this);
+
+ propagate_show_hide ();
}
}
@@ -319,18 +354,34 @@ void
Item::show ()
{
if (!_visible) {
- _visible = true;
- /* bounding box may have changed while we were hidden */
+ _visible = true;
- if (_parent) {
- _parent->child_changed ();
+ for (list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
+ if ((*i)->self_visible()) {
+ /* item used to be hidden by us (its parent),
+ but is now visible
+ */
+ (*i)->propagate_show_hide ();
+ }
}
- _canvas->item_shown_or_hidden (this);
+ propagate_show_hide ();
}
}
+void
+Item::propagate_show_hide ()
+{
+ /* bounding box may have changed while we were hidden */
+
+ if (_parent) {
+ _parent->child_changed ();
+ }
+
+ _canvas->item_shown_or_hidden (this);
+}
+
Duple
Item::item_to_parent (Duple const & d) const
{
@@ -555,7 +606,7 @@ Item::width () const
void
Item::redraw () const
{
- if (_visible && _bounding_box && _canvas) {
+ if (visible() && _bounding_box && _canvas) {
_canvas->request_redraw (item_to_window (_bounding_box.get()));
}
}
@@ -569,7 +620,7 @@ Item::begin_change ()
void
Item::end_change ()
{
- if (_visible) {
+ if (visible()) {
_canvas->item_changed (this, _pre_change_bounding_box);
if (_parent) {
@@ -586,7 +637,7 @@ Item::begin_visual_change ()
void
Item::end_visual_change ()
{
- if (_visible) {
+ if (visible()) {
_canvas->item_visual_property_changed (this);
}
}
@@ -1014,7 +1065,7 @@ Item::dump (ostream& o) const
{
boost::optional<ArdourCanvas::Rect> bb = bounding_box();
- o << _canvas->indent() << whatami() << ' ' << this << " Visible ? " << _visible;
+ o << _canvas->indent() << whatami() << ' ' << this << " self-Visible ? " << self_visible() << " visible ? " << visible();
o << " @ " << position();
#ifdef CANVAS_DEBUG
@@ -1038,7 +1089,8 @@ Item::dump (ostream& o) const
o << _canvas->indent();
o << " @ " << position();
o << " Items: " << _items.size();
- o << " Visible ? " << _visible;
+ o << " Self-Visible ? " << self_visible();
+ o << " Visible ? " << visible();
boost::optional<Rect> bb = bounding_box();