From 7922ec1e9a8db2cf23b286f1dd39bca942d5122d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 10 Jan 2013 16:25:31 +0000 Subject: [PATCH] remove rounded corners from non-mobile ends of pixfaders git-svn-id: svn://localhost/ardour2/branches/3.0@13828 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/gtkmm2ext/gtkmm2ext/utils.h | 8 ++++- libs/gtkmm2ext/pixfader.cc | 53 +++++++++++++++++++------------- libs/gtkmm2ext/utils.cc | 18 +++++++++++ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h index 1b0a9f5725..242e1c77d0 100644 --- a/libs/gtkmm2ext/gtkmm2ext/utils.h +++ b/libs/gtkmm2ext/gtkmm2ext/utils.h @@ -92,20 +92,26 @@ namespace Gtkmm2ext { int physical_screen_width (Glib::RefPtr); void container_clear (Gtk::Container&); + + /* C++ API for rounded rectangles */ + void rounded_rectangle (Cairo::RefPtr context, double x, double y, double w, double h, double r=10); void rounded_top_rectangle (Cairo::RefPtr context, double x, double y, double w, double h, double r=10); void rounded_top_left_rectangle (Cairo::RefPtr context, double x, double y, double w, double h, double r=10); void rounded_top_right_rectangle (Cairo::RefPtr context, double x, double y, double w, double h, double r=10); void rounded_top_half_rectangle (Cairo::RefPtr, double x, double y, double w, double h, double r=10); void rounded_bottom_half_rectangle (Cairo::RefPtr, double x, double y, double w, double h, double r=10); + void rounded_right_half_rectangle (Cairo::RefPtr, double x, double y, double w, double h, double r=10); + + /* C API for rounded rectangles */ void rounded_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); void rounded_top_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); void rounded_top_left_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); void rounded_top_right_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); - void rounded_top_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); void rounded_bottom_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); + void rounded_right_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10); Gtk::Label* left_aligned_label (std::string const &); diff --git a/libs/gtkmm2ext/pixfader.cc b/libs/gtkmm2ext/pixfader.cc index a4ea3456ab..c27fa680dd 100644 --- a/libs/gtkmm2ext/pixfader.cc +++ b/libs/gtkmm2ext/pixfader.cc @@ -43,8 +43,7 @@ PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length) dragging = false; default_value = adjustment.get_value(); last_drawn = -1; - - girth = 24; + girth = 23; set_fader_length (fader_length); @@ -85,11 +84,21 @@ PixFader::create_patterns () { Gdk::Color c = get_style()->get_fg (get_state()); float r, g, b; + + if (pattern) { + cairo_pattern_destroy (pattern); + } + + if (shine_pattern) { + cairo_pattern_destroy (shine_pattern); + } + r = c.get_red_p (); g = c.get_green_p (); b = c.get_blue_p (); if (_orien == VERT) { + pattern = cairo_pattern_create_linear (0.0, 0.0, get_width(), 0); cairo_pattern_add_color_stop_rgba (pattern, 0, r*0.8,g*0.8,b*0.8, 1.0); cairo_pattern_add_color_stop_rgba (pattern, 1, r*0.6,g*0.6,b*0.6, 1.0); @@ -99,14 +108,14 @@ PixFader::create_patterns () cairo_pattern_add_color_stop_rgba (shine_pattern, 0.2, 1,1,1,0.3); cairo_pattern_add_color_stop_rgba (shine_pattern, 0.5, 1,1,1,0.0); cairo_pattern_add_color_stop_rgba (shine_pattern, 1, 1,1,1,0.0); + } else { - float rheight = get_height(); - - pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, rheight); + + pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()); cairo_pattern_add_color_stop_rgba (pattern, 0, r*0.8,g*0.8,b*0.8, 1.0); cairo_pattern_add_color_stop_rgba (pattern, 1, r*0.6,g*0.6,b*0.6, 1.0); - shine_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, rheight); + shine_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()); cairo_pattern_add_color_stop_rgba (shine_pattern, 0, 1,1,1,0.0); cairo_pattern_add_color_stop_rgba (shine_pattern, 0.2, 1,1,1,0.3); cairo_pattern_add_color_stop_rgba (shine_pattern, 0.5, 1,1,1,0.0); @@ -119,7 +128,9 @@ PixFader::create_patterns () _text_width = 0; _text_height = 0; } + c = get_style()->get_text (get_state()); + text_r = c.get_red_p (); text_g = c.get_green_p (); text_b = c.get_blue_p (); @@ -152,43 +163,43 @@ PixFader::on_expose_event (GdkEventExpose*) /* draw active box */ if (_orien == VERT) { + if (ds > h - FADER_RESERVE) ds = h - FADER_RESERVE; cairo_set_source (cr, pattern); - Gtkmm2ext::rounded_rectangle (cr, 1, 1+ds, w-2, h-(1+ds)-1, radius-1.5); + Gtkmm2ext::rounded_top_half_rectangle (cr, 1, 1+ds, w-1, h-(1+ds)-1, radius-1.5); cairo_fill (cr); -// cairo_set_source (cr, shine_pattern); -// Gtkmm2ext::rounded_rectangle (cr, 2, ds, w-4, h-(1+ds)-1, radius-1.5); -// cairo_fill (cr); } else { + if (ds < FADER_RESERVE) ds = FADER_RESERVE; cairo_set_source (cr, pattern); - Gtkmm2ext::rounded_rectangle (cr, 1, 1, ds-1, h-2, radius-1.5); + Gtkmm2ext::rounded_right_half_rectangle (cr, 1, 1, ds-1, h-1, radius-1.5); cairo_fill (cr); -// cairo_set_source (cr, shine_pattern); -// Gtkmm2ext::rounded_rectangle (cr, 2, 3, ds-1, 15, radius-1.5); -// cairo_fill (cr); } /* draw the unity-position line if it's not at either end*/ if (unity_loc > 0) { - if ( _orien == VERT && unity_loc < h ) { + if ( _orien == VERT) { + if (unity_loc < h ) { context->set_line_width (1); context->set_source_rgb (0.0, 1.0, 0.0); context->move_to (1, unity_loc); context->line_to (girth, unity_loc); context->stroke (); - } else if ( unity_loc < w ){ - context->set_line_width (1); - context->set_source_rgb (0.0, 1.0, 0.0); - context->move_to (unity_loc, 1); - context->line_to (unity_loc, girth); - context->stroke (); + } + } else { + if ( unity_loc < w ){ + context->set_line_width (1); + context->set_source_rgb (0.0, 1.0, 0.0); + context->move_to (unity_loc, 1); + context->line_to (unity_loc, girth); + context->stroke (); + } } } diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index 61f93234ff..83ad4537a2 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -413,6 +413,11 @@ Gtkmm2ext::rounded_bottom_half_rectangle (Cairo::RefPtr context, { rounded_bottom_half_rectangle (context->cobj(), x, y, w, h, r); } +void +Gtkmm2ext::rounded_right_half_rectangle (Cairo::RefPtr context, double x, double y, double w, double h, double r) +{ + rounded_right_half_rectangle (context->cobj(), x, y, w, h, r); +} void Gtkmm2ext::rounded_rectangle (cairo_t* cr, double x, double y, double w, double h, double r) @@ -427,6 +432,19 @@ Gtkmm2ext::rounded_rectangle (cairo_t* cr, double x, double y, double w, double cairo_close_path (cr); } +void +Gtkmm2ext::rounded_right_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r) +{ + double degrees = M_PI / 180.0; + + cairo_new_sub_path (cr); + cairo_arc (cr, x + w - r, y + r, r, -90 * degrees, 0 * degrees); //tr + cairo_arc (cr, x + w - r, y + h - r, r, 0 * degrees, 90 * degrees); //br + cairo_line_to (cr, x, y + h); // bl + cairo_line_to (cr, x, y); // tl + cairo_close_path (cr); +} + void Gtkmm2ext::rounded_top_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r) {