fix crash when copy'ing latent plugins
[ardour.git] / libs / canvas / poly_item.cc
index 3b2e2efad9a8dafc1760e4c75eaad4e267ae4437..855140856eb0f3ccdb60cbcd0d2f93870d67d22c 100644 (file)
 using namespace std;
 using namespace ArdourCanvas;
 
-PolyItem::PolyItem (Group* parent)
-       : Item (parent)
-       , Outline (parent)
+PolyItem::PolyItem (Canvas* c)
+       : Item (c)
 {
+}
 
+PolyItem::PolyItem (Item* parent)
+       : Item (parent)
+{
 }
 
 void
 PolyItem::compute_bounding_box () const
 {
-       bool have_one = false;
-       Rect bbox;
 
-       for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
-               if (have_one) {
+       if (!_points.empty()) {
+
+               Rect bbox;
+               Points::const_iterator i = _points.begin();
+
+               bbox.x0 = bbox.x1 = i->x;
+               bbox.y0 = bbox.y1 = i->y;
+
+               ++i;
+
+               while (i != _points.end()) {
                        bbox.x0 = min (bbox.x0, i->x);
                        bbox.y0 = min (bbox.y0, i->y);
                        bbox.x1 = max (bbox.x1, i->x);
                        bbox.y1 = max (bbox.y1, i->y);
-               } else {
-                       bbox.x0 = bbox.x1 = i->x;
-                       bbox.y0 = bbox.y1 = i->y;
-                       have_one = true;
+                       ++i;
                }
-       }
+
+               _bounding_box = bbox.expand (_outline_width + 0.5);
 
 
-       if (!have_one) {
-               _bounding_box = boost::optional<Rect> ();
        } else {
-               _bounding_box = bbox.expand (_outline_width / 2);
+               _bounding_box = boost::optional<Rect> ();
        }
-       
+
        _bounding_box_dirty = false;
 }
 
@@ -107,14 +113,14 @@ PolyItem::render_curve (Rect const & area, Cairo::RefPtr<Cairo::Context> context
                Duple c2 = item_to_window (Duple (cp2->x, cp2->y));
 
                c = item_to_window (Duple (p->x, p->y));
-               
-               context->curve_to (c1.x + pixel_adjust, 
-                                  c1.y + pixel_adjust, 
-                                  c2.x + pixel_adjust, 
-                                  c2.y + pixel_adjust, 
-                                  c.x + pixel_adjust, 
+
+               context->curve_to (c1.x + pixel_adjust,
+                                  c1.y + pixel_adjust,
+                                  c2.x + pixel_adjust,
+                                  c2.y + pixel_adjust,
+                                  c.x + pixel_adjust,
                                   c.y + pixel_adjust);
-               
+
                ++cp1;
                ++cp2;
                ++p;
@@ -124,12 +130,15 @@ PolyItem::render_curve (Rect const & area, Cairo::RefPtr<Cairo::Context> context
 void
 PolyItem::set (Points const & points)
 {
-       begin_change ();
-       
-       _points = points;
-       
-       _bounding_box_dirty = true;
-       end_change ();
+       if (_points != points) {
+
+               begin_change ();
+
+               _points = points;
+
+               _bounding_box_dirty = true;
+               end_change ();
+       }
 }
 
 Points const &