2 * Copyright (C) 2013-2015 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <cairomm/context.h>
25 #include "pbd/compose.h"
26 #include "canvas/circle.h"
27 #include "canvas/types.h"
28 #include "canvas/debug.h"
29 #include "canvas/canvas.h"
32 using namespace ArdourCanvas;
38 , _start_degrees (0.0)
42 Arc::Arc (Item* parent)
46 , _start_degrees (0.0)
51 Arc::compute_bounding_box () const
55 /* this could be smaller in the case of small _arc values
56 but I can't be bothered to optimize it.
59 bbox.x0 = _center.x - _radius;
60 bbox.y0 = _center.y - _radius;
61 bbox.x1 = _center.x + _radius;
62 bbox.y1 = _center.y + _radius;
64 bbox = bbox.expand (0.5 + (_outline_width / 2));
67 _bounding_box_dirty = false;
71 Arc::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
73 if (_radius <= 0.0 || _arc_degrees <= 0.0) {
77 Duple c = item_to_window (Duple (_center.x, _center.y));
79 context->arc (c.x, c.y, _radius, _start_degrees * (M_PI/180.0), _arc_degrees * (M_PI/180.0));
80 setup_fill_context (context);
81 context->fill_preserve ();
82 setup_outline_context (context);
87 Arc::set_center (Duple const & c)
93 _bounding_box_dirty = true;
98 Arc::set_radius (Coord r)
104 _bounding_box_dirty = true;
109 Arc::set_arc (double deg)
115 _bounding_box_dirty = true;
121 Arc::set_start (double deg)
125 _start_degrees = deg;
127 _bounding_box_dirty = true;
132 Arc::covers (Duple const & point) const
134 Duple p = window_to_item (point);
136 double angle_degs = atan (p.y/p.x) * 2.0 * M_PI;
137 double radius = sqrt (p.x * p.x + p.y * p.y);
139 return (angle_degs >= _start_degrees) &&
140 (angle_degs <= (_start_degrees + _arc_degrees)) &&