merge exportvis branch into cairocanvas, to reduce the number of "floating" branches.
[ardour.git] / gtk2_ardour / time_axis_view_item.h
1 /*
2     Copyright (C) 2003 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 #ifndef __gtk_ardour_time_axis_view_item_h__
21 #define __gtk_ardour_time_axis_view_item_h__
22
23 #include <string>
24 #include <gdk/gdk.h>
25 #include <gdkmm/color.h>
26 #include <pangomm/fontdescription.h>
27 #include "pbd/signals.h"
28 #include "selectable.h"
29
30 class TimeAxisView;
31
32 namespace ArdourCanvas {
33         class Pixbuf;
34         class Rectangle;
35         class Item;
36         class Group;
37         class Text;
38 }
39
40 using ARDOUR::framepos_t;
41 using ARDOUR::framecnt_t;
42
43 /**
44  * Base class for items that may appear upon a TimeAxisView.
45  */
46
47 class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList
48 {
49    public:
50         virtual ~TimeAxisViewItem();
51
52         virtual bool set_position(framepos_t, void*, double* delta = 0);
53         framepos_t get_position() const;
54         virtual bool set_duration(framecnt_t, void*);
55         framecnt_t get_duration() const;
56         virtual void set_max_duration(framecnt_t, void*);
57         framecnt_t get_max_duration() const;
58         virtual void set_min_duration(framecnt_t, void*);
59         framecnt_t get_min_duration() const;
60         virtual void set_position_locked(bool, void*);
61         bool get_position_locked() const;
62         void set_max_duration_active(bool, void*);
63         bool get_max_duration_active() const;
64         void set_min_duration_active(bool, void*);
65         bool get_min_duration_active() const;
66         void set_item_name(std::string, void*);
67         virtual std::string get_item_name() const;
68         virtual void set_selected(bool yn);
69         void set_sensitive (bool yn) { _sensitive = yn; }
70         bool sensitive () const { return _sensitive; }
71         TimeAxisView& get_time_axis_view () const;
72         void set_name_text(const std::string&);
73         virtual void set_height(double h);
74         void set_y (double);
75         void set_color (Gdk::Color const &);
76
77         uint32_t get_fill_color () const;
78
79         ArdourCanvas::Item* get_canvas_frame();
80         ArdourCanvas::Group* get_canvas_group();
81         ArdourCanvas::Item* get_name_highlight();
82
83         virtual void set_samples_per_pixel (double);
84
85         double get_samples_per_pixel () const;
86
87         virtual void drag_start() { _dragging = true; }
88         virtual void drag_end() { _dragging = false; }
89         bool dragging() const { return _dragging; }
90
91         virtual void raise () { return; }
92         virtual void raise_to_top () { return; }
93         virtual void lower () { return; }
94         virtual void lower_to_bottom () { return; }
95
96         virtual void hide_rect ();
97         virtual void show_rect ();
98
99         /** @return true if the name area should respond to events */
100         bool name_active() const { return name_connected; }
101
102         // Default sizes, font and spacing
103         static Pango::FontDescription NAME_FONT;
104         static void set_constant_heights ();
105         static const double NAME_X_OFFSET;
106         static const double GRAB_HANDLE_TOP;
107         static const double GRAB_HANDLE_WIDTH;
108
109         /* these are not constant, but vary with the pixel size
110            of the font used to display the item name.
111         */
112         static int    NAME_HEIGHT;
113         static double NAME_Y_OFFSET;
114         static double NAME_HIGHLIGHT_SIZE;
115         static double NAME_HIGHLIGHT_THRESH;
116
117         /**
118          * Emitted when this Group has been removed.
119          * This is different to the CatchDeletion signal in that this signal
120          * is emitted during the deletion of this Time Axis, and not during
121          * the destructor, this allows us to capture the source of the deletion
122          * event
123          */
124
125         sigc::signal<void,std::string,void*> ItemRemoved;
126
127         /** Emitted when the name of this item is changed */
128         sigc::signal<void,std::string,std::string,void*> NameChanged;
129
130         /** Emiited when the position of this item changes */
131         sigc::signal<void,framepos_t,void*> PositionChanged;
132
133         /** Emitted when the position lock of this item is changed */
134         sigc::signal<void,bool,void*> PositionLockChanged;
135
136         /** Emitted when the duration of this item changes */
137         sigc::signal<void,framecnt_t,void*> DurationChanged;
138
139         /** Emitted when the maximum item duration is changed */
140         sigc::signal<void,framecnt_t,void*> MaxDurationChanged;
141
142         /** Emitted when the mionimum item duration is changed */
143         sigc::signal<void,framecnt_t,void*> MinDurationChanged;
144
145         enum Visibility {
146                 ShowFrame = 0x1,
147                 ShowNameHighlight = 0x2,
148                 ShowNameText = 0x4,
149                 ShowHandles = 0x8,
150                 HideFrameLeft = 0x10,
151                 HideFrameRight = 0x20,
152                 HideFrameTB = 0x40,
153                 FullWidthNameHighlight = 0x80
154         };
155
156   protected:
157         TimeAxisViewItem(const std::string &, ArdourCanvas::Group&, TimeAxisView&, double, Gdk::Color const &,
158                          framepos_t, framecnt_t, bool recording = false, bool automation = false, Visibility v = Visibility (0));
159
160         TimeAxisViewItem (const TimeAxisViewItem&);
161
162         void init (ArdourCanvas::Group*, double, Gdk::Color const &, framepos_t, framepos_t, Visibility, bool, bool);
163
164         virtual bool canvas_group_event (GdkEvent*);
165
166         virtual void compute_colors (Gdk::Color const &);
167         virtual void set_colors();
168         virtual void set_frame_color();
169         virtual void set_frame_gradient ();
170         void set_trim_handle_colors();
171
172         virtual void reset_width_dependent_items (double);
173         void reset_name_width (double);
174         void update_name_text_visibility ();
175
176         static gint idle_remove_this_item(TimeAxisViewItem*, void*);
177
178         /** time axis that this item is on */
179         TimeAxisView& trackview;
180
181         /** indicates whether this item is locked to its current position */
182         bool position_locked;
183
184         /** position of this item on the timeline */
185         framepos_t frame_position;
186
187         /** duration of this item upon the timeline */
188         framecnt_t item_duration;
189
190         /** maximum duration that this item can have */
191         framecnt_t max_item_duration;
192
193         /** minimum duration that this item can have */
194         framecnt_t min_item_duration;
195
196         /** indicates whether the max duration constraint is active */
197         bool max_duration_active;
198
199         /** indicates whether the min duration constraint is active */
200         bool min_duration_active;
201
202         /** frames per canvas pixel */
203         double samples_per_pixel;
204
205         /** should the item respond to events */
206         bool _sensitive;
207
208         /**
209          * The unique item name of this Item.
210          * Each item upon a time axis must have a unique id.
211          */
212         std::string item_name;
213
214         /** true if the name should respond to events */
215         bool name_connected;
216
217         /** true if a small vestigial rect should be shown when the item gets very narrow */
218         bool show_vestigial;
219
220         uint32_t fill_opacity;
221         uint32_t fill_color;
222         uint32_t frame_color_r;
223         uint32_t frame_color_g;
224         uint32_t frame_color_b;
225         uint32_t selected_frame_color_r;
226         uint32_t selected_frame_color_g;
227         uint32_t selected_frame_color_b;
228         uint32_t label_color;
229
230         uint32_t handle_color_r;
231         uint32_t handle_color_g;
232         uint32_t handle_color_b;
233         uint32_t lock_handle_color_r;
234         uint32_t lock_handle_color_g;
235         uint32_t lock_handle_color_b;
236         uint32_t last_item_width;
237         int name_text_width;
238         bool wide_enough_for_name;
239         bool high_enough_for_name;
240         bool rect_visible;
241
242         ArdourCanvas::Group*      group;
243         ArdourCanvas::Rectangle* vestigial_frame;
244         ArdourCanvas::Rectangle* frame;
245         ArdourCanvas::Text*      name_text;
246         ArdourCanvas::Rectangle* name_highlight;
247
248         /* with these two values, if frame_handle_start == 0 then frame_handle_end will also be 0 */
249         ArdourCanvas::Rectangle* frame_handle_start; ///< `frame' (fade) handle for the start of the item, or 0
250         ArdourCanvas::Rectangle* frame_handle_end; ///< `frame' (fade) handle for the end of the item, or 0
251
252         bool frame_handle_crossing (GdkEvent*, ArdourCanvas::Rectangle*);
253
254         double _height;
255         Visibility visibility;
256         bool _recregion;
257         bool _automation; ///< true if this is an automation region view
258         bool _dragging;
259
260 private:
261
262         void parameter_changed (std::string);
263
264 }; /* class TimeAxisViewItem */
265
266 #endif /* __gtk_ardour_time_axis_view_item_h__ */