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