Merge branch 'master' into cairocanvas
[ardour.git] / libs / canvas / item.cc
index 75a5718271af928eb54a5f08813c9a1ffce066c7..569d03f81f9fb8198a55aeb96426e6b7576ce1b9 100644 (file)
@@ -1,6 +1,24 @@
+/*
+    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/xml++.h"
 #include "pbd/convert.h"
 
 #include "ardour/utils.h"
@@ -52,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
@@ -218,13 +236,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);
        }
@@ -277,7 +296,6 @@ Item::width () const
        return 0;
 }
 
-/* XXX may be called even if bbox is not changing ... bit grotty */
 void
 Item::begin_change ()
 {
@@ -295,25 +313,20 @@ Item::end_change ()
 }
 
 void
-Item::move (Duple movement)
+Item::begin_visual_change ()
 {
-       set_position (position() + movement);
 }
 
 void
-Item::add_item_state (XMLNode* node) const
+Item::end_visual_change ()
 {
-       node->add_property ("x-position", string_compose ("%1", _position.x));
-       node->add_property ("y-position", string_compose ("%1", _position.y));
-       node->add_property ("visible", _visible ? "yes" : "no");
+       _canvas->item_visual_property_changed (this);
 }
 
 void
-Item::set_item_state (XMLNode const * node)
+Item::move (Duple movement)
 {
-       _position.x = atof (node->property("x-position")->value().c_str());
-       _position.y = atof (node->property("y-position")->value().c_str());
-       _visible = PBD::string_is_affirmative (node->property("visible")->value());
+       set_position (position() + movement);
 }
 
 void
@@ -358,7 +371,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