summaryrefslogtreecommitdiff
path: root/gtk2_ardour/time_axis_view_item.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-06-26 17:40:10 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-06-26 17:40:10 -0400
commit24acef66be9d94e7dee5f62c186271ac8053e46a (patch)
tree03040e1a891bf6328ed1d3e2370e35a41e392861 /gtk2_ardour/time_axis_view_item.cc
parent283e3ceb04286c2045236ff01bc2db6cf4c70957 (diff)
use W3C color difference computation to select black or white text for region name text
Diffstat (limited to 'gtk2_ardour/time_axis_view_item.cc')
-rw-r--r--gtk2_ardour/time_axis_view_item.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc
index d8d3cee807..24a1c711ba 100644
--- a/gtk2_ardour/time_axis_view_item.cc
+++ b/gtk2_ardour/time_axis_view_item.cc
@@ -728,6 +728,61 @@ TimeAxisViewItem::set_colors()
if (name_highlight) {
name_highlight->set_fill_color (fill_color);
}
+
+ if (name_text) {
+ double r, g, b, a;
+
+ const double black_r = 0.0;
+ const double black_g = 0.0;
+ const double black_b = 0.0;
+
+ const double white_r = 1.0;
+ const double white_g = 1.0;
+ const double white_b = 1.0;
+
+ ArdourCanvas::color_to_rgba (fill_color, r, g, b, a);
+
+ /* Use W3C contrast guideline calculation */
+
+ double white_contrast = (max (r, white_r) - min (r, white_r)) +
+ (max (g, white_g) - min (g, white_g)) +
+ (max (b, white_b) - min (b, white_b));
+
+ double black_contrast = (max (r, black_r) - min (r, black_r)) +
+ (max (g, black_g) - min (g, black_g)) +
+ (max (b, black_b) - min (b, black_b));
+
+ if (white_contrast > black_contrast) {
+ /* use white */
+ name_text->set_color (ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0));
+ } else {
+ /* use black */
+ name_text->set_color (ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0));
+ }
+
+#if 0
+ double h, s, v;
+
+ ArdourCanvas::color_to_hsv (fill_color, h, s, v);
+
+ if (v == 0.0) {
+ /* fill is black, set text to white */
+ name_text->set_color (ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0));
+ } else if (v == 1.0) {
+ /* fill is white, set text to black */
+ name_text->set_color (ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0));
+ } else {
+
+ h = fabs (fmod ((h - 180), 360.0)); /* complementary color */
+ s = 1.0; /* fully saturate */
+ v = 0.9; /* increase lightness/brightness/value */
+
+ name_text->set_color (ArdourCanvas::hsv_to_color (h, s, v, 1.0));
+ }
+#endif
+
+ }
+
set_trim_handle_colors();
}