diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-12 14:53:44 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-12 14:53:44 -0400 |
commit | 590882f3c8e063528452d71daffb36d3151da05e (patch) | |
tree | 27480b4b85a7d2a8aeae51c9c9470c196b8dfff8 /libs/canvas/item.cc | |
parent | 551014240a49ee11b9dc7541bbe8427ac3402aef (diff) |
change Canvas heirarchy and constructors
Items no longer need a parent group (they require a Canvas pointer instead), so all constructors have been rationalized
and have two variants, one with a parent and one with a canvas.
All Items now inherit from Fill and Outline, to banish diagonal inheritance and virtual base classes and all that.
There were zero changes to the Ardour GUI arising from these changes.
Diffstat (limited to 'libs/canvas/item.cc')
-rw-r--r-- | libs/canvas/item.cc | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index 2bca2feac2..53dca5d976 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -34,41 +34,53 @@ using namespace PBD; using namespace ArdourCanvas; Item::Item (Canvas* canvas) - : _canvas (canvas) + : Fill (*this) + , Outline (*this) + , _canvas (canvas) , _parent (0) + , _visible (true) + , _bounding_box_dirty (true) + , _ignore_events (false) { - init (); -} + DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); +} Item::Item (Group* parent) - : _canvas (parent->canvas ()) + : Fill (*this) + , Outline (*this) + , _canvas (parent->canvas()) , _parent (parent) + , _visible (true) + , _bounding_box_dirty (true) + , _ignore_events (false) { - init (); -} + DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); + + if (parent) { + _parent->add (this); + } + + find_scroll_parent (); +} -Item::Item (Group* parent, Duple position) - : _canvas (parent->canvas()) +Item::Item (Group* parent, Duple const& p) + : Fill (*this) + , Outline (*this) + , _canvas (parent->canvas()) , _parent (parent) - , _position (position) + , _position (p) + , _visible (true) + , _bounding_box_dirty (true) + , _ignore_events (false) { - init (); -} + DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); -void -Item::init () -{ - _visible = true; - _bounding_box_dirty = true; - _ignore_events = false; - - if (_parent) { + if (parent) { _parent->add (this); } find_scroll_parent (); - DEBUG_TRACE (DEBUG::CanvasItems, string_compose ("new canvas item %1\n", this)); } Item::~Item () @@ -98,7 +110,7 @@ Item::window_origin () const if (_parent) { return _parent->item_to_window (_position); } else { - return _parent->item_to_window (Duple (0,0)); + return _position; } } @@ -254,22 +266,25 @@ Item::set_y_position (Coord y) void Item::raise_to_top () { - assert (_parent); - _parent->raise_child_to_top (this); + if (_parent) { + _parent->raise_child_to_top (this); + } } void Item::raise (int levels) { - assert (_parent); - _parent->raise_child (this, levels); + if (_parent) { + _parent->raise_child (this, levels); + } } void Item::lower_to_bottom () { - assert (_parent); - _parent->lower_child_to_bottom (this); + if (_parent) { + _parent->lower_child_to_bottom (this); + } } void @@ -318,7 +333,11 @@ Item::unparent () void Item::reparent (Group* new_parent) { - assert (_canvas == _parent->canvas()); + if (new_parent == _parent) { + return; + } + + assert (_canvas == new_parent->canvas()); if (_parent) { _parent->remove (this); @@ -370,10 +389,16 @@ Item::common_ancestor_within (uint32_t limit, const Item& other) const while (d1 != d2) { if (d1 > d2) { + if (!i1) { + return false; + } i1 = i1->parent(); d1--; limit--; } else { + if (!i2) { + return false; + } i2 = i2->parent(); d2--; limit--; @@ -416,9 +441,15 @@ Item::closest_ancestor_with (const Item& other) const while (d1 != d2) { if (d1 > d2) { + if (!i1) { + return 0; + } i1 = i1->parent(); d1--; } else { + if (!i2) { + return 0; + } i2 = i2->parent(); d2--; } |