2 Copyright (C) 2003 Paul Davis
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.
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.
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.
20 #ifndef __gtk_ardour_time_axis_view_item_h__
21 #define __gtk_ardour_time_axis_view_item_h__
23 #include <jack/jack.h>
26 #include <libgnomecanvasmm/pixbuf.h>
28 #include "selectable.h"
29 #include "simplerect.h"
35 * A base class for 'items' that may appear upon a TimeAxisView
38 class TimeAxisViewItem
: public Selectable
41 virtual ~TimeAxisViewItem() ;
44 * Set the position of this item upon the timeline to the specified value
46 * @param pos the new position
47 * @param src the identity of the object that initiated the change
48 * @return true if the position change was a success, false otherwise
50 virtual bool set_position(nframes_t pos
, void* src
, double* delta
= 0) ;
53 * Return the position of this item upon the timeline
55 * @return the position of this item
57 nframes_t
get_position() const ;
60 * Sets the duration of this item
62 * @param dur the new duration of this item
63 * @param src the identity of the object that initiated the change
64 * @return true if the duration change was succesful, false otherwise
66 virtual bool set_duration(nframes_t dur
, void* src
) ;
69 * Returns the duration of this item
72 nframes_t
get_duration() const ;
75 * Sets the maximum duration that this item make have.
77 * @param dur the new maximum duration
78 * @param src the identity of the object that initiated the change
80 virtual void set_max_duration(nframes_t dur
, void* src
) ;
83 * Returns the maxmimum duration that this item may be set to
85 * @return the maximum duration that this item may be set to
87 nframes_t
get_max_duration() const ;
90 * Sets the minimu duration that this item may be set to
92 * @param the minimum duration that this item may be set to
93 * @param src the identity of the object that initiated the change
95 virtual void set_min_duration(nframes_t dur
, void* src
) ;
98 * Returns the minimum duration that this item mey be set to
100 * @return the nimum duration that this item mey be set to
102 nframes_t
get_min_duration() const ;
105 * Sets whether the position of this Item is locked to its current position
106 * Locked items cannot be moved until the item is unlocked again.
108 * @param yn set to true to lock this item to its current position
109 * @param src the identity of the object that initiated the change
111 virtual void set_position_locked(bool yn
, void* src
) ;
114 * Returns whether this item is locked to its current position
116 * @return true if this item is locked to its current posotion
119 bool get_position_locked() const ;
122 * Sets whether the Maximum Duration constraint is active and should be enforced
124 * @param active set true to enforce the max duration constraint
125 * @param src the identity of the object that initiated the change
127 void set_max_duration_active(bool active
, void* src
) ;
130 * Returns whether the Maximum Duration constraint is active and should be enforced
132 * @return true if the maximum duration constraint is active, false otherwise
134 bool get_max_duration_active() const ;
137 * Sets whether the Minimum Duration constraint is active and should be enforced
139 * @param active set true to enforce the min duration constraint
140 * @param src the identity of the object that initiated the change
142 void set_min_duration_active(bool active
, void* src
) ;
145 * Returns whether the Maximum Duration constraint is active and should be enforced
147 * @return true if the maximum duration constraint is active, false otherwise
149 bool get_min_duration_active() const ;
152 * Set the name/Id of this item.
154 * @param new_name the new name of this item
155 * @param src the identity of the object that initiated the change
157 void set_item_name(std::string new_name
, void* src
) ;
160 * Returns the name/id of this item
162 * @return the name/id of this item
164 virtual std::string
get_item_name() const ;
167 * Set to true to indicate that this item is currently selected
169 * @param yn true if this item is currently selected
171 virtual void set_selected(bool yn
) ;
174 * Set to true to indicate that this item should show its selection status
176 * @param yn true if this item should show its selected status
178 virtual void set_should_show_selection (bool yn
) ;
180 void set_sensitive (bool yn
) { _sensitive
= yn
; }
181 bool sensitive () const { return _sensitive
; }
183 //---------------------------------------------------------------------------------------//
184 // Parent Component Methods
187 * Returns the TimeAxisView that this item is upon
189 * @return the timeAxisView that this item is placed upon
191 TimeAxisView
& get_time_axis_view() ;
193 //---------------------------------------------------------------------------------------//
197 * Sets the displayed item text
198 * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
200 * @param new_name the new name text to display
202 void set_name_text(const Glib::ustring
& new_name
) ;
205 * Set the height of this item
207 * @param h the new height
209 virtual void set_height(double h
) ;
214 void set_color(Gdk::Color
& color
) ;
219 ArdourCanvas::Item
* get_canvas_frame() ;
224 ArdourCanvas::Group
* get_canvas_group();
229 ArdourCanvas::Item
* get_name_highlight();
234 ArdourCanvas::Pixbuf
* get_name_pixbuf();
238 * Returns the time axis that this item is upon
240 TimeAxisView
& get_trackview() const { return trackview
; }
243 * Sets the samples per unit of this item.
244 * this item is used to determine the relative visual size and position of this item
245 * based upon its duration and start value.
247 * @param spu the new samples per unit value
249 virtual void set_samples_per_unit(double spu
) ;
252 * Returns the current samples per unit of this item
254 * @return the samples per unit of this item
256 double get_samples_per_unit() ;
258 virtual void raise () { return; }
259 virtual void raise_to_top () { return; }
260 virtual void lower () { return; }
261 virtual void lower_to_bottom () { return; }
264 * returns true if the name area should respond to events.
266 bool name_active() const { return name_connected
; }
268 // Default sizes, font and spacing
269 static Pango::FontDescription
* NAME_FONT
;
270 static bool have_name_font
;
271 static const double NAME_X_OFFSET
;
272 static const double GRAB_HANDLE_LENGTH
;
273 /* these are not constant, but vary with the pixel size
274 of the font used to display the item name.
276 static int NAME_HEIGHT
;
277 static double NAME_Y_OFFSET
;
278 static double NAME_HIGHLIGHT_SIZE
;
279 static double NAME_HIGHLIGHT_THRESH
;
282 * Handles the Removal of this time axis item
283 * This _needs_ to be called to alert others of the removal properly, ie where the source
284 * of the removal came from.
286 * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
287 * just now to capture the source of the removal
289 * @param src the identity of the object that initiated the change
291 virtual void remove_this_item(void* src
) ;
294 * Emitted when this Group has been removed
295 * This is different to the GoingAway signal in that this signal
296 * is emitted during the deletion of this Time Axis, and not during
297 * the destructor, this allows us to capture the source of the deletion
301 sigc::signal
<void,std::string
,void*> ItemRemoved
;
303 /** Emitted when the name/Id of this item is changed */
304 sigc::signal
<void,std::string
,std::string
,void*> NameChanged
;
306 /** Emiited when the position of this item changes */
307 sigc::signal
<void,nframes_t
,void*> PositionChanged
;
309 /** Emitted when the position lock of this item is changed */
310 sigc::signal
<void,bool,void*> PositionLockChanged
;
312 /** Emitted when the duration of this item changes */
313 sigc::signal
<void,nframes_t
,void*> DurationChanged
;
315 /** Emitted when the maximum item duration is changed */
316 sigc::signal
<void,nframes_t
,void*> MaxDurationChanged
;
318 /** Emitted when the mionimum item duration is changed */
319 sigc::signal
<void,nframes_t
,void*> MinDurationChanged
;
323 ShowNameHighlight
= 0x2,
326 HideFrameLeft
= 0x10,
327 HideFrameRight
= 0x20,
329 FullWidthNameHighlight
= 0x80
333 * Constructs a new TimeAxisViewItem.
335 * @param it_name the unique name/Id of this item
336 * @param parent the parent canvas group
337 * @param tv the TimeAxisView we are going to be added to
338 * @param spu samples per unit
340 * @param start the start point of this item
341 * @param duration the duration of this item
343 TimeAxisViewItem(const std::string
& it_name
, ArdourCanvas::Group
& parent
, TimeAxisView
& tv
, double spu
, Gdk::Color
& base_color
,
344 nframes_t start
, nframes_t duration
, bool recording
= false, Visibility v
= Visibility (0));
346 TimeAxisViewItem (const TimeAxisViewItem
& other
);
348 void init (const std::string
& it_name
, double spu
, Gdk::Color
& base_color
, nframes_t start
, nframes_t duration
, Visibility vis
);
351 * Calculates some contrasting color for displaying various parts of this item, based upon the base color
353 * @param color the base color of the item
355 virtual void compute_colors(Gdk::Color
& color
) ;
358 * convenience method to set the various canvas item colors
360 virtual void set_colors() ;
363 * Sets the frame color depending on whether this item is selected
365 virtual void set_frame_color() ;
368 * Sets the colors of the start and end trim handle depending on object state
371 void set_trim_handle_colors() ;
373 virtual void reset_width_dependent_items (double pixel_width
);
374 void reset_name_width (double pixel_width
);
377 * Callback used to remove this item during the gtk idle loop
378 * This is used to avoid deleting the obejct while inside the remove_this_group
381 * @param item the time axis item to remove
382 * @param src the identity of the object that initiated the change
384 static gint
idle_remove_this_item(TimeAxisViewItem
* item
, void* src
) ;
386 /** The time axis that this item is upon */
387 TimeAxisView
& trackview
;
389 /** indicates whether this item is locked to its current position */
390 bool position_locked
;
392 /** The posotion of this item on the timeline */
393 nframes_t frame_position
;
395 /** the duration of this item upon the timeline */
396 nframes_t item_duration
;
398 /** the maximum duration that we allow this item to take */
399 nframes_t max_item_duration
;
401 /** the minimu duration that we allow this item to take */
402 nframes_t min_item_duration
;
404 /** indicates whether this Max Duration constraint is active */
405 bool max_duration_active
;
407 /** indicates whether this Min Duration constraint is active */
408 bool min_duration_active
;
410 /** the curretn samples per canvas unit */
411 double samples_per_unit
;
413 /** indicates if this item is currently selected */
416 /** should the item show its selected status */
417 bool should_show_selection
;
419 /** should the item respond to events */
423 * The unique item name of this Item
424 * Each item upon a time axis must have a unique id
426 std::string item_name
;
429 * true if the name should respond to events
434 * true if a small vestigial rect should be shown when the item gets very narrow
438 uint32_t fill_opacity
;
439 uint32_t fill_color
;
440 uint32_t frame_color_r
;
441 uint32_t frame_color_g
;
442 uint32_t frame_color_b
;
443 uint32_t selected_frame_color_r
;
444 uint32_t selected_frame_color_g
;
445 uint32_t selected_frame_color_b
;
446 uint32_t label_color
;
448 uint32_t handle_color_r
;
449 uint32_t handle_color_g
;
450 uint32_t handle_color_b
;
451 uint32_t lock_handle_color_r
;
452 uint32_t lock_handle_color_g
;
453 uint32_t lock_handle_color_b
;
454 uint32_t last_item_width
;
455 int name_pixbuf_width
;
457 ArdourCanvas::Group
* group
;
458 ArdourCanvas::SimpleRect
* vestigial_frame
;
459 ArdourCanvas::SimpleRect
* frame
;
460 ArdourCanvas::Pixbuf
* name_pixbuf
;
461 ArdourCanvas::SimpleRect
* name_highlight
;
462 ArdourCanvas::SimpleRect
* frame_handle_start
;
463 ArdourCanvas::SimpleRect
* frame_handle_end
;
466 Visibility visibility
;
470 }; /* class TimeAxisViewItem */
472 #endif /* __gtk_ardour_time_axis_view_item_h__ */