extend ArdourButton API to allow independently setting fixed active/inactive colors
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 9 Jun 2016 19:35:37 +0000 (15:35 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 9 Jun 2016 20:03:14 +0000 (16:03 -0400)
gtk2_ardour/ardour_button.cc
gtk2_ardour/ardour_button.h

index 305956ff5905ecdeb412054b3aa1d481ba16ceab..0fa53c53728175152b7f0b98ed8bee37d34fa4f9 100644 (file)
@@ -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);
+}
+
+void ArdourButton::set_active_color (const uint32_t color)
+{
+       _fixed_colors_set |= 0x1;
 
-       fill_active_color = color_active;
-       fill_inactive_color = color_inactive;
+       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 ();
+}
+
+void ArdourButton::set_inactive_color (const uint32_t color)
+{
+       _fixed_colors_set |= 0x2;
 
-       UINT_TO_RGBA(color_inactive, &r, &g, &b, &a);
+       fill_inactive_color = color;
 
-       white_contrast = (max (double(r), 255.) - min (double(r), 255.)) +
+       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.));
 
index 25986ccc0c8bb4ea7afcfb970d0dc6c4367a2fe2..928f4a8355e581e14e59d43f7a35cfc9db48a200 100644 (file)
@@ -104,7 +104,9 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
 
        void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
 
-       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;