region trimming and height patch from lincoln. great work
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
index 013a04054c8d0bd6262473ada7fec6afb9d17c87..47a8d6a3225e12d3c0cd3414eabf523064f06cbc 100644 (file)
 
 #include <gtkmm2ext/utils.h>
 
+#include "ardour_ui.h"
+/*
+ * ardour_ui.h was moved up in the include list
+ * due to a conflicting definition of 'Rect' between
+ * Apple's MacTypes.h file and GTK
+ */
+
 #include "public_editor.h"
 #include "time_axis_view_item.h"
 #include "time_axis_view.h"
@@ -32,7 +39,6 @@
 #include "utils.h"
 #include "canvas_impl.h"
 #include "rgb_macros.h"
-#include "ardour_ui.h"
 
 #include "i18n.h"
 
@@ -54,38 +60,6 @@ double TimeAxisViewItem::NAME_Y_OFFSET;
 double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE;
 double TimeAxisViewItem::NAME_HIGHLIGHT_THRESH;
 
-inline guint8
-convert_color_channel (guint8 src,
-                      guint8 alpha)
-{
-       return alpha ? ((guint (src) << 8) - src) / alpha : 0;
-}
-
-void
-convert_bgra_to_rgba (guint8 const* src,
-                     guint8*       dst,
-                     int           width,
-                     int           height)
-{
-       guint8 const* src_pixel = src;
-       guint8*       dst_pixel = dst;
-       
-       for (int y = 0; y < height; y++)
-               for (int x = 0; x < width; x++)
-               {
-                       dst_pixel[0] = convert_color_channel (src_pixel[2],
-                                                             src_pixel[3]);
-                       dst_pixel[1] = convert_color_channel (src_pixel[1],
-                                                             src_pixel[3]);
-                       dst_pixel[2] = convert_color_channel (src_pixel[0],
-                                                             src_pixel[3]);
-                       dst_pixel[3] = src_pixel[3];
-                       
-                       dst_pixel += 4;
-                       src_pixel += 4;
-               }
-}
-
 //---------------------------------------------------------------------------------------//
 // Constructor / Desctructor
 
@@ -100,7 +74,7 @@ convert_bgra_to_rgba (guint8 const* src,
  * @param start the start point of this item
  * @param duration the duration of this item
  */
-TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color& base_color, 
+TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color const & base_color, 
                                   nframes_t start, nframes_t duration, bool recording,
                                   Visibility vis)
        : trackview (tv), _recregion(recording)
@@ -116,15 +90,15 @@ TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group&
                win.add (foo);
 
                Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
-               int width;
-               int height;
+               int width = 0;
+               int height = 0;
 
                layout->set_font_description (*NAME_FONT);
                Gtkmm2ext::get_ink_pixel_size (layout, width, height);
 
-               NAME_Y_OFFSET = height + 5;
-               NAME_HIGHLIGHT_SIZE = height + 6;
-               NAME_HIGHLIGHT_THRESH = NAME_HIGHLIGHT_SIZE * 2;
+               NAME_Y_OFFSET = height + 3;
+               NAME_HIGHLIGHT_SIZE = height + 2;
+               NAME_HIGHLIGHT_THRESH = NAME_HIGHLIGHT_SIZE * 3;
 
                have_name_font = true;
        }
@@ -156,7 +130,7 @@ TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
 }
 
 void
-TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color& base_color, nframes_t start, nframes_t duration, Visibility vis)
+TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color const & base_color, nframes_t start, nframes_t duration, Visibility vis)
 {
        item_name = it_name ;
        samples_per_unit = spu ;
@@ -171,7 +145,6 @@ TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color& base_colo
        show_vestigial = true;
        visibility = vis;
        _sensitive = true;
-       name_pixbuf = 0;
 
        if (duration == 0) {
                warning << "Time Axis Item Duration == 0" << endl ;
@@ -228,22 +201,16 @@ TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color& base_colo
                name_pixbuf->property_x() = NAME_X_OFFSET;
                name_pixbuf->property_y() = trackview.current_height() - 1.0 - NAME_Y_OFFSET;
        
+       } else {
+               name_pixbuf = 0;
        }
 
-       /* create our grab handles used for trimming/duration etc */
+       /* create our grab handles used for trimming/duration etc */    
+       frame_handle_start = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height());
+       frame_handle_start->property_outline_what() = 0x0;
 
-       if (visibility & ShowHandles) {
-       
-               frame_handle_start = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 1.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH+1);
-               frame_handle_start->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_FrameHandle.get();
-
-               frame_handle_end = new ArdourCanvas::SimpleRect (*group, trackview.editor().frame_to_pixel(get_duration()) - TimeAxisViewItem::GRAB_HANDLE_LENGTH, trackview.editor().frame_to_pixel(get_duration()), 1.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH + 1);
-               frame_handle_end->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_FrameHandle.get();
-
-       } else {
-               frame_handle_start = 0;
-               frame_handle_end = 0;
-       }
+       frame_handle_end = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height());
+       frame_handle_end->property_outline_what() = 0x0;
 
        set_color (base_color) ;
 
@@ -437,9 +404,9 @@ TimeAxisViewItem::get_position_locked() const
  * @param src the identity of the object that initiated the change
  */
 void
-TimeAxisViewItem::set_max_duration_active(bool active, void* src)
+TimeAxisViewItem::set_max_duration_active (bool active, void* /*src*/)
 {
-       max_duration_active = active ;
+       max_duration_active = active;
 }
                
 /**
@@ -460,7 +427,7 @@ TimeAxisViewItem::get_max_duration_active() const
  * @param src the identity of the object that initiated the change
  */
 void
-TimeAxisViewItem::set_min_duration_active(bool active, void* src)
+TimeAxisViewItem::set_min_duration_active (bool active, void* /*src*/)
 {
        min_duration_active = active ;
 }
@@ -561,8 +528,6 @@ TimeAxisViewItem::set_name_text(const ustring& new_name)
        uint32_t pb_width, it_width;
        double font_size;
 
-       if (!name_pixbuf) return;
-
        font_size = NAME_FONT->get_size() / Pango::SCALE;
        it_width = trackview.editor().frame_to_pixel(item_duration);
        pb_width = new_name.length() * font_size;
@@ -572,7 +537,9 @@ TimeAxisViewItem::set_name_text(const ustring& new_name)
        }
 
        if (pb_width <= 0 || it_width < NAME_X_OFFSET) {
-               name_pixbuf->hide();
+               if (name_pixbuf) {
+                       name_pixbuf->hide();
+               }
                return;
        } else {
                name_pixbuf->show();
@@ -583,7 +550,7 @@ TimeAxisViewItem::set_name_text(const ustring& new_name)
        cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, pb_width, NAME_HIGHLIGHT_SIZE );
        cairo_t *cr = cairo_create (surface);
        cairo_text_extents_t te;
-       cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
+       cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 1.0);
        cairo_select_font_face (cr, NAME_FONT->get_family().c_str(),
                                CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
        cairo_set_font_size (cr, 10);
@@ -620,8 +587,8 @@ TimeAxisViewItem::set_height (double height)
                }
 
                if (height > NAME_HIGHLIGHT_SIZE) {
-                       name_highlight->property_y1() = (double) height+1 - NAME_HIGHLIGHT_SIZE;
-                       name_highlight->property_y2() = (double) height;
+                       name_highlight->property_y1() = (double) height - 1 - NAME_HIGHLIGHT_SIZE;
+                       name_highlight->property_y2() = (double) height - 2;
                }
                else {
                        /* it gets hidden now anyway */
@@ -631,21 +598,23 @@ TimeAxisViewItem::set_height (double height)
        }
 
        if (visibility & ShowNameText) {
-               name_pixbuf->property_y() = height+1 - NAME_Y_OFFSET;
+               name_pixbuf->property_y() =  height - 1 - NAME_Y_OFFSET;
        }
 
        if (frame) {
-               frame->property_y2() = height+1;
+               frame->property_y2() = height - 1;
+               frame_handle_start->property_y2() = height - 1;
+               frame_handle_end->property_y2() = height - 1;
        }
 
-       vestigial_frame->property_y2() = height+1;
+       vestigial_frame->property_y2() = height - 1;
 }
 
 /**
  * 
  */
 void
-TimeAxisViewItem::set_color(Gdk::Color& base_color)
+TimeAxisViewItem::set_color (Gdk::Color const & base_color)
 {
        compute_colors (base_color);
        set_colors ();
@@ -693,7 +662,7 @@ TimeAxisViewItem::get_name_pixbuf()
  * @param color the base color of the item
  */
 void
-TimeAxisViewItem::compute_colors(Gdk::Color& base_color)
+TimeAxisViewItem::compute_colors (Gdk::Color const & base_color)
 {
        unsigned char radius ;
        char minor_shift ;
@@ -830,10 +799,10 @@ TimeAxisViewItem::set_trim_handle_colors()
        if (frame_handle_start) {
                if (position_locked) {
                        frame_handle_start->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandleLocked.get();
-                       frame_handle_end->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandleLocked.get();
+                       frame_handle_end->property_fill_color_rgba() =  ARDOUR_UI::config()->canvasvar_TrimHandleLocked.get();
                } else {
-                       frame_handle_start->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandle.get();
-                       frame_handle_end->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TrimHandle.get();
+                       frame_handle_start->property_fill_color_rgba() = RGBA_TO_UINT(1, 1, 1, 0); //ARDOUR_UI::config()->canvasvar_TrimHandle.get();
+                       frame_handle_end->property_fill_color_rgba() = RGBA_TO_UINT(1, 1, 1, 0); //ARDOUR_UI::config()->canvasvar_TrimHandle.get();
                }
        }
 }
@@ -926,7 +895,7 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
 }
 
 void
-TimeAxisViewItem::reset_name_width (double pixel_width)
+TimeAxisViewItem::reset_name_width (double /*pixel_width*/)
 {
        set_name_text (item_name);
 }