Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / gtk2_ardour / control_point.cc
1 /*
2     Copyright (C) 2002-2007 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
20 #include "control_point.h"
21 #include "diamond.h"
22 #include "automation_line.h"
23 #include "ardour_ui.h"
24 #include "public_editor.h"
25
26 #include "i18n.h"
27
28 using namespace std;
29 using namespace sigc;
30 using namespace ARDOUR;
31 using namespace PBD;
32 using namespace Gnome; // for Canvas
33
34 ControlPoint::ControlPoint (AutomationLine& al)
35         : _line (al)
36 {
37         _model = al.the_list()->end();
38         _view_index = 0;
39         _can_slide = true;
40         _x = 0;
41         _y = 0;
42         _shape = Full;
43         _size = 4.0;
44         _selected = false;
45
46         _item = new Canvas::SimpleRect (_line.canvas_group());
47         _item->property_draw() = true;
48         _item->property_fill() = false;
49         _item->property_fill_color_rgba() =  ARDOUR_UI::config()->canvasvar_ControlPointFill.get();
50         _item->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ControlPointOutline.get();
51         _item->property_outline_pixels() = 1;
52         _item->set_data ("control_point", this);
53         _item->signal_event().connect (mem_fun (this, &ControlPoint::event_handler));
54
55         hide ();
56         set_visible (false);
57 }
58
59 ControlPoint::ControlPoint (const ControlPoint& other, bool /*dummy_arg_to_force_special_copy_constructor*/)
60         : _line (other._line)
61 {
62         if (&other == this) {
63                 return;
64         }
65
66         _model = other._model;
67         _view_index = other._view_index;
68         _can_slide = other._can_slide;
69         _x = other._x;
70         _y = other._y;
71         _shape = other._shape;
72         _size = other._size;
73         _selected = false;
74
75         _item = new Canvas::SimpleRect (_line.canvas_group());
76         _item->property_fill() = false;
77         _item->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ControlPointOutline.get();
78         _item->property_outline_pixels() = 1;
79
80         /* NOTE: no event handling in copied ControlPoints */
81
82         hide ();
83         set_visible (false);
84 }
85
86 ControlPoint::~ControlPoint ()
87 {
88         delete _item;
89 }
90
91 bool
92 ControlPoint::event_handler (GdkEvent* event)
93 {
94         return PublicEditor::instance().canvas_control_point_event (event, _item, this);
95 }
96
97 void
98 ControlPoint::hide ()
99 {
100         _item->hide();
101 }
102
103 void
104 ControlPoint::show()
105 {
106         _item->show();
107 }
108
109 void
110 ControlPoint::set_visible (bool yn)
111 {
112         _item->property_draw() = (gboolean) yn;
113 }
114
115 void
116 ControlPoint::reset (double x, double y, AutomationList::iterator mi, uint32_t vi, ShapeType shape)
117 {
118         _model = mi;
119         _view_index = vi;
120         move_to (x, y, shape);
121 }
122
123 void
124 ControlPoint::show_color (bool entered, bool hide_too)
125 {
126         uint32_t color = 0;
127
128         if (entered) {
129                 if (_selected) {
130                         color = ARDOUR_UI::config()->canvasvar_EnteredControlPointSelected.get();
131                         set_visible(true);
132                 } else {
133                         color = ARDOUR_UI::config()->canvasvar_EnteredControlPointOutline.get();
134                         if (hide_too) {
135                                 set_visible(false);
136                         }
137                 }
138
139         } else {
140                 if (_selected) {
141                         color = ARDOUR_UI::config()->canvasvar_ControlPointSelected.get();
142                         set_visible(true);
143                 } else {
144                         color = ARDOUR_UI::config()->canvasvar_ControlPointOutline.get();
145                         if (hide_too) {
146                                 set_visible(false);
147                         }
148                 }
149         }
150
151         _item->property_outline_color_rgba() = color;
152         _item->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ControlPointFill.get();
153 }
154
155 void
156 ControlPoint::set_size (double sz)
157 {
158         _size = sz;
159
160 #if 0
161         if (_size > 6.0) {
162                 item->property_fill() = (gboolean) TRUE;
163         } else {
164                 item->property_fill() = (gboolean) FALSE;
165         }
166 #endif
167
168         move_to (_x, _y, _shape);
169 }
170
171 void
172 ControlPoint::move_to (double x, double y, ShapeType shape)
173 {
174         double x1 = 0;
175         double x2 = 0;
176         double half_size = rint(_size/2.0);
177
178         switch (shape) {
179         case Full:
180                 x1 = x - half_size;
181                 x2 = x + half_size;
182                 break;
183         case Start:
184                 x1 = x;
185                 x2 = x + half_size;
186                 break;
187         case End:
188                 x1 = x - half_size;
189                 x2 = x;
190                 break;
191         }
192
193         _item->property_x1() = x1;
194         _item->property_x2() = x2;
195         _item->property_y1() = y - half_size;
196         _item->property_y2() = y + half_size;
197
198         _x = x;
199         _y = y;
200         _shape = shape;
201 }
202