make marker labels and regionview name text (now drawn with pixbufs) be color-adjusta...
[ardour2.git] / gtk2_ardour / time_axis_view_item.cc
blobd3f720c2537ddf693429443fb0ccc47920b3d5b6
1 /*
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 #include <pbd/error.h>
21 #include <pbd/stacktrace.h>
23 #include <ardour/types.h>
24 #include <ardour/ardour.h>
26 #include <gtkmm2ext/utils.h>
28 #include "public_editor.h"
29 #include "time_axis_view_item.h"
30 #include "time_axis_view.h"
31 #include "simplerect.h"
32 #include "utils.h"
33 #include "canvas_impl.h"
34 #include "rgb_macros.h"
35 #include "ardour_ui.h"
37 #include "i18n.h"
39 using namespace std;
40 using namespace Editing;
41 using namespace Glib;
42 using namespace PBD;
44 //------------------------------------------------------------------------------
45 /** Initialize const static memeber data */
47 Pango::FontDescription* TimeAxisViewItem::NAME_FONT = 0;
48 bool TimeAxisViewItem::have_name_font = false;
49 const double TimeAxisViewItem::NAME_X_OFFSET = 15.0;
50 const double TimeAxisViewItem::GRAB_HANDLE_LENGTH = 6 ;
52 int TimeAxisViewItem::NAME_HEIGHT;
53 double TimeAxisViewItem::NAME_Y_OFFSET;
54 double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE;
55 double TimeAxisViewItem::NAME_HIGHLIGHT_THRESH;
57 //---------------------------------------------------------------------------------------//
58 // Constructor / Desctructor
60 /**
61 * Constructs a new TimeAxisViewItem.
63 * @param it_name the unique name/Id of this item
64 * @param parant the parent canvas group
65 * @param tv the TimeAxisView we are going to be added to
66 * @param spu samples per unit
67 * @param base_color
68 * @param start the start point of this item
69 * @param duration the duration of this item
71 TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color& base_color,
72 nframes_t start, nframes_t duration, bool recording,
73 Visibility vis)
74 : trackview (tv), _height(1.0), _recregion(recording)
76 if (!have_name_font) {
78 /* first constructed item sets up font info */
80 NAME_FONT = get_font_for_style (N_("TimeAxisViewItemName"));
82 Gtk::Window win;
83 Gtk::Label foo;
84 win.add (foo);
86 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
87 int width;
88 int height;
90 layout->set_font_description (*NAME_FONT);
91 Gtkmm2ext::get_ink_pixel_size (layout, width, height);
93 NAME_HEIGHT = height;
94 NAME_Y_OFFSET = (height / 2) + 8;
95 NAME_HIGHLIGHT_SIZE = height + 6;
96 NAME_HIGHLIGHT_THRESH = NAME_HIGHLIGHT_SIZE * 2;
98 have_name_font = true;
101 group = new ArdourCanvas::Group (parent);
103 init (it_name, spu, base_color, start, duration, vis);
107 TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
108 : trackview (other.trackview)
109 , _height (other._height)
112 Gdk::Color c;
113 int r,g,b,a;
115 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
116 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
118 /* share the other's parent, but still create a new group */
120 Gnome::Canvas::Group* parent = other.group->property_parent();
122 group = new ArdourCanvas::Group (*parent);
124 init (other.item_name, other.samples_per_unit, c, other.frame_position, other.item_duration, other.visibility);
127 void
128 TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color& base_color, nframes_t start, nframes_t duration, Visibility vis)
130 item_name = it_name ;
131 samples_per_unit = spu ;
132 should_show_selection = true;
133 frame_position = start ;
134 item_duration = duration ;
135 name_connected = false;
136 fill_opacity = 0;
137 position_locked = false ;
138 max_item_duration = ARDOUR::max_frames;
139 min_item_duration = 0 ;
140 show_vestigial = true;
141 visibility = vis;
142 _sensitive = true;
143 name_pixbuf_width = 0;
144 last_item_width = 0;
146 if (duration == 0) {
147 warning << "Time Axis Item Duration == 0" << endl ;
150 vestigial_frame = new ArdourCanvas::SimpleRect (*group);
151 vestigial_frame->property_x1() = (double) 0.0;
152 vestigial_frame->property_y1() = (double) 1.0;
153 vestigial_frame->property_x2() = (double) 2.0;
154 vestigial_frame->property_y2() = (double) trackview.current_height();
155 vestigial_frame->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_VestigialFrame.get();
156 vestigial_frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VestigialFrame.get();
157 vestigial_frame->hide ();
159 if (visibility & ShowFrame) {
160 frame = new ArdourCanvas::SimpleRect (*group);
161 frame->property_x1() = (double) 0.0;
162 frame->property_y1() = (double) 1.0;
163 frame->property_x2() = (double) trackview.editor.frame_to_pixel(duration);
164 frame->property_y2() = (double) trackview.current_height();
165 frame->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
167 /* by default draw all 4 edges */
169 uint32_t outline_what = 0x1|0x2|0x4|0x8;
171 if (visibility & HideFrameLeft) {
172 outline_what &= ~(0x1);
175 if (visibility & HideFrameRight) {
176 outline_what &= ~(0x2);
179 if (visibility & HideFrameTB) {
180 outline_what &= ~(0x4 | 0x8);
183 frame->property_outline_what() = outline_what;
185 } else {
186 frame = 0;
189 if (visibility & ShowNameHighlight) {
190 name_highlight = new ArdourCanvas::SimpleRect (*group);
191 if (visibility & FullWidthNameHighlight) {
192 name_highlight->property_x1() = (double) 0.0;
193 name_highlight->property_x2() = (double) (trackview.editor.frame_to_pixel(item_duration));
194 } else {
195 name_highlight->property_x1() = (double) 1.0;
196 name_highlight->property_x2() = (double) (trackview.editor.frame_to_pixel(item_duration)) - 1;
198 name_highlight->property_y1() = (double) (trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE);
199 name_highlight->property_y2() = (double) (trackview.current_height() - 1);
201 name_highlight->set_data ("timeaxisviewitem", this);
203 } else {
204 name_highlight = 0;
207 /* create our grab handles used for trimming/duration etc */
209 if (visibility & ShowHandles) {
210 frame_handle_start = new ArdourCanvas::SimpleRect (*group);
211 frame_handle_start->property_x1() = (double) 0.0;
212 frame_handle_start->property_x2() = (double) TimeAxisViewItem::GRAB_HANDLE_LENGTH;
213 frame_handle_start->property_y1() = (double) 1.0;
214 frame_handle_start->property_y2() = (double) TimeAxisViewItem::GRAB_HANDLE_LENGTH+1;
215 frame_handle_start->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_FrameHandle.get();
217 frame_handle_end = new ArdourCanvas::SimpleRect (*group);
218 frame_handle_end->property_x1() = (double) (trackview.editor.frame_to_pixel(get_duration())) - (TimeAxisViewItem::GRAB_HANDLE_LENGTH);
219 frame_handle_end->property_x2() = (double) trackview.editor.frame_to_pixel(get_duration());
220 frame_handle_end->property_y1() = (double) 1;
221 frame_handle_end->property_y2() = (double) TimeAxisViewItem::GRAB_HANDLE_LENGTH + 1;
222 frame_handle_end->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_FrameHandle.get();
224 } else {
225 frame_handle_start = 0;
226 frame_handle_end = 0;
229 if (visibility & ShowNameText) {
230 name_pixbuf = new ArdourCanvas::Pixbuf(*group);
231 name_pixbuf->property_x() = NAME_X_OFFSET;
232 name_pixbuf->property_y() = trackview.current_height() - 1.0 - NAME_Y_OFFSET;
234 } else {
235 name_pixbuf = 0;
238 set_color (base_color) ;
240 set_duration (item_duration, this) ;
241 set_position (start, this) ;
243 ColorsChanged.connect (mem_fun (*this, &TimeAxisViewItem::color_handler));
247 * Destructor
249 TimeAxisViewItem::~TimeAxisViewItem()
251 delete group;
255 //---------------------------------------------------------------------------------------//
256 // Position and duration Accessors/Mutators
259 * Set the position of this item upon the timeline to the specified value
261 * @param pos the new position
262 * @param src the identity of the object that initiated the change
263 * @return true if the position change was a success, false otherwise
265 bool
266 TimeAxisViewItem::set_position(nframes_t pos, void* src, double* delta)
268 if (position_locked) {
269 return false;
272 frame_position = pos;
274 /* This sucks. The GnomeCanvas version I am using
275 doesn't correctly implement gnome_canvas_group_set_arg(),
276 so that simply setting the "x" arg of the group
277 fails to move the group. Instead, we have to
278 use gnome_canvas_item_move(), which does the right
279 thing. I see that in GNOME CVS, the current (Sept 2001)
280 version of GNOME Canvas rectifies this issue cleanly.
283 double old_unit_pos ;
284 double new_unit_pos = pos / samples_per_unit ;
286 old_unit_pos = group->property_x();
288 if (new_unit_pos != old_unit_pos) {
289 group->move (new_unit_pos - old_unit_pos, 0.0);
292 if (delta) {
293 (*delta) = new_unit_pos - old_unit_pos;
296 PositionChanged (frame_position, src) ; /* EMIT_SIGNAL */
298 return true;
302 * Return the position of this item upon the timeline
304 * @return the position of this item
306 nframes_t
307 TimeAxisViewItem::get_position() const
309 return frame_position;
313 * Sets the duration of this item
315 * @param dur the new duration of this item
316 * @param src the identity of the object that initiated the change
317 * @return true if the duration change was succesful, false otherwise
319 bool
320 TimeAxisViewItem::set_duration (nframes_t dur, void* src)
322 if ((dur > max_item_duration) || (dur < min_item_duration)) {
323 warning << string_compose (_("new duration %1 frames is out of bounds for %2"), get_item_name(), dur)
324 << endmsg;
325 return false;
328 if (dur == 0) {
329 group->hide();
332 item_duration = dur;
334 reset_width_dependent_items (trackview.editor.frame_to_pixel (dur));
336 DurationChanged (dur, src) ; /* EMIT_SIGNAL */
337 return true;
341 * Returns the duration of this item
344 nframes_t
345 TimeAxisViewItem::get_duration() const
347 return (item_duration);
351 * Sets the maximum duration that this item make have.
353 * @param dur the new maximum duration
354 * @param src the identity of the object that initiated the change
356 void
357 TimeAxisViewItem::set_max_duration(nframes_t dur, void* src)
359 max_item_duration = dur ;
360 MaxDurationChanged(max_item_duration, src) ; /* EMIT_SIGNAL */
364 * Returns the maxmimum duration that this item may be set to
366 * @return the maximum duration that this item may be set to
368 nframes_t
369 TimeAxisViewItem::get_max_duration() const
371 return (max_item_duration) ;
375 * Sets the minimu duration that this item may be set to
377 * @param the minimum duration that this item may be set to
378 * @param src the identity of the object that initiated the change
380 void
381 TimeAxisViewItem::set_min_duration(nframes_t dur, void* src)
383 min_item_duration = dur ;
384 MinDurationChanged(max_item_duration, src) ; /* EMIT_SIGNAL */
388 * Returns the minimum duration that this item mey be set to
390 * @return the nimum duration that this item mey be set to
392 nframes_t
393 TimeAxisViewItem::get_min_duration() const
395 return(min_item_duration) ;
399 * Sets whether the position of this Item is locked to its current position
400 * Locked items cannot be moved until the item is unlocked again.
402 * @param yn set to true to lock this item to its current position
403 * @param src the identity of the object that initiated the change
405 void
406 TimeAxisViewItem::set_position_locked(bool yn, void* src)
408 position_locked = yn ;
409 set_trim_handle_colors() ;
410 PositionLockChanged (position_locked, src); /* EMIT_SIGNAL */
414 * Returns whether this item is locked to its current position
416 * @return true if this item is locked to its current posotion
417 * false otherwise
419 bool
420 TimeAxisViewItem::get_position_locked() const
422 return (position_locked);
426 * Sets whether the Maximum Duration constraint is active and should be enforced
428 * @param active set true to enforce the max duration constraint
429 * @param src the identity of the object that initiated the change
431 void
432 TimeAxisViewItem::set_max_duration_active(bool active, void* src)
434 max_duration_active = active ;
438 * Returns whether the Maximum Duration constraint is active and should be enforced
440 * @return true if the maximum duration constraint is active, false otherwise
442 bool
443 TimeAxisViewItem::get_max_duration_active() const
445 return(max_duration_active) ;
449 * Sets whether the Minimum Duration constraint is active and should be enforced
451 * @param active set true to enforce the min duration constraint
452 * @param src the identity of the object that initiated the change
454 void
455 TimeAxisViewItem::set_min_duration_active(bool active, void* src)
457 min_duration_active = active ;
461 * Returns whether the Maximum Duration constraint is active and should be enforced
463 * @return true if the maximum duration constraint is active, false otherwise
465 bool
466 TimeAxisViewItem::get_min_duration_active() const
468 return(min_duration_active) ;
471 //---------------------------------------------------------------------------------------//
472 // Name/Id Accessors/Mutators
475 * Set the name/Id of this item.
477 * @param new_name the new name of this item
478 * @param src the identity of the object that initiated the change
480 void
481 TimeAxisViewItem::set_item_name(std::string new_name, void* src)
483 if (new_name != item_name) {
484 std::string temp_name = item_name ;
485 item_name = new_name ;
486 NameChanged (item_name, temp_name, src) ; /* EMIT_SIGNAL */
491 * Returns the name/id of this item
493 * @return the name/id of this item
495 std::string
496 TimeAxisViewItem::get_item_name() const
498 return(item_name) ;
501 //---------------------------------------------------------------------------------------//
502 // Selection Methods
505 * Set to true to indicate that this item is currently selected
507 * @param yn true if this item is currently selected
508 * @param src the identity of the object that initiated the change
510 void
511 TimeAxisViewItem::set_selected(bool yn)
513 if (_selected != yn) {
514 Selectable::set_selected (yn);
515 set_frame_color ();
519 void
520 TimeAxisViewItem::set_should_show_selection (bool yn)
522 if (should_show_selection != yn) {
523 should_show_selection = yn;
524 set_frame_color ();
528 //---------------------------------------------------------------------------------------//
529 // Parent Componenet Methods
532 * Returns the TimeAxisView that this item is upon
534 * @return the timeAxisView that this item is placed upon
536 TimeAxisView&
537 TimeAxisViewItem::get_time_axis_view()
539 return trackview;
541 //---------------------------------------------------------------------------------------//
542 // ui methods & data
545 * Sets the displayed item text
546 * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
548 * @param new_name the new name text to display
550 void
551 TimeAxisViewItem::set_name_text(const ustring& new_name)
553 if (!name_pixbuf) {
554 return;
557 _name = new_name;
559 last_item_width = trackview.editor.frame_to_pixel(item_duration);
560 name_pixbuf_width = pixel_width (new_name, *NAME_FONT) + 2;
561 name_pixbuf->property_pixbuf() = pixbuf_from_ustring(new_name, NAME_FONT,
562 ARDOUR_UI::config()->canvasvar_TimeAxisViewItemName.get(),
563 name_pixbuf_width, NAME_HEIGHT);
566 void
567 TimeAxisViewItem::color_handler ()
569 set_name_text (_name);
573 * Set the height of this item
575 * @param h the new height
577 void
578 TimeAxisViewItem::set_height (double height)
580 _height = height;
582 if (name_highlight) {
583 if (height < NAME_HIGHLIGHT_THRESH) {
584 name_highlight->hide();
585 } else {
586 name_highlight->show();
589 if (height > NAME_HIGHLIGHT_SIZE) {
590 name_highlight->property_y1() = (double) height+1 - NAME_HIGHLIGHT_SIZE;
591 name_highlight->property_y2() = (double) height;
592 } else {
593 /* it gets hidden now anyway */
594 //name_highlight->property_y1() = (double) 1.0;
595 //name_highlight->property_y2() = (double) height;
599 if (name_pixbuf) {
600 if (height < NAME_HIGHLIGHT_THRESH) {
601 name_pixbuf->hide();
602 } else {
603 name_pixbuf->property_y() = height+1 - NAME_Y_OFFSET;
604 name_pixbuf->show();
608 if (frame) {
609 frame->property_y2() = height+1;
612 vestigial_frame->property_y2() = height+1;
618 void
619 TimeAxisViewItem::set_color(Gdk::Color& base_color)
621 compute_colors (base_color);
622 set_colors ();
628 ArdourCanvas::Item*
629 TimeAxisViewItem::get_canvas_frame()
631 return(frame) ;
637 ArdourCanvas::Group*
638 TimeAxisViewItem::get_canvas_group()
640 return (group) ;
646 ArdourCanvas::Item*
647 TimeAxisViewItem::get_name_highlight()
649 return (name_highlight) ;
655 ArdourCanvas::Pixbuf*
656 TimeAxisViewItem::get_name_pixbuf()
658 return (name_pixbuf) ;
662 * Calculates some contrasting color for displaying various parts of this item, based upon the base color
664 * @param color the base color of the item
666 void
667 TimeAxisViewItem::compute_colors(Gdk::Color& base_color)
669 unsigned char radius ;
670 char minor_shift ;
672 unsigned char r,g,b ;
674 /* FILL: this is simple */
675 r = base_color.get_red()/256 ;
676 g = base_color.get_green()/256 ;
677 b = base_color.get_blue()/256 ;
678 fill_color = RGBA_TO_UINT(r,g,b,255) ;
680 /* for minor colors:
681 if the overall saturation is strong, make the minor colors light.
682 if its weak, make them dark.
684 we do this by moving an equal distance to the other side of the
685 central circle in the color wheel from where we started.
688 radius = (unsigned char) rint (floor (sqrt (static_cast<double>(r*r + g*g + b+b))/3.0f)) ;
689 minor_shift = 125 - radius ;
691 /* LABEL: rotate around color wheel by 120 degrees anti-clockwise */
693 r = base_color.get_red()/256;
694 g = base_color.get_green()/256;
695 b = base_color.get_blue()/256;
697 if (r > b)
699 if (r > g)
701 /* red sector => green */
702 swap (r,g);
704 else
706 /* green sector => blue */
707 swap (g,b);
710 else
712 if (b > g)
714 /* blue sector => red */
715 swap (b,r);
717 else
719 /* green sector => blue */
720 swap (g,b);
724 r += minor_shift;
725 b += minor_shift;
726 g += minor_shift;
728 label_color = RGBA_TO_UINT(r,g,b,255);
729 r = (base_color.get_red()/256) + 127 ;
730 g = (base_color.get_green()/256) + 127 ;
731 b = (base_color.get_blue()/256) + 127 ;
733 label_color = RGBA_TO_UINT(r,g,b,255);
735 /* XXX can we do better than this ? */
736 /* We're trying ;) */
737 /* NUKECOLORS */
739 //frame_color_r = 192;
740 //frame_color_g = 192;
741 //frame_color_b = 194;
743 //selected_frame_color_r = 182;
744 //selected_frame_color_g = 145;
745 //selected_frame_color_b = 168;
747 //handle_color_r = 25 ;
748 //handle_color_g = 0 ;
749 //handle_color_b = 255 ;
750 //lock_handle_color_r = 235 ;
751 //lock_handle_color_g = 16;
752 //lock_handle_color_b = 16;
756 * Convenience method to set the various canvas item colors
758 void
759 TimeAxisViewItem::set_colors()
761 set_frame_color() ;
763 if (name_highlight) {
764 name_highlight->property_fill_color_rgba() = fill_color;
765 name_highlight->property_outline_color_rgba() = fill_color;
767 set_trim_handle_colors() ;
771 * Sets the frame color depending on whether this item is selected
773 void
774 TimeAxisViewItem::set_frame_color()
776 if (frame) {
777 uint32_t r,g,b,a;
779 if (_selected && should_show_selection) {
780 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
781 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);// Lets still use the theme's opacity value if Opaque is not set
782 } else {
783 if (_recregion) {
784 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
785 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
786 } else {
787 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
788 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
795 * Sets the colors of the start and end trim handle depending on object state
798 void
799 TimeAxisViewItem::set_trim_handle_colors()
801 if (frame_handle_start) {
802 if (position_locked) {
803 frame_handle_start->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandleLocked.get();
804 frame_handle_end->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandleLocked.get();
805 } else {
806 frame_handle_start->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandle.get();
807 frame_handle_end->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandle.get();
812 double
813 TimeAxisViewItem::get_samples_per_unit()
815 return(samples_per_unit) ;
818 void
819 TimeAxisViewItem::set_samples_per_unit (double spu)
821 samples_per_unit = spu ;
822 set_position (this->get_position(), this);
823 reset_width_dependent_items ((double)get_duration() / samples_per_unit);
826 void
827 TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
829 if (pixel_width < 2.0) {
831 if (show_vestigial) {
832 vestigial_frame->show();
835 if (name_highlight) {
836 name_highlight->hide();
839 if (name_pixbuf) {
840 name_pixbuf->hide();
843 if (frame) {
844 frame->hide();
847 if (frame_handle_start) {
848 frame_handle_start->hide();
849 frame_handle_end->hide();
852 } else {
853 vestigial_frame->hide();
855 if (name_highlight) {
857 if (_height < NAME_HIGHLIGHT_THRESH) {
858 name_highlight->hide();
859 } else {
860 name_highlight->show();
863 if (visibility & FullWidthNameHighlight) {
864 name_highlight->property_x2() = pixel_width;
865 } else {
866 name_highlight->property_x2() = pixel_width - 1.0;
871 if (name_pixbuf) {
872 if (_height < NAME_HIGHLIGHT_THRESH) {
873 name_pixbuf->hide();
874 } else {
875 reset_name_width (pixel_width);
879 if (frame) {
880 frame->show();
881 frame->property_x2() = pixel_width;
884 if (frame_handle_start) {
885 if (pixel_width < (2*TimeAxisViewItem::GRAB_HANDLE_LENGTH)) {
886 frame_handle_start->hide();
887 frame_handle_end->hide();
888 } else {
889 frame_handle_start->show();
890 frame_handle_end->property_x1() = pixel_width - (TimeAxisViewItem::GRAB_HANDLE_LENGTH);
891 frame_handle_end->property_x2() = pixel_width;
892 frame_handle_end->show();
898 void
899 TimeAxisViewItem::reset_name_width (double pix_width)
901 uint32_t it_width;
902 int pb_width;
903 bool pixbuf_holds_full_name;
905 if (!name_pixbuf) {
906 return;
909 it_width = trackview.editor.frame_to_pixel(item_duration);
910 pb_width = name_pixbuf_width;
912 pixbuf_holds_full_name = last_item_width > pb_width + NAME_X_OFFSET;
913 last_item_width = it_width;
915 if (pixbuf_holds_full_name && (it_width >= pb_width + NAME_X_OFFSET)) {
917 we've previously had the full name length showing
918 and its still showing.
920 return;
923 if (pb_width > it_width - NAME_X_OFFSET) {
924 pb_width = it_width - NAME_X_OFFSET;
927 if (pb_width <= 0 || it_width <= NAME_X_OFFSET) {
928 name_pixbuf->hide();
929 return;
930 } else {
931 name_pixbuf->show();
934 name_pixbuf->property_pixbuf() = pixbuf_from_ustring(item_name, NAME_FONT,
935 ARDOUR_UI::config()->canvasvar_TimeAxisViewItemName.get(),
936 pb_width, NAME_HEIGHT);
940 //---------------------------------------------------------------------------------------//
941 // Handle time axis removal
944 * Handles the Removal of this time axis item
945 * This _needs_ to be called to alert others of the removal properly, ie where the source
946 * of the removal came from.
948 * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
949 * just now to capture the source of the removal
951 * @param src the identity of the object that initiated the change
953 void
954 TimeAxisViewItem::remove_this_item(void* src)
957 defer to idle loop, otherwise we'll delete this object
958 while we're still inside this function ...
960 Glib::signal_idle().connect(bind (sigc::ptr_fun (&TimeAxisViewItem::idle_remove_this_item), this, src));
964 * Callback used to remove this time axis item during the gtk idle loop
965 * This is used to avoid deleting the obejct while inside the remove_this_item
966 * method
968 * @param item the TimeAxisViewItem to remove
969 * @param src the identity of the object that initiated the change
971 gint
972 TimeAxisViewItem::idle_remove_this_item(TimeAxisViewItem* item, void* src)
974 item->ItemRemoved (item->get_item_name(), src) ; /* EMIT_SIGNAL */
975 delete item;
976 item = 0;
977 return false;