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.
21 #ifndef __gtk_ardour_time_axis_view_item_h__
22 #define __gtk_ardour_time_axis_view_item_h__
24 #include <sigc++/signal.h>
26 #include <jack/jack.h>
29 #include <libgnomecanvasmm/text.h>
31 #include "selectable.h"
32 #include "simplerect.h"
37 * A base class for 'items' that may appear upon a TimeAxisView
40 class TimeAxisViewItem : public sigc::trackable, public Selectable
43 virtual ~TimeAxisViewItem() ;
46 * Set the position of this item upon the timeline to the specified value
48 * @param pos the new position
49 * @param src the identity of the object that initiated the change
50 * @return true if the position change was a success, false otherwise
52 virtual bool set_position(jack_nframes_t pos, void* src, double* delta = 0) ;
55 * Return the position of this item upon the timeline
57 * @return the position of this item
59 jack_nframes_t get_position() const ;
62 * Sets the duration of this item
64 * @param dur the new duration of this item
65 * @param src the identity of the object that initiated the change
66 * @return true if the duration change was succesful, false otherwise
68 virtual bool set_duration(jack_nframes_t dur, void* src) ;
71 * Returns the duration of this item
74 jack_nframes_t get_duration() const ;
77 * Sets the maximum duration that this item make have.
79 * @param dur the new maximum duration
80 * @param src the identity of the object that initiated the change
82 virtual void set_max_duration(jack_nframes_t dur, void* src) ;
85 * Returns the maxmimum duration that this item may be set to
87 * @return the maximum duration that this item may be set to
89 jack_nframes_t get_max_duration() const ;
92 * Sets the minimu duration that this item may be set to
94 * @param the minimum duration that this item may be set to
95 * @param src the identity of the object that initiated the change
97 virtual void set_min_duration(jack_nframes_t dur, void* src) ;
100 * Returns the minimum duration that this item mey be set to
102 * @return the nimum duration that this item mey be set to
104 jack_nframes_t get_min_duration() const ;
107 * Sets whether the position of this Item is locked to its current position
108 * Locked items cannot be moved until the item is unlocked again.
110 * @param yn set to true to lock this item to its current position
111 * @param src the identity of the object that initiated the change
113 virtual void set_position_locked(bool yn, void* src) ;
116 * Returns whether this item is locked to its current position
118 * @return true if this item is locked to its current posotion
121 bool get_position_locked() const ;
124 * Sets whether the Maximum Duration constraint is active and should be enforced
126 * @param active set true to enforce the max duration constraint
127 * @param src the identity of the object that initiated the change
129 void set_max_duration_active(bool active, void* src) ;
132 * Returns whether the Maximum Duration constraint is active and should be enforced
134 * @return true if the maximum duration constraint is active, false otherwise
136 bool get_max_duration_active() const ;
139 * Sets whether the Minimum Duration constraint is active and should be enforced
141 * @param active set true to enforce the min duration constraint
142 * @param src the identity of the object that initiated the change
144 void set_min_duration_active(bool active, void* src) ;
147 * Returns whether the Maximum Duration constraint is active and should be enforced
149 * @return true if the maximum duration constraint is active, false otherwise
151 bool get_min_duration_active() const ;
154 * Set the name/Id of this item.
156 * @param new_name the new name of this item
157 * @param src the identity of the object that initiated the change
159 void set_item_name(std::string new_name, void* src) ;
162 * Returns the name/id of this item
164 * @return the name/id of this item
166 virtual std::string get_item_name() const ;
169 * Set to true to indicate that this item is currently selected
171 * @param yn true if this item is currently selected
172 * @param src the identity of the object that initiated the change
174 virtual void set_selected(bool yn, void* src) ;
177 * Set to true to indicate that this item should show its selection status
179 * @param yn true if this item should show its selected status
181 virtual void set_should_show_selection (bool yn) ;
184 * Returns whether this item is currently selected.
186 * @return true if this item is currently selected, false otherwise
188 bool get_selected() const ;
190 //---------------------------------------------------------------------------------------//
191 // Parent Component Methods
194 * Returns the TimeAxisView that this item is upon
196 * @return the timeAxisView that this item is placed upon
198 TimeAxisView& get_time_axis_view() ;
200 //---------------------------------------------------------------------------------------//
204 * Sets the displayed item text
205 * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
207 * @param new_name the new name text to display
209 void set_name_text(std::string new_name) ;
212 * Set the height of this item
214 * @param h the new height
216 virtual void set_height(double h) ;
221 void set_color(Gdk::Color& color) ;
226 Gnome::Canvas::Item* get_canvas_frame() ;
231 Gnome::Canvas::Item* get_canvas_group();
236 Gnome::Canvas::Item* get_name_highlight();
241 Gnome::Canvas::Text* get_name_text();
245 * Sets the samples per unit of this item.
246 * this item is used to determine the relative visual size and position of this item
247 * based upon its duration and start value.
249 * @param spu the new samples per unit value
251 virtual void set_samples_per_unit(double spu) ;
254 * Returns the current samples per unit of this item
256 * @return the samples per unit of this item
258 double get_samples_per_unit() ;
260 virtual void raise () { return; }
261 virtual void raise_to_top () { return; }
262 virtual void lower () { return; }
263 virtual void lower_to_bottom () { return; }
266 * returns true if the name area should respond to events.
268 bool name_active() const { return name_connected; }
270 // Default sizes, font and spacing
271 static Pango::FontDescription NAME_FONT ;
272 static bool have_name_font;
273 static const double NAME_X_OFFSET ;
274 static const double NAME_Y_OFFSET ;
275 static const double NAME_HIGHLIGHT_SIZE ;
276 static const double NAME_HIGHLIGHT_THRESH ;
277 static const double GRAB_HANDLE_LENGTH ;
280 * Handles the Removal of this time axis item
281 * This _needs_ to be called to alert others of the removal properly, ie where the source
282 * of the removal came from.
284 * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
285 * just now to capture the source of the removal
287 * @param src the identity of the object that initiated the change
289 virtual void remove_this_item(void* src) ;
292 * Emitted when this Group has been removed
293 * This is different to the GoingAway signal in that this signal
294 * is emitted during the deletion of this Time Axis, and not during
295 * the destructor, this allows us to capture the source of the deletion
298 sigc::signal<void,std::string,void*> ItemRemoved ;
300 /** Emitted when the name/Id of this item is changed */
301 sigc::signal<void,std::string,std::string,void*> NameChanged ;
303 /** Emiited when the position of this item changes */
304 sigc::signal<void,jack_nframes_t,void*> PositionChanged ;
306 /** Emitted when the position lock of this item is changed */
307 sigc::signal<void,bool,void*> PositionLockChanged ;
309 /** Emitted when the duration of this item changes */
310 sigc::signal<void,jack_nframes_t,void*> DurationChanged ;
312 /** Emitted when the maximum item duration is changed */
313 sigc::signal<void,jack_nframes_t,void*> MaxDurationChanged ;
315 /** Emitted when the mionimum item duration is changed */
316 sigc::signal<void,jack_nframes_t,void*> MinDurationChanged ;
318 /** Emitted when the selected status of this item changes */
319 sigc::signal<void, bool> Selected ;
326 ShowNameHighlight = 0x2,
332 * Constructs a new TimeAxisViewItem.
334 * @param it_name the unique name/Id of this item
335 * @param parent the parent canvas group
336 * @param tv the TimeAxisView we are going to be added to
337 * @param spu samples per unit
339 * @param start the start point of this item
340 * @param duration the duration of this item
342 TimeAxisViewItem(std::string it_name, Gnome::Canvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color& base_color,
343 jack_nframes_t start, jack_nframes_t duration, Visibility v = Visibility (0));
346 * Calculates some contrasting color for displaying various parts of this item, based upon the base color
348 * @param color the base color of the item
350 virtual void compute_colors(Gdk::Color& color) ;
353 * convenience method to set the various canvas item colors
355 virtual void set_colors() ;
358 * Sets the frame color depending on whether this item is selected
360 void set_frame_color() ;
363 * Sets the colors of the start and end trim handle depending on object state
366 void set_trim_handle_colors() ;
368 virtual void reset_width_dependent_items (double pixel_width);
369 void reset_name_width (double pixel_width);
372 * Callback used to remove this item during the gtk idle loop
373 * This is used to avoid deleting the obejct while inside the remove_this_group
376 * @param item the time axis item to remove
377 * @param src the identity of the object that initiated the change
379 static gint idle_remove_this_item(TimeAxisViewItem* item, void* src) ;
381 /** The time axis that this item is upon */
382 TimeAxisView& trackview ;
384 /** indicates whether this item is locked to its current position */
385 bool position_locked ;
387 /** The posotion of this item on the timeline */
388 jack_nframes_t frame_position ;
390 /** the duration of this item upon the timeline */
391 jack_nframes_t item_duration ;
393 /** the maximum duration that we allow this item to take */
394 jack_nframes_t max_item_duration ;
396 /** the minimu duration that we allow this item to take */
397 jack_nframes_t min_item_duration ;
399 /** indicates whether this Max Duration constraint is active */
400 bool max_duration_active ;
402 /** indicates whether this Min Duration constraint is active */
403 bool min_duration_active ;
405 /** the curretn samples per canvas unit */
406 double samples_per_unit ;
408 /** indicates if this item is currently selected */
411 /** should the item show its selected status */
412 bool should_show_selection;
415 * The unique item name of this Item
416 * Each item upon a time axis must have a unique id
418 std::string item_name ;
421 * true if the name should respond to events
426 * true if a small vestigial rect should be shown when the item gets very narrow
431 uint32_t fill_opacity;
432 uint32_t fill_color ;
433 uint32_t frame_color_r ;
434 uint32_t frame_color_g ;
435 uint32_t frame_color_b ;
436 uint32_t selected_frame_color_r ;
437 uint32_t selected_frame_color_g ;
438 uint32_t selected_frame_color_b ;
439 uint32_t label_color ;
441 uint32_t handle_color_r ;
442 uint32_t handle_color_g ;
443 uint32_t handle_color_b ;
444 uint32_t lock_handle_color_r ;
445 uint32_t lock_handle_color_g ;
446 uint32_t lock_handle_color_b ;
448 Gnome::Canvas::Group* group;
449 Gnome::Canvas::SimpleRect* vestigial_frame;
450 Gnome::Canvas::SimpleRect* frame;
451 Gnome::Canvas::Text* name_text;
452 Gnome::Canvas::SimpleRect* name_highlight;
453 Gnome::Canvas::SimpleRect* frame_handle_start;
454 Gnome::Canvas::SimpleRect* frame_handle_end;
456 }; /* class TimeAxisViewItem */
458 #endif /* __gtk_ardour_time_axis_view_item_h__ */