X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Fpixfader.cc;h=f4e362bca1b6ec0b3670d3a110354c8fa9cd2bad;hb=93349141379343c91ea0ec2127d694f6cf2e230e;hp=1f963fbdda29da123d466ce48cc532725e7cd9a8;hpb=b4abc10f716f1ec8d85d8f82b2aa97c11e03bb0c;p=ardour.git diff --git a/libs/gtkmm2ext/pixfader.cc b/libs/gtkmm2ext/pixfader.cc index 1f963fbdda..f4e362bca1 100644 --- a/libs/gtkmm2ext/pixfader.cc +++ b/libs/gtkmm2ext/pixfader.cc @@ -21,6 +21,8 @@ #include +#include "pbd/stacktrace.h" + #include "gtkmm2ext/pixfader.h" #include "gtkmm2ext/keyboard.h" #include "gtkmm2ext/rgb_macros.h" @@ -106,6 +108,10 @@ PixFader::create_patterns () float radius = CORNER_RADIUS; double w = get_width(); + + if (w <= 1 || get_height() <= 1) { + return; + } if ((pattern = find_pattern (fr, fg, fb, br, bg, bb, get_width(), get_height())) != 0) { /* found it - use it */ @@ -184,13 +190,35 @@ PixFader::on_expose_event (GdkEventExpose* ev) Cairo::RefPtr context = get_window()->create_cairo_context(); cairo_t* cr = context->cobj(); - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_clip (cr); - if (!pattern) { create_patterns(); } - + + if (!pattern) { + + /* this isn't supposed to be happen, but some wackiness whereby + the pixfader ends up with a 1xN or Nx1 size allocation + leads to it. the basic wackiness needs fixing but we + shouldn't crash. just fill in the expose area with + our bg color. + */ + + Gdk::Color c = get_style()->get_bg (get_state()); + float br, bg, bb; + + br = c.get_red_p (); + bg = c.get_green_p (); + bb = c.get_blue_p (); + cairo_set_source_rgb (cr, br, bg, bb); + cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); + cairo_fill (cr); + + return true; + } + + cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); + cairo_clip (cr); + int ds = display_span (); float w = get_width(); float h = get_height(); @@ -254,12 +282,11 @@ PixFader::on_expose_event (GdkEventExpose* ev) } } } - - if ( !_text.empty() ) { - cairo_new_path (cr); + if ( !_text.empty() ) { /* center text */ + cairo_new_path (cr); cairo_move_to (cr, (get_width() - _text_width)/2.0, get_height()/2.0 - _text_height/2.0); cairo_set_source_rgba (cr, text_r, text_g, text_b, 0.9); pango_cairo_show_layout (cr, _layout->gobj()); @@ -282,11 +309,11 @@ void PixFader::on_size_request (GtkRequisition* req) { if (_orien == VERT) { - req->width = girth; - req->height = span; + req->width = (girth ? girth : -1); + req->height = (span ? span : -1); } else { - req->height = girth; - req->width = span; + req->height = (girth ? girth : -1); + req->width = (span ? span : -1); } } @@ -303,12 +330,12 @@ PixFader::on_size_allocate (Gtk::Allocation& alloc) span = alloc.get_width (); } - update_unity_position (); - if (is_realized()) { - create_patterns(); - queue_draw (); + /* recreate patterns in case we've changed size */ + create_patterns (); } + + update_unity_position (); } bool @@ -513,14 +540,6 @@ PixFader::display_span () return ds; } -void -PixFader::set_fader_length (int l) -{ - span = l; - update_unity_position (); - queue_resize (); -} - void PixFader::update_unity_position () { @@ -594,3 +613,19 @@ PixFader::on_state_changed (Gtk::StateType old_state) Widget::on_state_changed (old_state); create_patterns (); } + +void +PixFader::on_style_changed (const Glib::RefPtr&) +{ + if (_layout) { + std::string txt = _layout->get_text(); + _layout.clear (); // drop reference to existing layout + set_text (txt); + } + + /* remember that all patterns are cached and not owned by an individual + pixfader. we will lazily create a new pattern when needed. + */ + + pattern = 0; +}