diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-04-15 10:38:12 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-04-15 10:38:12 -0400 |
commit | af4539f857a14be3856da89a20811bf39e4ffb6e (patch) | |
tree | 1a830af01e43e9c7491408f54514882ad59df465 /libs/canvas/item.cc | |
parent | cfe4bfb7325c7786865ea1e51505e4c9a4d0631f (diff) |
a few changes to fix region dragging, all related to coordinate system handling, which is now much simpler with the new canvas; more debugging output when asked for
Diffstat (limited to 'libs/canvas/item.cc')
-rw-r--r-- | libs/canvas/item.cc | 109 |
1 files changed, 65 insertions, 44 deletions
diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index 2c4ec893e7..75a5718271 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -67,6 +67,66 @@ Item::item_to_parent (ArdourCanvas::Rect const & r) const return r.translate (_position); } +ArdourCanvas::Rect +Item::item_to_canvas (ArdourCanvas::Rect const & r) const +{ + Item const * i = this; + Duple offset; + + while (i) { + offset = offset.translate (i->position()); + i = i->parent(); + } + + return r.translate (offset); +} + +ArdourCanvas::Duple +Item::item_to_canvas (ArdourCanvas::Duple const & d) const +{ + Item const * i = this; + Duple offset; + + while (i) { + offset = offset.translate (i->position()); + i = i->parent(); + } + + return d.translate (offset); +} + +ArdourCanvas::Duple +Item::canvas_to_item (ArdourCanvas::Duple const & d) const +{ + Item const * i = this; + Duple offset; + + while (i) { + offset = offset.translate (-(i->position())); + i = i->parent(); + } + + return d.translate (offset); +} + +void +Item::item_to_canvas (Coord& x, Coord& y) const +{ + Duple d = item_to_canvas (Duple (x, y)); + + x = d.x; + y = d.y; +} + +void +Item::canvas_to_item (Coord& x, Coord& y) const +{ + Duple d = canvas_to_item (Duple (x, y)); + + x = d.x; + y = d.y; +} + /** Set the position of this item in the parent's coordinates */ void Item::set_position (Duple p) @@ -75,6 +135,9 @@ Item::set_position (Duple p) boost::optional<ArdourCanvas::Rect> pre_change_parent_bounding_box; if (bbox) { + /* see the comment in Canvas::item_moved() to understand + * why we use the parent's bounding box here. + */ pre_change_parent_bounding_box = item_to_parent (bbox.get()); } @@ -285,50 +348,6 @@ Item::get_data (string const & key) const } void -Item::item_to_canvas (Coord& x, Coord& y) const -{ - Duple d (x, y); - Item const * i = this; - - while (i) { - d = i->item_to_parent (d); - i = i->_parent; - } - - x = d.x; - y = d.y; -} - -void -Item::canvas_to_item (Coord& x, Coord& y) const -{ - Duple d (x, y); - Item const * i = this; - - while (i) { - d = i->parent_to_item (d); - i = i->_parent; - } - - x = d.x; - y = d.y; -} - -ArdourCanvas::Rect -Item::item_to_canvas (ArdourCanvas::Rect const & area) const -{ - ArdourCanvas::Rect r = area; - Item const * i = this; - - while (i) { - r = i->item_to_parent (r); - i = i->parent (); - } - - return r; -} - -void Item::set_ignore_events (bool ignore) { _ignore_events = ignore; @@ -340,6 +359,7 @@ Item::dump (ostream& o) const boost::optional<ArdourCanvas::Rect> bb = bounding_box(); o << _canvas->indent() << whatami() << ' ' << this; + o << " @ " << position(); #ifdef CANVAS_DEBUG if (!name.empty()) { @@ -349,6 +369,7 @@ Item::dump (ostream& o) const if (bb) { o << endl << _canvas->indent() << "\tbbox: " << bb.get(); + o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb.get()); } else { o << " bbox unset"; } |