From bd3af3454b5f3e12562d9d28085c512415994215 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 3 Feb 2012 04:17:25 +0000 Subject: [PATCH] allow specification (partially) of which corners of an ArdourButton are rounded git-svn-id: svn://localhost/ardour2/branches/3.0@11435 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_button.cc | 37 +++++++++++++++++++++++++++++++----- gtk2_ardour/ardour_button.h | 2 ++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc index 55e94a996e..538ab3a442 100644 --- a/gtk2_ardour/ardour_button.cc +++ b/gtk2_ardour/ardour_button.cc @@ -57,6 +57,7 @@ ArdourButton::ArdourButton (Element e) , _text_height (0) , _diameter (11.0) , _corner_radius (9.0) + , _corner_mask (0xf) , edge_pattern (0) , fill_pattern (0) , led_inset_pattern (0) @@ -128,21 +129,40 @@ ArdourButton::set_markup (const std::string& str) void ArdourButton::render (cairo_t* cr) { + void (*rounded_function)(cairo_t*, double, double, double, double, double); + + switch (_corner_mask) { + case 0x1: /* upper left only */ + rounded_function = Gtkmm2ext::rounded_top_left_rectangle; + break; + case 0x2: /* upper right only */ + rounded_function = Gtkmm2ext::rounded_top_right_rectangle; + break; + case 0x3: /* upper only */ + rounded_function = Gtkmm2ext::rounded_top_rectangle; + break; + /* should really have functions for lower right, lower left, + lower only, but for now, we don't + */ + default: + rounded_function = Gtkmm2ext::rounded_rectangle; + } + if (!_fixed_diameter) { _diameter = std::min (get_width(), get_height()); } if (_elements & Edge) { - Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), _corner_radius); + rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius); cairo_set_source (cr, edge_pattern); cairo_fill (cr); } if (_elements & Body) { if (_elements & Edge) { - Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width()-2, get_height()-2, _corner_radius - 1.0); + rounded_function (cr, 1, 1, get_width()-2, get_height()-2, _corner_radius - 1.0); } else { - Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), _corner_radius - 1.0); + rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius - 1.0); } cairo_set_source (cr, fill_pattern); cairo_fill (cr); @@ -232,7 +252,7 @@ ArdourButton::render (cairo_t* cr) /* a partially transparent gray layer to indicate insensitivity */ if ((visual_state() & Gtkmm2ext::Insensitive)) { - Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), _corner_radius); + rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius); cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.5); cairo_fill (cr); } @@ -241,7 +261,7 @@ ArdourButton::render (cairo_t* cr) if (ARDOUR::Config->get_widget_prelight()) { if (_hovering) { - Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), _corner_radius); + rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius); cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2); cairo_fill (cr); } @@ -695,3 +715,10 @@ ArdourButton::action_tooltip_changed () string str = _action->property_tooltip().get_value(); ARDOUR_UI::instance()->set_tip (*this, str); } + +void +ArdourButton::set_rounded_corner_mask (int mask) +{ + _corner_mask = mask; + queue_draw (); +} diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h index 78ff66b7a6..94f75fb5da 100644 --- a/gtk2_ardour/ardour_button.h +++ b/gtk2_ardour/ardour_button.h @@ -62,6 +62,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable Element elements() const { return _elements; } void set_corner_radius (float); + void set_rounded_corner_mask (int); void set_diameter (float); void set_text (const std::string&); @@ -109,6 +110,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable int _text_height; float _diameter; float _corner_radius; + int _corner_mask; cairo_pattern_t* edge_pattern; cairo_pattern_t* fill_pattern;