From ef6f0de5a31bd14a4d48e806b3b56b2845ebd690 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 9 Jun 2016 15:35:37 -0400 Subject: [PATCH] extend ArdourButton API to allow independently setting fixed active/inactive colors --- gtk2_ardour/ardour_button.cc | 50 ++++++++++++++++++++++++++---------- gtk2_ardour/ardour_button.h | 6 +++-- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc index 305956ff59..0fa53c5372 100644 --- a/gtk2_ardour/ardour_button.cc +++ b/gtk2_ardour/ardour_button.cc @@ -619,19 +619,26 @@ void ArdourButton::set_colors () { _update_colors = false; - if (_fixed_colors_set) { + + if (_fixed_colors_set == 0x3) { return; } + std::string name = get_name(); bool failed = false; - fill_active_color = UIConfiguration::instance().color (string_compose ("%1: fill active", name), &failed); - if (failed) { - fill_active_color = UIConfiguration::instance().color ("generic button: fill active"); + if (!(_fixed_colors_set & 0x1)) { + fill_active_color = UIConfiguration::instance().color (string_compose ("%1: fill active", name), &failed); + if (failed) { + fill_active_color = UIConfiguration::instance().color ("generic button: fill active"); + } } - fill_inactive_color = UIConfiguration::instance().color (string_compose ("%1: fill", name), &failed); - if (failed) { - fill_inactive_color = UIConfiguration::instance().color ("generic button: fill"); + + if (!(_fixed_colors_set & 0x2)) { + fill_inactive_color = UIConfiguration::instance().color (string_compose ("%1: fill", name), &failed); + if (failed) { + fill_inactive_color = UIConfiguration::instance().color ("generic button: fill"); + } } text_active_color = ArdourCanvas::contrasting_text_color (fill_active_color); @@ -659,13 +666,18 @@ ArdourButton::set_colors () */ void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t color_inactive) { - _fixed_colors_set = true; + set_active_color (color_active); + set_inactive_color (color_inactive); +} - fill_active_color = color_active; - fill_inactive_color = color_inactive; +void ArdourButton::set_active_color (const uint32_t color) +{ + _fixed_colors_set |= 0x1; + + fill_active_color = color; unsigned char r, g, b, a; - UINT_TO_RGBA(color_active, &r, &g, &b, &a); + UINT_TO_RGBA(color, &r, &g, &b, &a); double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + (max (double(g), 255.) - min (double(g), 255.)) + @@ -679,14 +691,24 @@ void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t RGBA_TO_UINT(255, 255, 255, 255) : /* use white */ RGBA_TO_UINT( 0, 0, 0, 255); /* use black */ + /* XXX what about led colors ? */ + CairoWidget::set_dirty (); +} - UINT_TO_RGBA(color_inactive, &r, &g, &b, &a); +void ArdourButton::set_inactive_color (const uint32_t color) +{ + _fixed_colors_set |= 0x2; - white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + + fill_inactive_color = color; + + unsigned char r, g, b, a; + UINT_TO_RGBA(color, &r, &g, &b, &a); + + double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + (max (double(g), 255.) - min (double(g), 255.)) + (max (double(b), 255.) - min (double(b), 255.)); - black_contrast = (max (double(r), 0.) - min (double(r), 0.)) + + double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) + (max (double(g), 0.) - min (double(g), 0.)) + (max (double(b), 0.) - min (double(b), 0.)); diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h index 25986ccc0c..928f4a8355 100644 --- a/gtk2_ardour/ardour_button.h +++ b/gtk2_ardour/ardour_button.h @@ -104,7 +104,9 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable void set_image (const Glib::RefPtr&); - void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color); + void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color); + void set_active_color (const uint32_t active_color); + void set_inactive_color (const uint32_t inactive_color); void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; } @@ -172,7 +174,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable bool _distinct_led_click; bool _hovering; bool _focused; - bool _fixed_colors_set; + int _fixed_colors_set; bool _fallthrough_to_parent; int _layout_ellipsize_width; Pango::EllipsizeMode _ellipsis;