update region's constrained-name width with name
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
index e6053906e05d68afc3f4b039259099823154d53f..d9e7a22b869e6a1dc3d5700cfe496a50f3afd4a7 100644 (file)
@@ -191,7 +191,7 @@ TimeAxisViewItem::init (ArdourCanvas::Item* parent, double fpp, uint32_t base_co
        }
 
        if (visibility & ShowFrame) {
-               frame = new ArdourCanvas::TimeRectangle (group, 
+               frame = new ArdourCanvas::Rectangle (group, 
                                                     ArdourCanvas::Rect (0.0, 0.0, 
                                                                         trackview.editor().sample_to_pixel(duration), 
                                                                         trackview.current_height()));
@@ -209,24 +209,12 @@ TimeAxisViewItem::init (ArdourCanvas::Item* parent, double fpp, uint32_t base_co
        
        if (ARDOUR_UI::config()->get_show_name_highlight() && (visibility & ShowNameHighlight)) {
 
-               double width;
-               double start = 1.0;
-
-               if (visibility & FullWidthNameHighlight) {
-                       width = trackview.editor().sample_to_pixel(item_duration);
-               } else {
-                       width = trackview.editor().sample_to_pixel(item_duration) - 2.0;
-               }
-
-               name_highlight = new ArdourCanvas::Rectangle (group, 
-                                                             ArdourCanvas::Rect (start, 
-                                                                                 trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, 
-                                                                                 width - 2.0,
-                                                                                 trackview.current_height() - 1.0));
+               /* rectangle size will be set in ::manage_name_highlight() */
+               name_highlight = new ArdourCanvas::Rectangle (group);
                CANVAS_DEBUG_NAME (name_highlight, string_compose ("name highlight for %1", get_item_name()));
                name_highlight->set_data ("timeaxisviewitem", this);
                 name_highlight->set_outline_what (ArdourCanvas::Rectangle::TOP);
-               name_highlight->set_outline_color (RGBA_TO_UINT (0,0,0,255));
+                name_highlight->set_outline_color (RGBA_TO_UINT (0,0,0,255)); // this should use a theme color
 
        } else {
                name_highlight = 0;
@@ -317,7 +305,6 @@ TimeAxisViewItem::set_position(framepos_t pos, void* src, double* delta)
        }
 
        group->set_x_position (new_unit_pos);
-
        PositionChanged (frame_position, src); /* EMIT_SIGNAL */
 
        return true;
@@ -355,7 +342,10 @@ TimeAxisViewItem::set_duration (framecnt_t dur, void* src)
 
        item_duration = dur;
 
-       reset_width_dependent_items (trackview.editor().sample_to_pixel (dur));
+       double end_pixel = trackview.editor().sample_to_pixel (frame_position + dur);
+       double first_pixel = trackview.editor().sample_to_pixel (frame_position);
+
+       reset_width_dependent_items (end_pixel - first_pixel);
 
        DurationChanged (dur, src); /* EMIT_SIGNAL */
        return true;
@@ -511,7 +501,7 @@ TimeAxisViewItem::set_selected(bool yn)
 
        if (_selected && frame) {
                if (!selection_frame) {
-                       selection_frame = new ArdourCanvas::TimeRectangle (group);
+                       selection_frame = new ArdourCanvas::Rectangle (group);
                        selection_frame->set_fill (false);
                        selection_frame->set_outline_color (ARDOUR_UI::config()->color ("selected time axis frame"));
                        selection_frame->set_ignore_events (true);
@@ -548,6 +538,7 @@ TimeAxisViewItem::set_name_text(const string& new_name)
 
        name_text_width = pixel_width (new_name, NAME_FONT) + 2;
        name_text->set (new_name);
+       manage_name_text ();
 
 }
 
@@ -573,7 +564,7 @@ TimeAxisViewItem::set_height (double height)
 
        if (frame) {
                
-               frame->set_y0 (1.0);
+               frame->set_y0 (0.0);
                frame->set_y1 (height);
 
                if (frame_handle_start) {
@@ -587,7 +578,7 @@ TimeAxisViewItem::set_height (double height)
        }
 
        if (vestigial_frame) {
-               vestigial_frame->set_y0 (1.0);
+               vestigial_frame->set_y0 (0.0);
                vestigial_frame->set_y1 (height);
        }
 
@@ -616,7 +607,8 @@ TimeAxisViewItem::manage_name_highlight ()
        if (name_highlight && wide_enough_for_name && high_enough_for_name) {
 
                name_highlight->show();
-               name_highlight->set (ArdourCanvas::Rect (1.0, (double) _height - NAME_HIGHLIGHT_SIZE,  _width, (double) _height - 1.0));
+               // name_highlight->set_x_position (1.0);
+               name_highlight->set (ArdourCanvas::Rect (0.0, (double) _height - NAME_HIGHLIGHT_SIZE,  _width - 2.0, _height));
                        
        } else {
                name_highlight->hide();
@@ -694,27 +686,17 @@ TimeAxisViewItem::set_name_text_color ()
 ArdourCanvas::Color
 TimeAxisViewItem::get_fill_color () const
 {
-       ArdourCanvas::Color c;
        const std::string mod_name = (_dragging ? "dragging region" : fill_color_name);
 
        if (_selected) {
-
-               c = ARDOUR_UI::config()->color_mod ("selected region base", mod_name);
-
-       } else {
-
-               if (_recregion) {
-                       c = ARDOUR_UI::config()->color ("recording rect");
-               } else {
-                       if ((!ARDOUR_UI::config()->get_show_name_highlight() || high_enough_for_name) && !ARDOUR_UI::config()->get_color_regions_using_track_color()) {
-                               c = ARDOUR_UI::config()->color_mod (fill_color_name, mod_name);
-                       } else {
-                               c = ARDOUR_UI::config()->color_mod (fill_color, mod_name);
-                       }
-               }
+               return ARDOUR_UI::config()->color_mod ("selected region base", mod_name);
+       } else if (_recregion) {
+               return ARDOUR_UI::config()->color ("recording rect");
+       } else if ((!ARDOUR_UI::config()->get_show_name_highlight() || high_enough_for_name) &&
+                  !ARDOUR_UI::config()->get_color_regions_using_track_color()) {
+               return ARDOUR_UI::config()->color_mod (fill_color_name, mod_name);
        }
-
-       return c;
+       return ARDOUR_UI::config()->color_mod (fill_color, mod_name);
 }
 
 /**
@@ -830,7 +812,11 @@ TimeAxisViewItem::set_samples_per_pixel (double fpp)
 {
        samples_per_pixel = fpp;
        set_position (this->get_position(), this);
-       reset_width_dependent_items ((double) get_duration() / samples_per_pixel);
+
+       double end_pixel = trackview.editor().sample_to_pixel (frame_position + get_duration());
+       double first_pixel = trackview.editor().sample_to_pixel (frame_position);
+
+       reset_width_dependent_items (end_pixel - first_pixel);
 }
 
 void
@@ -846,7 +832,7 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
                if (show_vestigial) {
 
                        if (!vestigial_frame) {
-                               vestigial_frame = new ArdourCanvas::TimeRectangle (group, ArdourCanvas::Rect (0.0, 0.0, 2.0, trackview.current_height()));
+                               vestigial_frame = new ArdourCanvas::Rectangle (group, ArdourCanvas::Rect (0.0, 0.0, 2.0, trackview.current_height()));
                                CANVAS_DEBUG_NAME (vestigial_frame, string_compose ("vestigial frame for %1", get_item_name()));
                                vestigial_frame->set_outline_color (ARDOUR_UI::config()->color ("vestigial frame"));
                                vestigial_frame->set_fill_color (ARDOUR_UI::config()->color ("vestigial frame"));
@@ -872,6 +858,9 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
 
                if (frame) {
                        frame->show();
+                       /* Note: x0 is always zero - the position is defined by
+                        * the position of the group, not the frame.
+                        */
                        frame->set_x1 (pixel_width);
 
                        if (selection_frame) {