Build plugin menu only when plugins change, and build the first version of it before...
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
index cb114f4f3d119ce40b3244c708f18b73ea6c0557..1d8fc2aca7f6bd6defa2349217519b3441b80fb1 100644 (file)
@@ -56,6 +56,7 @@ bool TimeAxisViewItem::have_name_font = false;
 const double TimeAxisViewItem::NAME_X_OFFSET = 15.0;
 const double TimeAxisViewItem::GRAB_HANDLE_LENGTH = 6 ;
 
+int    TimeAxisViewItem::NAME_HEIGHT;
 double TimeAxisViewItem::NAME_Y_OFFSET;
 double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE;
 double TimeAxisViewItem::NAME_HIGHLIGHT_THRESH;
@@ -96,6 +97,7 @@ TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group&
                layout->set_font_description (*NAME_FONT);
                Gtkmm2ext::get_ink_pixel_size (layout, width, height);
 
+               NAME_HEIGHT = height;
                NAME_Y_OFFSET = height + 3;
                NAME_HIGHLIGHT_SIZE = height + 2;
                NAME_HIGHLIGHT_THRESH = NAME_HIGHLIGHT_SIZE * 3;
@@ -145,6 +147,8 @@ TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color const & ba
        show_vestigial = true;
        visibility = vis;
        _sensitive = true;
+       name_pixbuf_width = 0;
+       last_item_width = 0;
 
        if (duration == 0) {
                warning << "Time Axis Item Duration == 0" << endl ;
@@ -525,48 +529,16 @@ TimeAxisViewItem::get_time_axis_view()
 void
 TimeAxisViewItem::set_name_text(const ustring& new_name)
 {
-       uint32_t pb_width, it_width;
-       double font_size;
-
-       font_size = NAME_FONT->get_size() / Pango::SCALE;
-       it_width = trackview.editor().frame_to_pixel(item_duration);
-       pb_width = new_name.length() * font_size;
-
-       if (pb_width > it_width - NAME_X_OFFSET) {
-               pb_width = it_width - NAME_X_OFFSET;
-       }
-
-       if (pb_width <= 0 || it_width < NAME_X_OFFSET) {
-               if (name_pixbuf) {
-                       name_pixbuf->hide();
-               }
+       if (!name_pixbuf) {
                return;
-       } else {
-               name_pixbuf->show();
        }
 
-       Glib::RefPtr<Gdk::Pixbuf> buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, pb_width, NAME_HIGHLIGHT_SIZE);
-
-       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.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);
-       cairo_text_extents (cr, new_name.c_str(), &te);
-
-       cairo_move_to (cr, 0.5,
-                      0.5 - te.height / 2 - te.y_bearing + NAME_HIGHLIGHT_SIZE / 2);
-       cairo_show_text (cr, new_name.c_str());
-
-       unsigned char* src = cairo_image_surface_get_data (surface);
-       convert_bgra_to_rgba(src, buf->get_pixels(), pb_width, NAME_HIGHLIGHT_SIZE);
-
-       cairo_destroy(cr);
-       name_pixbuf->property_pixbuf() = buf;
+       last_item_width = trackview.editor().frame_to_pixel(item_duration);
+       name_pixbuf_width = pixel_width (new_name, *NAME_FONT) + 2;
+       name_pixbuf->property_pixbuf() = pixbuf_from_ustring(new_name, NAME_FONT, name_pixbuf_width, NAME_HEIGHT);
 }
 
+
 /**
  * Set the height of this item
  *
@@ -897,7 +869,40 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
 void
 TimeAxisViewItem::reset_name_width (double /*pixel_width*/)
 {
-       set_name_text (item_name);
+       uint32_t it_width;
+       int pb_width;
+       bool pixbuf_holds_full_name;
+
+       if (!name_pixbuf) {
+               return;
+       }
+
+       it_width = trackview.editor().frame_to_pixel(item_duration);
+       pb_width = name_pixbuf_width;
+
+       pixbuf_holds_full_name = last_item_width > pb_width + NAME_X_OFFSET;
+       last_item_width = it_width;
+
+       if (pixbuf_holds_full_name && (it_width >= pb_width + NAME_X_OFFSET)) {
+               /*
+                 we've previously had the full name length showing 
+                 and its still showing.
+               */
+               return;
+       }
+       
+       if (pb_width > it_width - NAME_X_OFFSET) {
+               pb_width = it_width - NAME_X_OFFSET;
+       }
+       
+       if (pb_width <= 0 || it_width <= NAME_X_OFFSET) {
+               name_pixbuf->hide();
+               return;
+       } else {
+               name_pixbuf->show();
+       }
+
+       name_pixbuf->property_pixbuf() = pixbuf_from_ustring(item_name, NAME_FONT, pb_width, NAME_HEIGHT);
 }