ardour
control_point.cc
Go to the documentation of this file.
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 "automation_line.h"
22 #include "ardour_ui.h"
23 #include "public_editor.h"
24 
25 #include "canvas/rectangle.h"
26 
27 #include "i18n.h"
28 
29 using namespace std;
30 using namespace ARDOUR;
31 using namespace PBD;
32 
33 PBD::Signal1<void, ControlPoint *> ControlPoint::CatchDeletion;
34 
36  : _line (al)
37 {
38  _model = al.the_list()->end();
39  _view_index = 0;
40  _can_slide = true;
41  _x = 0;
42  _y = 0;
43  _shape = Full;
44  _size = 4.0;
45 
46  _item = new ArdourCanvas::Rectangle (&_line.canvas_group());
47  _item->set_fill (true);
48  _item->set_fill_color (ARDOUR_UI::config()->color ("control point fill"));
49  _item->set_outline_color (ARDOUR_UI::config()->color ("control point outline"));
50  _item->set_data ("control_point", this);
51  _item->Event.connect (sigc::mem_fun (this, &ControlPoint::event_handler));
52 
53  hide ();
54 }
55 
56 ControlPoint::ControlPoint (const ControlPoint& other, bool /*dummy_arg_to_force_special_copy_constructor*/)
57  : _line (other._line)
58 {
59  if (&other == this) {
60  return;
61  }
62 
63  _model = other._model;
64  _view_index = other._view_index;
65  _can_slide = other._can_slide;
66  _x = other._x;
67  _y = other._y;
68  _shape = other._shape;
69  _size = other._size;
70 
71  _item = new ArdourCanvas::Rectangle (&_line.canvas_group());
72  _item->set_fill (true);
73  _item->set_outline_color (ARDOUR_UI::config()->color ("control point outline"));
74 
75  /* NOTE: no event handling in copied ControlPoints */
76 
77  hide ();
78 }
79 
81 {
82  CatchDeletion (this); /* EMIT SIGNAL */
83 
84  delete _item;
85 }
86 
87 bool
88 ControlPoint::event_handler (GdkEvent* event)
89 {
91 }
92 
93 void
95 {
96  _item->hide();
97 }
98 
99 void
101 {
102  _item->show();
103 }
104 
105 bool
107 {
108  return _item->visible ();
109 }
110 
111 void
112 ControlPoint::reset (double x, double y, AutomationList::iterator mi, uint32_t vi, ShapeType shape)
113 {
114  _model = mi;
115  _view_index = vi;
116  move_to (x, y, shape);
117 }
118 
119 void
121 {
122  if (_selected) {
123  _item->set_outline_color(ARDOUR_UI::config()->color ("control point selected outline"));;
124  _item->set_fill_color(ARDOUR_UI::config()->color ("control point selected fill"));
125  } else {
126  _item->set_outline_color(ARDOUR_UI::config()->color ("control point outline"));
127  _item->set_fill_color(ARDOUR_UI::config()->color ("control point fill"));
128  }
129 }
130 
131 void
133 {
134  _size = sz;
135  move_to (_x, _y, _shape);
136 }
137 
138 void
139 ControlPoint::move_to (double x, double y, ShapeType shape)
140 {
141  double x1 = 0;
142  double x2 = 0;
143  double half_size = rint(_size/2.0);
144 
145  switch (shape) {
146  case Full:
147  x1 = x - half_size;
148  x2 = x + half_size;
149  break;
150  case Start:
151  x1 = x;
152  x2 = x + half_size;
153  break;
154  case End:
155  x1 = x - half_size;
156  x2 = x;
157  break;
158  }
159 
160  _item->set (ArdourCanvas::Rect (x1, y - half_size, x2, y + half_size));
161 
162  _x = x;
163  _y = y;
164  _shape = shape;
165 }
166 
167 ArdourCanvas::Item&
169 {
170  return *_item;
171 }
ArdourCanvas::Container & canvas_group() const
uint32_t _view_index
Definition: control_point.h:89
boost::shared_ptr< ARDOUR::AutomationList > the_list() const
void reset(double x, double y, ARDOUR::AutomationList::iterator, uint32_t, ShapeType)
Definition: Beats.hpp:239
void move_to(double x, double y, ShapeType)
bool visible() const
static PBD::Signal1< void, ControlPoint * > CatchDeletion
Definition: control_point.h:83
virtual bool canvas_control_point_event(GdkEvent *event, ArdourCanvas::Item *, ControlPoint *)=0
ControlPoint(AutomationLine &al)
ArdourCanvas::Item & item() const
Definition: amp.h:29
virtual bool event_handler(GdkEvent *)
AutomationLine & _line
Definition: control_point.h:87
void set_size(double)
ARDOUR::AutomationList::iterator _model
Definition: control_point.h:88
virtual ~ControlPoint()
bool _selected
Definition: selectable.h:45
ShapeType _shape
Definition: control_point.h:94
static PublicEditor & instance()
static UIConfiguration * config()
Definition: ardour_ui.h:188
ArdourCanvas::Rectangle * _item
Definition: control_point.h:86
Definition: debug.h:30
LIBARDOUR_API PBD::PropertyDescriptor< bool > color
Definition: route_group.cc:50