fix issue with initialization of a BBT_Time variable.
[ardour.git] / libs / canvas / arc.cc
1 /*
2     Copyright (C) 2013 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <cmath>
20 #include <algorithm>
21
22 #include <cairomm/context.h>
23
24 #include "pbd/compose.h"
25 #include "canvas/circle.h"
26 #include "canvas/types.h"
27 #include "canvas/debug.h"
28 #include "canvas/canvas.h"
29
30 using namespace std;
31 using namespace ArdourCanvas;
32
33 Arc::Arc (Canvas* c)
34         : Item (c)
35         , _radius (0.0)
36         , _arc_degrees (0.0)
37         , _start_degrees (0.0)
38 {
39 }
40
41 Arc::Arc (Item* parent)
42         : Item (parent)
43         , _radius (0.0)
44         , _arc_degrees (0.0)
45         , _start_degrees (0.0)
46 {
47 }
48
49 void
50 Arc::compute_bounding_box () const
51 {
52         Rect bbox;
53
54         /* this could be smaller in the case of small _arc values
55            but I can't be bothered to optimize it.
56         */
57
58         bbox.x0 = _center.x - _radius;
59         bbox.y0 = _center.y - _radius;
60         bbox.x1 = _center.x + _radius;
61         bbox.y1 = _center.y + _radius;
62
63         bbox = bbox.expand (0.5 + (_outline_width / 2));
64
65         _bounding_box = bbox;
66         _bounding_box_dirty = false;
67 }
68
69 void
70 Arc::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
71 {
72         if (_radius <= 0.0 || _arc_degrees <= 0.0) {
73                 return;
74         }
75
76         Duple c = item_to_window (Duple (_center.x, _center.y));
77
78         context->arc (c.x, c.y, _radius, _start_degrees * (M_PI/180.0), _arc_degrees * (M_PI/180.0));
79         setup_fill_context (context);
80         context->fill_preserve ();
81         setup_outline_context (context);
82         context->stroke ();
83 }
84
85 void
86 Arc::set_center (Duple const & c)
87 {
88         begin_change ();
89
90         _center = c;
91
92         _bounding_box_dirty = true;
93         end_change ();
94 }
95
96 void
97 Arc::set_radius (Coord r)
98 {
99         begin_change ();
100
101         _radius = r;
102
103         _bounding_box_dirty = true;
104         end_change ();
105 }
106
107 void
108 Arc::set_arc (double deg)
109 {
110         begin_change ();
111
112         _arc_degrees = deg;
113
114         _bounding_box_dirty = true;
115         end_change ();
116 }
117
118
119 void
120 Arc::set_start (double deg)
121 {
122         begin_change ();
123
124         _start_degrees = deg;
125
126         _bounding_box_dirty = true;
127         end_change ();
128 }
129
130 bool
131 Arc::covers (Duple const & point) const
132 {
133         Duple p = window_to_item (point);
134
135         double angle_degs = atan (p.y/p.x) * 2.0 * M_PI;
136         double radius = sqrt (p.x * p.x + p.y * p.y);
137
138         return (angle_degs >= _start_degrees) &&
139                 (angle_degs <= (_start_degrees + _arc_degrees)) &&
140                 (radius < _radius);
141 }