4 #include "pbd/compose.h"
6 #include "canvas/poly_item.h"
7 #include "canvas/canvas.h"
10 using namespace ArdourCanvas;
12 PolyItem::PolyItem (Group* parent)
20 PolyItem::compute_bounding_box () const
22 bool have_one = false;
26 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
28 bbox.x0 = min (bbox.x0, i->x);
29 bbox.y0 = min (bbox.y0, i->y);
30 bbox.x1 = max (bbox.x1, i->x);
31 bbox.y1 = max (bbox.y1, i->y);
33 bbox.x0 = bbox.x1 = i->x;
34 bbox.y0 = bbox.y1 = i->y;
41 _bounding_box = boost::optional<Rect> ();
43 _bounding_box = bbox.expand (_outline_width / 2);
46 _bounding_box_dirty = false;
50 PolyItem::render_path (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
52 bool done_first = false;
53 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
55 context->line_to (i->x, i->y);
57 context->move_to (i->x, i->y);
64 PolyItem::set (Points const & points)
70 _bounding_box_dirty = true;
75 PolyItem::get () const
81 PolyItem::add_poly_item_state (XMLNode* node) const
83 add_item_state (node);
85 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
86 XMLNode* p = new XMLNode ("Point");
87 p->add_property ("x", string_compose ("%1", i->x));
88 p->add_property ("y", string_compose ("%1", i->y));
89 node->add_child_nocopy (*p);
94 PolyItem::set_poly_item_state (XMLNode const * node)
96 XMLNodeList const & children = node->children ();
97 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
99 p.x = atof ((*i)->property("x")->value().c_str());
100 p.y = atof ((*i)->property("y")->value().c_str());
101 _points.push_back (p);
104 _bounding_box_dirty = true;
108 PolyItem::dump (ostream& o) const
112 o << _canvas->indent() << '\t' << _points.size() << " points" << endl;
113 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
114 o << _canvas->indent() << "\t\t" << i->x << ", " << i->y << endl;