hopefully fix up selection of color for region name text, under all conditions
[ardour.git] / gtk2_ardour / region_view.cc
index 37ddb45917bd30e198aa3f9bd075f36da4d083b6..d6c006a77b27085f42a60b415517f48f35f74d44 100644 (file)
@@ -69,8 +69,9 @@ RegionView::RegionView (ArdourCanvas::Group*              parent,
                         Gdk::Color const &                basic_color,
                        bool                              automation)
        : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), false, automation,
-                           TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
-                                                         TimeAxisViewItem::ShowNameHighlight| TimeAxisViewItem::ShowFrame))
+                           (automation ? TimeAxisViewItem::ShowFrame :
+                            TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
+                                                          TimeAxisViewItem::ShowNameHighlight| TimeAxisViewItem::ShowFrame)))
        , _region (r)
        , sync_mark(0)
        , sync_line(0)
@@ -167,20 +168,20 @@ RegionView::init (Gdk::Color const & basic_color, bool wfd)
        if (name_highlight) {
                name_highlight->set_data ("regionview", this);
                name_highlight->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
-
-               if (frame_handle_start) {
-                       frame_handle_start->set_data ("regionview", this);
-                       frame_handle_start->set_data ("isleft", (void*) 1);
-                       frame_handle_start->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_start, this));
-                       frame_handle_start->raise_to_top();
-               }
-
-               if (frame_handle_end) {
-                       frame_handle_end->set_data ("regionview", this);
-                       frame_handle_end->set_data ("isleft", (void*) 0);
-                       frame_handle_end->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_end, this));
-                       frame_handle_end->raise_to_top();
-               }
+       }
+       
+       if (frame_handle_start) {
+               frame_handle_start->set_data ("regionview", this);
+               frame_handle_start->set_data ("isleft", (void*) 1);
+               frame_handle_start->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_start, this));
+               frame_handle_start->raise_to_top();
+       }
+       
+       if (frame_handle_end) {
+               frame_handle_end->set_data ("regionview", this);
+               frame_handle_end->set_data ("isleft", (void*) 0);
+               frame_handle_end->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_end, this));
+               frame_handle_end->raise_to_top();
        }
 
        if (name_text) {
@@ -196,8 +197,6 @@ RegionView::init (Gdk::Color const & basic_color, bool wfd)
 
        _region->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&RegionView::region_changed, this, _1), gui_context());
 
-       group->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
-
        set_colors ();
 
        ColorsChanged.connect (sigc::mem_fun (*this, &RegionView::color_handler));
@@ -222,6 +221,12 @@ RegionView::~RegionView ()
        delete editor;
 }
 
+bool
+RegionView::canvas_group_event (GdkEvent* event)
+{
+       return trackview.editor().canvas_region_view_event (event, group, this);
+}
+
 void
 RegionView::set_silent_frames (const AudioIntervalResult& silences, double /*threshold*/)
 {
@@ -632,9 +637,11 @@ RegionView::region_sync_changed ()
                /* points set below */
 
                sync_mark = new ArdourCanvas::Polygon (group);
+               CANVAS_DEBUG_NAME (sync_mark, string_compose ("sync mark for %1", get_item_name()));
                sync_mark->set_fill_color (RGBA_TO_UINT(0,255,0,255));    // FIXME make a themeable colour
 
                sync_line = new ArdourCanvas::Line (group);
+               CANVAS_DEBUG_NAME (sync_line, string_compose ("sync mark for %1", get_item_name()));
                sync_line->set_outline_color (RGBA_TO_UINT(0,255,0,255)); // FIXME make a themeable colour
        }
 
@@ -687,7 +694,18 @@ RegionView::move (double x_delta, double y_delta)
                return;
        }
 
-       get_canvas_group()->move (ArdourCanvas::Duple (x_delta, y_delta));
+       /* items will not prevent Item::move() moving
+        * them to a negative x-axis coordinate, which
+        * is legal, but we don't want that here.
+        */
+
+       ArdourCanvas::Item *item = get_canvas_group ();
+       
+       if (item->position().x + x_delta < 0) {
+               x_delta = -item->position().x; /* move it to zero */
+       }
+
+       item->move (ArdourCanvas::Duple (x_delta, y_delta));
 
        /* note: ghosts never leave their tracks so y_delta for them is always zero */
 
@@ -722,12 +740,6 @@ RegionView::remove_ghost (GhostRegion* ghost)
        }
 }
 
-uint32_t
-RegionView::get_fill_color ()
-{
-       return fill_color;
-}
-
 void
 RegionView::set_height (double h)
 {
@@ -930,32 +942,12 @@ RegionView::thaw_after_trim ()
 
 
 void
-RegionView::trim_contents (framepos_t frame_delta, bool left_direction, bool swap_direction)
+RegionView::move_contents (frameoffset_t distance)
 {
        if (_region->locked()) {
                return;
        }
-
-       framepos_t new_bound;
-
-       RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
-       double const speed = rtv.track()->speed ();
-
-       if (left_direction) {
-               if (swap_direction) {
-                       new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
-               } else {
-                       new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
-               }
-       } else {
-               if (swap_direction) {
-                       new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
-               } else {
-                       new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
-               }
-       }
-
-       _region->trim_start ((framepos_t) (new_bound * speed));
+       _region->move_start (distance);
        region_changed (PropertyChange (ARDOUR::Properties::start));
 }