- start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start active", get_name()));
-
- if (_flat_buttons) {
- end_color = start_color;
- } else {
- end_color = fill_color_active;
- }
- UINT_TO_RGBA (start_color, &r, &g, &b, &a);
-
- active_r = r/255.0;
- active_g = g/255.0;
- active_b = b/255.0;
- active_a = a/255.0;
-
- 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.5, 1,1,1,0.1);
- cairo_pattern_add_color_stop_rgba (shine_pattern, 0.7, 1,1,1,0.2);
- cairo_pattern_add_color_stop_rgba (shine_pattern, 1, 1,1,1,0.1);
-
- fill_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()-3);
- if (_flat_buttons) {
- end_color = start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end", get_name()));
- } else {
- start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start", get_name()));
- end_color = fill_color_inactive;
- }
- UINT_TO_RGBA (start_color, &r, &g, &b, &a);
- cairo_pattern_add_color_stop_rgba (fill_pattern, 0, r/255.0,g/255.0,b/255.0, a/255.0);
- UINT_TO_RGBA (end_color, &r, &g, &b, &a);
- cairo_pattern_add_color_stop_rgba (fill_pattern, 1, r/255.0,g/255.0,b/255.0, a/255.0);
-
- fill_pattern_active = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()-3);
- if (_flat_buttons) {
- if (active_state() == Gtkmm2ext::ImplicitActive && (_tweaks & ImplicitUsesSolidColor)) {
- end_color = start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led active", get_name()));
- } else {
- end_color = start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end active", get_name()));
- }
- } else {
- if (active_state() == Gtkmm2ext::ImplicitActive && (_tweaks & ImplicitUsesSolidColor)) {
- start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led", get_name()));
- end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led active", get_name()));
- } else {
- start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start active", get_name()));
- end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end active", get_name()));
- }
- }
- UINT_TO_RGBA (start_color, &r, &g, &b, &a);
- cairo_pattern_add_color_stop_rgba (fill_pattern_active, 0, r/255.0,g/255.0,b/255.0, a/255.0);
- UINT_TO_RGBA (end_color, &r, &g, &b, &a);
- cairo_pattern_add_color_stop_rgba (fill_pattern_active, 1, r/255.0,g/255.0,b/255.0, a/255.0);
+ fill_active_color = color_active;
+ fill_inactive_color = color_inactive;
+
+ unsigned char r, g, b, a;
+ UINT_TO_RGBA(color_active, &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.));
+
+ 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.));
+
+ text_active_color = (white_contrast > black_contrast) ?
+ RGBA_TO_UINT(255, 255, 255, 255) : /* use white */
+ RGBA_TO_UINT( 0, 0, 0, 255); /* use black */
+
+
+ UINT_TO_RGBA(color_inactive, &r, &g, &b, &a);
+
+ 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.)) +
+ (max (double(g), 0.) - min (double(g), 0.)) +
+ (max (double(b), 0.) - min (double(b), 0.));
+
+ text_inactive_color = (white_contrast > black_contrast) ?
+ 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::build_patterns ()
+{
+ if (convex_pattern) {
+ cairo_pattern_destroy (convex_pattern);
+ convex_pattern = 0;
+ }
+
+ if (concave_pattern) {
+ cairo_pattern_destroy (concave_pattern);
+ concave_pattern = 0;