X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fcanvas%2Fpoly_item.cc;h=855140856eb0f3ccdb60cbcd0d2f93870d67d22c;hb=c8c6bca6587450ff64303dbc994a4cd28d6ce7aa;hp=2500ac90e2ea034bb7aea114549856c1cc70a758;hpb=5e5c71614664d02e1160454f080505fbcc2078aa;p=ardour.git diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc index 2500ac90e2..855140856e 100644 --- a/libs/canvas/poly_item.cc +++ b/libs/canvas/poly_item.cc @@ -27,64 +27,72 @@ 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; + if (!_points.empty()) { - for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) { - if (have_one) { + 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 (); } else { - _bounding_box = bbox.expand (_outline_width / 2); + _bounding_box = boost::optional (); } - + _bounding_box_dirty = false; } void -PolyItem::render_path (Rect const & /*area*/, Cairo::RefPtr context) const +PolyItem::render_path (Rect const & /* area */, Cairo::RefPtr context) const { - bool done_first = false; - for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) { - if (done_first) { - Duple c = item_to_window (Duple (i->x, i->y)); - context->line_to (c.x, c.y); - } else { - Duple c = item_to_window (Duple (i->x, i->y)); - context->move_to (c.x, c.y); - done_first = true; - } + if (_points.size() < 2) { + return; + } + + Points::const_iterator i = _points.begin(); + Duple c (item_to_window (Duple (i->x, i->y))); + const double pixel_adjust = (_outline_width == 1.0 ? 0.5 : 0.0); + + context->move_to (c.x + pixel_adjust, c.y + pixel_adjust); + ++i; + + while (i != _points.end()) { + c = item_to_window (Duple (i->x, i->y)); + context->line_to (c.x + pixel_adjust, c.y + pixel_adjust); + ++i; } } void PolyItem::render_curve (Rect const & area, Cairo::RefPtr context, Points const & first_control_points, Points const & second_control_points) const { - bool done_first = false; - if (_points.size() <= 2) { render_path (area, context); return; @@ -92,38 +100,45 @@ PolyItem::render_curve (Rect const & area, Cairo::RefPtr context Points::const_iterator cp1 = first_control_points.begin(); Points::const_iterator cp2 = second_control_points.begin(); + Points::const_iterator p = _points.begin(); + const double pixel_adjust = (_outline_width == 1.0 ? 0.5 : 0.0); - for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) { + Duple c = item_to_window (Duple (p->x, p->y)); + context->move_to (c.x + pixel_adjust, c.y + pixel_adjust); + ++p; - if (done_first) { + while (p != _points.end()) { - Duple c1 = item_to_window (Duple (cp1->x, cp1->y)); - Duple c2 = item_to_window (Duple (cp2->x, cp2->y)); - Duple c3 = item_to_window (Duple (i->x, i->y)); + Duple c1 = item_to_window (Duple (cp1->x, cp1->y)); + Duple c2 = item_to_window (Duple (cp2->x, cp2->y)); - context->curve_to (c1.x, c1.y, c2.x, c2.y, c3.x, c3.y); + c = item_to_window (Duple (p->x, p->y)); - cp1++; - cp2++; - - } else { + 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); - Duple c = item_to_window (Duple (i->x, i->y)); - context->move_to (c.x, c.y); - done_first = true; - } + ++cp1; + ++cp2; + ++p; } } 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 &