Fix 0006183 (waveview crash).
[ardour.git] / libs / canvas / arrow.cc
index 2e9557e1796ec1038dd963a3c8003f94ff6e19a2..d78b04ef5804ceb867c48bfb380900c24d1a5da3 100644 (file)
@@ -34,11 +34,21 @@ using namespace ArdourCanvas;
 /** Construct an Arrow.
  *  @param parent Parent canvas group.
  */
-Arrow::Arrow (Group* parent)
-       : Group (parent)
+Arrow::Arrow (Canvas* c)
+       : Container (c)
 {
-       assert (parent);
+       setup ();
+}
 
+Arrow::Arrow (Item* parent)
+       : Container (parent)
+{
+       setup ();
+}
+
+void
+Arrow::setup ()
+{
        /* set up default arrow heads at each end */
        for (int i = 0; i < 2; ++i) {
                _heads[i].polygon = new Polygon (this);
@@ -53,6 +63,24 @@ Arrow::Arrow (Group* parent)
        CANVAS_DEBUG_NAME (_line, "arrow line");
 }
 
+void
+Arrow::compute_bounding_box () const
+{
+       /* Compute our bounding box manually rather than using the default
+          container algorithm, since having the bounding box with origin other
+          than zero causes strange problems for mysterious reasons. */
+
+       const double outline_pad = 0.5 + (_line->outline_width() / 2.0);
+       const double head_width  = std::max(_heads[0].width, _heads[1].width);
+
+       _bounding_box = Rect(0,
+                            0,
+                            _line->x1() + (head_width / 2.0) + outline_pad,
+                            _line->y1());
+
+       _bounding_box_dirty = false;
+}
+
 /** Set whether to show an arrow head at one end or other
  *  of the line.
  *  @param which 0 or 1 to specify the arrow head to set up.
@@ -145,6 +173,7 @@ Arrow::set_outline_width (Distance width)
        if (_heads[1].polygon) {
                _heads[1].polygon->set_outline_width (width);
        }
+       _bounding_box_dirty = true;
 }
 
 /** Set the x position of our line.
@@ -160,7 +189,7 @@ Arrow::set_x (Coord x)
                        _heads[i].polygon->set_x_position (x - _heads[i].width / 2);
                }
        }
-               
+       _bounding_box_dirty = true;
 }
 
 /** Set the y position of end 0 of our line.
@@ -173,6 +202,7 @@ Arrow::set_y0 (Coord y0)
        if (_heads[0].polygon) {
                _heads[0].polygon->set_y_position (y0);
        }
+       _bounding_box_dirty = true;
 }
 
 /** Set the y position of end 1 of our line.
@@ -185,6 +215,7 @@ Arrow::set_y1 (Coord y1)
        if (_heads[1].polygon) {
                _heads[1].polygon->set_y_position (y1 - _heads[1].height);
        }
+       _bounding_box_dirty = true;
 }
 
 /** @return x position of our line in pixels (in our coordinate system) */