7a34d7e590eb5ee176b1520e41515f6644e4d077
[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
25 #include <libgnomecanvasmm/pixbuf.h>
26
27 #include "pbd/signals.h"
28
29 #include "selectable.h"
30 #include "simplerect.h"
31 #include "canvas.h"
32
33 class TimeAxisView;
34
35 /**
36  * Base class for items that may appear upon a TimeAxisView.
37  */
38
39 class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList
40 {
41    public:
42         virtual ~TimeAxisViewItem();
43
44         virtual bool set_position(nframes64_t, void*, double* delta = 0);
45         nframes64_t get_position() const;
46         virtual bool set_duration(nframes64_t, void*);
47         nframes64_t get_duration() const;
48         virtual void set_max_duration(nframes64_t, void*);
49         nframes64_t get_max_duration() const;
50         virtual void set_min_duration(nframes64_t, void*);
51         nframes64_t get_min_duration() const;
52         virtual void set_position_locked(bool, void*);
53         bool get_position_locked() const;
54         void set_max_duration_active(bool, void*);
55         bool get_max_duration_active() const;
56         void set_min_duration_active(bool, void*);
57         bool get_min_duration_active() const;
58         void set_item_name(std::string, void*);
59         virtual std::string get_item_name() const;
60         virtual void set_selected(bool yn);
61         virtual void set_should_show_selection (bool yn);
62         void set_sensitive (bool yn) { _sensitive = yn; }
63         bool sensitive () const { return _sensitive; }
64         TimeAxisView& get_time_axis_view();
65         void set_name_text(const Glib::ustring&);
66         virtual void set_height(double h);
67         void set_y (double);
68         void set_color (Gdk::Color const &);
69         
70         ArdourCanvas::Item* get_canvas_frame();
71         ArdourCanvas::Group* get_canvas_group();
72         ArdourCanvas::Item* get_name_highlight();
73         ArdourCanvas::Pixbuf* get_name_pixbuf();
74
75         TimeAxisView& get_trackview() const { return trackview; }
76
77         virtual void set_samples_per_unit(double spu);
78
79         double get_samples_per_unit();
80
81         virtual void raise () { return; }
82         virtual void raise_to_top () { return; }
83         virtual void lower () { return; }
84         virtual void lower_to_bottom () { return; }
85         
86         /** @return true if the name area should respond to events */
87         bool name_active() const { return name_connected; }
88
89         // Default sizes, font and spacing
90         static Pango::FontDescription* NAME_FONT;
91         static void set_constant_heights ();
92         static const double NAME_X_OFFSET;
93         static const double GRAB_HANDLE_LENGTH;
94         
95         /* these are not constant, but vary with the pixel size
96            of the font used to display the item name.
97         */
98         static int    NAME_HEIGHT;
99         static double NAME_Y_OFFSET;
100         static double NAME_HIGHLIGHT_SIZE;
101         static double NAME_HIGHLIGHT_THRESH;
102
103         /**
104          * Emitted when this Group has been removed.
105          * This is different to the CatchDeletion signal in that this signal
106          * is emitted during the deletion of this Time Axis, and not during
107          * the destructor, this allows us to capture the source of the deletion
108          * event
109          */
110
111         sigc::signal<void,std::string,void*> ItemRemoved;
112
113         /** Emitted when the name of this item is changed */
114         sigc::signal<void,std::string,std::string,void*> NameChanged;
115         
116         /** Emiited when the position of this item changes */
117         sigc::signal<void,nframes64_t,void*> PositionChanged;
118         
119         /** Emitted when the position lock of this item is changed */
120         sigc::signal<void,bool,void*> PositionLockChanged;
121         
122         /** Emitted when the duration of this item changes */
123         sigc::signal<void,nframes64_t,void*> DurationChanged;
124         
125         /** Emitted when the maximum item duration is changed */
126         sigc::signal<void,nframes64_t,void*> MaxDurationChanged;
127         
128         /** Emitted when the mionimum item duration is changed */
129         sigc::signal<void,nframes64_t,void*> MinDurationChanged;
130         
131         enum Visibility {
132                 ShowFrame = 0x1,
133                 ShowNameHighlight = 0x2,
134                 ShowNameText = 0x4,
135                 ShowHandles = 0x8,
136                 HideFrameLeft = 0x10,
137                 HideFrameRight = 0x20,
138                 HideFrameTB = 0x40,
139                 FullWidthNameHighlight = 0x80
140         };
141         
142 protected:
143         TimeAxisViewItem(const std::string &, ArdourCanvas::Group&, TimeAxisView&, double, Gdk::Color const &,
144                          nframes64_t, nframes64_t, bool recording = false, Visibility v = Visibility (0));
145         
146         TimeAxisViewItem (const TimeAxisViewItem&);
147         
148         void init (const std::string&, double, Gdk::Color const &, nframes64_t, nframes64_t, Visibility, bool, bool);
149
150         virtual void compute_colors (Gdk::Color const &);
151         virtual void set_colors();
152         virtual void set_frame_color();
153         void set_trim_handle_colors();
154
155         virtual void reset_width_dependent_items (double);
156         void reset_name_width (double);
157         void update_name_pixbuf_visibility ();
158         
159         static gint idle_remove_this_item(TimeAxisViewItem*, void*);
160         
161         /** time axis that this item is on */
162         TimeAxisView& trackview;
163         
164         /** indicates whether this item is locked to its current position */
165         bool position_locked;
166         
167         /** position of this item on the timeline */
168         nframes64_t frame_position;
169
170         /** duration of this item upon the timeline */
171         nframes64_t item_duration;
172         
173         /** maximum duration that this item can have */
174         nframes64_t max_item_duration;
175         
176         /** minimum duration that this item can have */
177         nframes64_t min_item_duration;
178         
179         /** indicates whether the max duration constraint is active */
180         bool max_duration_active;
181         
182         /** indicates whether the min duration constraint is active */
183         bool min_duration_active;
184         
185         /** samples per canvas unit */
186         double samples_per_unit;
187
188         /** should the item show its selected status */
189         bool should_show_selection;
190         
191         /** should the item respond to events */
192         bool _sensitive;
193         
194         /**
195          * The unique item name of this Item.
196          * Each item upon a time axis must have a unique id.
197          */
198         std::string item_name;
199
200         /** true if the name should respond to events */
201         bool name_connected;
202
203         /** true if a small vestigial rect should be shown when the item gets very narrow */
204         bool show_vestigial;
205
206         uint32_t fill_opacity;
207         uint32_t fill_color;
208         uint32_t frame_color_r;
209         uint32_t frame_color_g;
210         uint32_t frame_color_b;
211         uint32_t selected_frame_color_r;
212         uint32_t selected_frame_color_g;
213         uint32_t selected_frame_color_b;
214         uint32_t label_color;
215         
216         uint32_t handle_color_r;
217         uint32_t handle_color_g;
218         uint32_t handle_color_b;
219         uint32_t lock_handle_color_r;
220         uint32_t lock_handle_color_g;
221         uint32_t lock_handle_color_b;
222         uint32_t last_item_width;
223         int name_pixbuf_width;
224         bool wide_enough_for_name;
225         bool high_enough_for_name;
226         
227         ArdourCanvas::Group*      group;
228         ArdourCanvas::SimpleRect* vestigial_frame;
229         ArdourCanvas::SimpleRect* frame;
230         ArdourCanvas::Pixbuf*     name_pixbuf;
231         ArdourCanvas::SimpleRect* name_highlight;
232         ArdourCanvas::SimpleRect* frame_handle_start;
233         ArdourCanvas::SimpleRect* frame_handle_end;
234         
235         double _height;
236         Visibility visibility;
237         bool _recregion;
238         
239 }; /* class TimeAxisViewItem */
240
241 #endif /* __gtk_ardour_time_axis_view_item_h__ */