Gnime::Canvas::Points init fix
[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     $Id$
19 */
20
21 #ifndef __gtk_ardour_time_axis_view_item_h__
22 #define __gtk_ardour_time_axis_view_item_h__
23
24 #include <sigc++/signal.h>
25 #include <libgnomecanvas/libgnomecanvas.h>
26 #include <jack/jack.h>
27 #include <string>
28
29 #include "selectable.h"
30
31 class TimeAxisView;
32
33 /**
34  * A base class for 'items' that may appear upon a TimeAxisView
35  *
36  */
37 class TimeAxisViewItem : public sigc::trackable, public Selectable
38 {
39    public:
40        virtual ~TimeAxisViewItem() ;
41     
42     /**
43      * Set the position of this item upon the timeline to the specified value
44      *
45      * @param pos the new position
46      * @param src the identity of the object that initiated the change
47      * @return true if the position change was a success, false otherwise
48      */
49     virtual bool set_position(jack_nframes_t pos, void* src, double* delta = 0) ;
50     
51     /**
52      * Return the position of this item upon the timeline
53      *
54      * @return the position of this item
55      */
56     jack_nframes_t get_position() const ; 
57     
58     /**
59      * Sets the duration of this item
60      *
61      * @param dur the new duration of this item
62      * @param src the identity of the object that initiated the change
63      * @return true if the duration change was succesful, false otherwise
64      */
65     virtual bool set_duration(jack_nframes_t dur, void* src) ;
66     
67     /**
68      * Returns the duration of this item
69      *
70      */
71     jack_nframes_t get_duration() const ;
72     
73     /**
74      * Sets the maximum duration that this item make have.
75      *
76      * @param dur the new maximum duration
77      * @param src the identity of the object that initiated the change
78      */
79     virtual void set_max_duration(jack_nframes_t dur, void* src) ;
80     
81     /**
82      * Returns the maxmimum duration that this item may be set to
83      *
84      * @return the maximum duration that this item may be set to
85      */
86     jack_nframes_t get_max_duration() const ;
87     
88     /**
89      * Sets the minimu duration that this item may be set to
90      *
91      * @param the minimum duration that this item may be set to
92      * @param src the identity of the object that initiated the change
93      */
94     virtual void set_min_duration(jack_nframes_t dur, void* src) ;
95     
96     /**
97      * Returns the minimum duration that this item mey be set to
98      *
99      * @return the nimum duration that this item mey be set to
100      */
101     jack_nframes_t get_min_duration() const ;
102     
103     /**
104      * Sets whether the position of this Item is locked to its current position
105      * Locked items cannot be moved until the item is unlocked again.
106      *
107      * @param yn set to true to lock this item to its current position
108      * @param src the identity of the object that initiated the change
109      */
110     virtual void set_position_locked(bool yn, void* src) ;
111     
112     /**
113      * Returns whether this item is locked to its current position
114      *
115      * @return true if this item is locked to its current posotion
116      *         false otherwise
117      */
118     bool get_position_locked() const ;
119     
120     /**
121      * Sets whether the Maximum Duration constraint is active and should be enforced
122      *
123      * @param active set true to enforce the max duration constraint
124      * @param src the identity of the object that initiated the change
125      */
126     void set_max_duration_active(bool active, void* src) ;
127     
128     /**
129      * Returns whether the Maximum Duration constraint is active and should be enforced
130      *
131      * @return true if the maximum duration constraint is active, false otherwise
132      */
133     bool get_max_duration_active() const ;
134     
135     /**
136      * Sets whether the Minimum Duration constraint is active and should be enforced
137      *
138      * @param active set true to enforce the min duration constraint
139      * @param src the identity of the object that initiated the change
140      */
141     void set_min_duration_active(bool active, void* src) ;
142     
143     /**
144      * Returns whether the Maximum Duration constraint is active and should be enforced
145      *
146      * @return true if the maximum duration constraint is active, false otherwise
147      */
148     bool get_min_duration_active() const ;
149     
150     /**
151      * Set the name/Id of this item.
152      *
153      * @param new_name the new name of this item
154      * @param src the identity of the object that initiated the change
155      */
156     void set_item_name(std::string new_name, void* src) ;
157     
158     /**
159      * Returns the name/id of this item
160      *
161      * @return the name/id of this item
162      */
163     virtual std::string get_item_name() const ;
164     
165     /**
166      * Set to true to indicate that this item is currently selected
167      *
168      * @param yn true if this item is currently selected
169      * @param src the identity of the object that initiated the change
170      */
171     virtual void set_selected(bool yn, void* src) ;
172
173     /**
174      * Set to true to indicate that this item should show its selection status
175      *
176      * @param yn true if this item should show its selected status
177      */
178     virtual void set_should_show_selection (bool yn) ;
179     
180     /**
181      * Returns whether this item is currently selected.
182      *
183      * @return true if this item is currently selected, false otherwise
184      */
185     bool get_selected() const ; 
186     
187     //---------------------------------------------------------------------------------------//
188     // Parent Component Methods
189     
190     /**
191      * Returns the TimeAxisView that this item is upon
192      *
193      * @return the timeAxisView that this item is placed upon
194      */
195     TimeAxisView& get_time_axis_view() ;
196     
197     //---------------------------------------------------------------------------------------//
198     // ui methods & data
199     
200     /**
201      * Sets the displayed item text
202      * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
203      *
204      * @param new_name the new name text to display
205      */
206     void set_name_text(std::string new_name) ;
207     
208     /**
209      * Set the height of this item
210      *
211      * @param h the new height
212      */
213     virtual void set_height(double h) ;
214     
215     /**
216      * 
217      */
218     void set_color(Gdk::Color& color) ;
219     
220     /**
221      * 
222      */
223     GnomeCanvasItem* get_canvas_frame() ;
224
225     /**
226      * 
227      */
228     GnomeCanvasItem* get_canvas_group();
229
230     /**
231      * 
232      */
233     GnomeCanvasItem* get_name_highlight();
234
235     /**
236      * 
237      */
238     GnomeCanvasItem* get_name_text();
239
240     /**
241      * Sets the samples per unit of this item.
242      * this item is used to determine the relative visual size and position of this item
243      * based upon its duration and start value.
244      *
245      * @param spu the new samples per unit value
246      */
247     virtual void set_samples_per_unit(double spu) ;
248     
249     /**
250      * Returns the current samples per unit of this item
251      *
252      * @return the samples per unit of this item
253      */
254     double get_samples_per_unit() ;
255
256     virtual void raise () { return; }
257     virtual void raise_to_top () { return; }
258     virtual void lower () { return; }
259     virtual void lower_to_bottom () { return; }
260     
261     /**
262      * returns true if the name area should respond to events.
263      */
264     bool name_active() const { return name_connected; }
265
266     // Default sizes, font and spacing
267     static Pango::FontDescription NAME_FONT ;
268     static bool have_name_font;
269     static const double NAME_X_OFFSET ;
270     static const double NAME_Y_OFFSET ;
271     static const double NAME_HIGHLIGHT_SIZE ;
272     static const double NAME_HIGHLIGHT_THRESH ;
273     static const double GRAB_HANDLE_LENGTH ;
274
275     /**
276      * Handles the Removal of this time axis item
277      * This _needs_ to be called to alert others of the removal properly, ie where the source
278      * of the removal came from.
279      *
280      * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
281      *     just now to capture the source of the removal
282      *
283      * @param src the identity of the object that initiated the change
284      */
285     virtual void remove_this_item(void* src) ;
286     
287     /**
288      * Emitted when this Group has been removed
289      * This is different to the GoingAway signal in that this signal
290      * is emitted during the deletion of this Time Axis, and not during
291      * the destructor, this allows us to capture the source of the deletion
292      * event
293      */
294     sigc::signal<void,std::string,void*> ItemRemoved ;
295     
296     /** Emitted when the name/Id of this item is changed */
297     sigc::signal<void,std::string,std::string,void*> NameChanged ;
298     
299     /** Emiited when the position of this item changes */
300     sigc::signal<void,jack_nframes_t,void*> PositionChanged ;
301     
302     /** Emitted when the position lock of this item is changed */
303     sigc::signal<void,bool,void*> PositionLockChanged ;
304     
305     /** Emitted when the duration of this item changes */
306     sigc::signal<void,jack_nframes_t,void*> DurationChanged ;
307     
308     /** Emitted when the maximum item duration is changed */
309     sigc::signal<void,jack_nframes_t,void*> MaxDurationChanged ;
310     
311     /** Emitted when the mionimum item duration is changed */
312     sigc::signal<void,jack_nframes_t,void*> MinDurationChanged ;
313     
314     /** Emitted when the selected status of this item changes */
315     sigc::signal<void, bool> Selected ;
316     
317
318   protected:
319     
320     enum Visibility {
321             ShowFrame = 0x1,
322             ShowNameHighlight = 0x2,
323             ShowNameText = 0x4,
324             ShowHandles = 0x8
325     };
326
327     /**
328      * Constructs a new TimeAxisViewItem.
329      *
330      * @param it_name the unique name/Id of this item
331      * @param parent the parent canvas group
332      * @param tv the TimeAxisView we are going to be added to
333      * @param spu samples per unit
334      * @param base_color
335      * @param start the start point of this item
336      * @param duration the duration of this item
337      */
338     TimeAxisViewItem(std::string it_name, GnomeCanvasGroup* parent, TimeAxisView& tv, double spu, Gdk::Color& base_color, 
339                      jack_nframes_t start, jack_nframes_t duration, Visibility v = Visibility (0));
340     
341     /**
342      * Calculates some contrasting color for displaying various parts of this item, based upon the base color
343      *
344      * @param color the base color of the item
345      */
346     virtual void compute_colors(Gdk::Color& color) ;
347     
348     /**
349      * convenience method to set the various canvas item colors
350      */
351     virtual void set_colors() ;
352     
353     /**
354      * Sets the frame color depending on whether this item is selected
355      */
356     void set_frame_color() ;
357     
358     /**
359      * Sets the colors of the start and end trim handle depending on object state
360      *
361      */
362     void set_trim_handle_colors() ;
363
364     virtual void reset_width_dependent_items (double pixel_width);
365     void reset_name_width (double pixel_width);
366
367     /**
368      * Callback used to remove this item during the gtk idle loop
369      * This is used to avoid deleting the obejct while inside the remove_this_group
370      * method
371      *
372      * @param item the time axis item to remove
373      * @param src the identity of the object that initiated the change
374      */
375     static gint idle_remove_this_item(TimeAxisViewItem* item, void* src) ;
376     
377     /** The time axis that this item is upon */
378     TimeAxisView& trackview ;
379     
380     /** indicates whether this item is locked to its current position */
381     bool position_locked ;
382     
383     /** The posotion of this item on the timeline */
384     jack_nframes_t frame_position ;
385     
386     /** the duration of this item upon the timeline */
387     jack_nframes_t item_duration ;
388     
389     /** the maximum duration that we allow this item to take */
390     jack_nframes_t max_item_duration ;
391     
392     /** the minimu duration that we allow this item to take */
393     jack_nframes_t min_item_duration ;
394     
395     /** indicates whether this Max Duration constraint is active */
396     bool max_duration_active ;
397     
398     /** indicates whether this Min Duration constraint is active */
399     bool min_duration_active ;
400     
401     /** the curretn samples per canvas unit */
402     double samples_per_unit ;
403     
404     /** indicates if this item is currently selected */
405     bool selected ;
406
407     /** should the item show its selected status */
408     bool should_show_selection;
409     
410     /**
411      * The unique item name of this Item
412      * Each item upon a time axis must have a unique id
413      */
414     std::string item_name ;
415     
416     /**
417      * true if the name should respond to events
418      */
419     bool name_connected;
420
421     /**
422      * true if a small vestigial rect should be shown when the item gets very narrow
423      */
424
425     bool show_vestigial;
426
427     uint32_t fill_opacity;
428     uint32_t fill_color ;
429     uint32_t frame_color_r ;
430     uint32_t frame_color_g ;
431     uint32_t frame_color_b ;
432     uint32_t selected_frame_color_r ;
433     uint32_t selected_frame_color_g ;
434     uint32_t selected_frame_color_b ;
435     uint32_t label_color ;
436     
437     uint32_t handle_color_r ;
438     uint32_t handle_color_g ;
439     uint32_t handle_color_b ;
440     uint32_t lock_handle_color_r ;
441     uint32_t lock_handle_color_g ;
442     uint32_t lock_handle_color_b ;
443     
444     GnomeCanvasItem* group ;               /* the group */
445     GnomeCanvasItem* vestigial_frame ;     /* simplerect */
446     GnomeCanvasItem* frame ;               /* simplerect */
447     GnomeCanvasItem* name_text ;           /* text */
448     GnomeCanvasItem* name_highlight ;      /* simplerect */
449     GnomeCanvasItem* frame_handle_start ;  /* simplerect */
450     GnomeCanvasItem* frame_handle_end ;    /* simplerect */
451
452 }; /* class TimeAxisViewItem */
453
454 #endif /* __gtk_ardour_time_axis_view_item_h__ */