fix merge conflicts with master
[ardour.git] / libs / canvas / item.cc
index 68901aafc54af74c308c1d9d147f6abb4d5f3f06..b553d8d6ae76ff0e9e9249f0e73523fa3822d2ed 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2011-2013 Paul Davis
+    Author: Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
 #include "pbd/compose.h"
 #include "pbd/stacktrace.h"
 #include "pbd/convert.h"
@@ -51,13 +70,13 @@ Item::init ()
 
 Item::~Item ()
 {
-       if (_canvas) {
-               _canvas->item_going_away (this, _bounding_box);
-       }
-       
        if (_parent) {
                _parent->remove (this);
        }
+
+       if (_canvas) {
+               _canvas->item_going_away (this, _bounding_box);
+       }
 }
 
 ArdourCanvas::Rect
@@ -108,6 +127,20 @@ Item::canvas_to_item (ArdourCanvas::Duple const & d) const
        return d.translate (offset);
 }
 
+ArdourCanvas::Rect
+Item::canvas_to_item (ArdourCanvas::Rect 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
 {
@@ -126,6 +159,24 @@ Item::canvas_to_item (Coord& x, Coord& y) const
        y = d.y;
 }
 
+Duple
+Item::item_to_window (ArdourCanvas::Duple const & d) const
+{
+       return _canvas->canvas_to_window (item_to_canvas (d));
+}
+
+Duple
+Item::window_to_item (ArdourCanvas::Duple const & d) const
+{
+       return _canvas->window_to_canvas (canvas_to_item (d));
+}
+
+ArdourCanvas::Rect
+Item::item_to_window (ArdourCanvas::Rect const & r) const
+{
+       return _canvas->canvas_to_window (item_to_canvas (r));
+}
+
 /** Set the position of this item in the parent's coordinates */
 void
 Item::set_position (Duple p)
@@ -217,13 +268,14 @@ Item::parent_to_item (ArdourCanvas::Rect const & d) const
 void
 Item::unparent ()
 {
-       _canvas = 0;
        _parent = 0;
 }
 
 void
 Item::reparent (Group* new_parent)
 {
+       assert (_canvas == _parent->canvas());
+
        if (_parent) {
                _parent->remove (this);
        }
@@ -276,7 +328,6 @@ Item::width () const
        return 0;
 }
 
-/* XXX may be called even if bbox is not changing ... bit grotty */
 void
 Item::begin_change ()
 {
@@ -293,6 +344,17 @@ Item::end_change ()
        }
 }
 
+void
+Item::begin_visual_change ()
+{
+}
+
+void
+Item::end_visual_change ()
+{
+       _canvas->item_visual_property_changed (this);
+}
+
 void
 Item::move (Duple movement)
 {
@@ -341,7 +403,7 @@ Item::dump (ostream& o) const
 {
        boost::optional<ArdourCanvas::Rect> bb = bounding_box();
 
-       o << _canvas->indent() << whatami() << ' ' << this;
+       o << _canvas->indent() << whatami() << ' ' << this << " Visible ? " << _visible;
        o << " @ " << position();
        
 #ifdef CANVAS_DEBUG