tentative intermediate state for ArdourCanvas::Curve
[ardour.git] / libs / canvas / line_set.cc
index 5aefe1bf47f76cff8c2428ab4686a79b7450a576..1625e0478dd80cee7fe0e9f15b41664330242648 100644 (file)
@@ -45,11 +45,9 @@ LineSet::compute_bounding_box () const
 {
        if (_lines.empty ()) {
                _bounding_box = boost::optional<Rect> ();
-               _bounding_box_dirty = false;
-               return;
+       } else {
+               _bounding_box = Rect (0, _lines.front().y - (_lines.front().width/2.0), COORD_MAX, min (_height, _lines.back().y - (_lines.back().width/2.0)));
        }
-       
-       _bounding_box = Rect (0, _lines.front().y, COORD_MAX, min (_height, _lines.back().y));
        _bounding_box_dirty = false;
 }
 
@@ -67,18 +65,22 @@ LineSet::set_height (Distance height)
 void
 LineSet::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
 {
+       /* area is in window coordinates */
+
        for (list<Line>::const_iterator i = _lines.begin(); i != _lines.end(); ++i) {
-               if (i->y > area.y1) {
-                       break;
-               } else if (i->y > area.y0) {
-                       set_source_rgba (context, i->color);
-                       context->set_line_width (i->width);
-                       Duple p0 = item_to_window (Duple (area.x0, i->y));
-                       Duple p1 = item_to_window (Duple (area.x1, i->y));
-                       context->move_to (p0.x, p0.y);
-                       context->line_to (p1.x, p1.y);
-                       context->stroke ();
+
+               Rect self = item_to_window (Rect (0, i->y - (i->width/2.0), COORD_MAX, i->y + (i->width/2.0)));
+               boost::optional<Rect> intersect = self.intersection (area);
+                       
+               if (!intersect) {
+                       continue;       
                }
+
+               set_source_rgba (context, i->color);
+               context->set_line_width (i->width);
+               context->move_to (intersect->x0, self.y0 + ((self.y1 - self.y0)/2.0));
+               context->line_to (intersect->x1, self.y0 + ((self.y1 - self.y0)/2.0));
+               context->stroke ();
        }
 }
 
@@ -102,3 +104,9 @@ LineSet::clear ()
        _bounding_box_dirty = true;
        end_change ();
 }
+
+bool
+LineSet::covers (Duple const & /*point*/) const
+{
+       return false;
+}