3 #include "pbd/compose.h"
4 #include "canvas/poly_item.h"
7 using namespace ArdourCanvas;
9 PolyItem::PolyItem (Group* parent)
17 PolyItem::compute_bounding_box () const
19 bool have_one = false;
23 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
25 bbox.x0 = min (bbox.x0, i->x);
26 bbox.y0 = min (bbox.y0, i->y);
27 bbox.x1 = max (bbox.x1, i->x);
28 bbox.y1 = max (bbox.y1, i->y);
30 bbox.x0 = bbox.x1 = i->x;
31 bbox.y0 = bbox.y1 = i->y;
37 _bounding_box = boost::optional<Rect> ();
39 _bounding_box = bbox.expand (_outline_width / 2);
42 _bounding_box_dirty = false;
46 PolyItem::render_path (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
48 bool done_first = false;
49 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
51 context->line_to (i->x, i->y);
53 context->move_to (i->x, i->y);
60 PolyItem::set (Points const & points)
66 _bounding_box_dirty = true;
71 PolyItem::get () const
77 PolyItem::add_poly_item_state (XMLNode* node) const
79 add_item_state (node);
81 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
82 XMLNode* p = new XMLNode ("Point");
83 p->add_property ("x", string_compose ("%1", i->x));
84 p->add_property ("y", string_compose ("%1", i->y));
85 node->add_child_nocopy (*p);
90 PolyItem::set_poly_item_state (XMLNode const * node)
92 XMLNodeList const & children = node->children ();
93 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
95 p.x = atof ((*i)->property("x")->value().c_str());
96 p.y = atof ((*i)->property("y")->value().c_str());
97 _points.push_back (p);
100 _bounding_box_dirty = true;