2 Copyright (C) 2011-2013 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "pbd/compose.h"
24 #include "canvas/poly_item.h"
25 #include "canvas/canvas.h"
28 using namespace ArdourCanvas;
30 PolyItem::PolyItem (Group* parent)
38 PolyItem::compute_bounding_box () const
40 bool have_one = false;
43 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
45 bbox.x0 = min (bbox.x0, i->x);
46 bbox.y0 = min (bbox.y0, i->y);
47 bbox.x1 = max (bbox.x1, i->x);
48 bbox.y1 = max (bbox.y1, i->y);
50 bbox.x0 = bbox.x1 = i->x;
51 bbox.y0 = bbox.y1 = i->y;
58 _bounding_box = boost::optional<Rect> ();
60 _bounding_box = bbox.expand (_outline_width / 2);
63 _bounding_box_dirty = false;
67 PolyItem::render_path (Rect const & /* area */, Cairo::RefPtr<Cairo::Context> context) const
69 if (_points.size() < 2) {
73 Points::const_iterator i = _points.begin();
74 Duple c (item_to_window (Duple (i->x, i->y)));
76 context->move_to (c.x, c.y);
79 while (i != _points.end()) {
80 c = item_to_window (Duple (i->x, i->y));
81 context->line_to (c.x, c.y);
87 PolyItem::render_curve (Rect const & area, Cairo::RefPtr<Cairo::Context> context, Points const & first_control_points, Points const & second_control_points) const
89 if (_points.size() <= 2) {
90 render_path (area, context);
94 Points::const_iterator cp1 = first_control_points.begin();
95 Points::const_iterator cp2 = second_control_points.begin();
96 Points::const_iterator p = _points.begin();
98 Duple c = item_to_window (Duple (p->x, p->y));
99 context->move_to (c.x, c.y);
102 while (p != _points.end()) {
104 Duple c1 = item_to_window (Duple (cp1->x, cp1->y));
105 Duple c2 = item_to_window (Duple (cp2->x, cp2->y));
107 c = item_to_window (Duple (p->x, p->y));
109 context->curve_to (c1.x, c1.y, c2.x, c2.y, c.x, c.y);
118 PolyItem::set (Points const & points)
124 _bounding_box_dirty = true;
129 PolyItem::get () const
135 PolyItem::dump (ostream& o) const
139 o << _canvas->indent() << '\t' << _points.size() << " points" << endl;
140 for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) {
141 o << _canvas->indent() << "\t\t" << i->x << ", " << i->y << endl;