summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk2_ardour/editor_group_tabs.cc2
-rw-r--r--gtk2_ardour/mixer_group_tabs.cc2
-rw-r--r--gtk2_ardour/time_axis_view_item.cc2
-rw-r--r--gtk2_ardour/utils.cc32
-rw-r--r--libs/canvas/canvas/utils.h2
-rw-r--r--libs/canvas/utils.cc32
6 files changed, 37 insertions, 35 deletions
diff --git a/gtk2_ardour/editor_group_tabs.cc b/gtk2_ardour/editor_group_tabs.cc
index af5e63bd55..fff113a7e2 100644
--- a/gtk2_ardour/editor_group_tabs.cc
+++ b/gtk2_ardour/editor_group_tabs.cc
@@ -114,7 +114,7 @@ EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
cairo_text_extents_t ext;
cairo_text_extents (cr, tab.group->name().c_str(), &ext);
- ArdourCanvas::Color c = contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a));
+ ArdourCanvas::Color c = ArdourCanvas::contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a));
ArdourCanvas::color_to_rgba (c, r, g, b, a);
cairo_set_source_rgb (cr, r, g, b);
diff --git a/gtk2_ardour/mixer_group_tabs.cc b/gtk2_ardour/mixer_group_tabs.cc
index 7f9f1f0e53..03e9409df2 100644
--- a/gtk2_ardour/mixer_group_tabs.cc
+++ b/gtk2_ardour/mixer_group_tabs.cc
@@ -121,7 +121,7 @@ MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
cairo_text_extents_t ext;
cairo_text_extents (cr, tab.group->name().c_str(), &ext);
- ArdourCanvas::Color c = contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a));
+ ArdourCanvas::Color c = ArdourCanvas::contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a));
ArdourCanvas::color_to_rgba (c, r, g, b, a);
cairo_set_source_rgb (cr, r, g, b);
diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc
index c46b7941e0..009dda1e67 100644
--- a/gtk2_ardour/time_axis_view_item.cc
+++ b/gtk2_ardour/time_axis_view_item.cc
@@ -699,7 +699,7 @@ TimeAxisViewItem::set_name_text_color ()
f = get_fill_color ();
}
- name_text->set_color (contrasting_text_color (f));
+ name_text->set_color (ArdourCanvas::contrasting_text_color (f));
}
uint32_t
diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc
index 4c654ee418..417e950431 100644
--- a/gtk2_ardour/utils.cc
+++ b/gtk2_ardour/utils.cc
@@ -402,38 +402,6 @@ ARDOUR_UI_UTILS::gdk_color_to_rgba (Gdk::Color const& c)
return RGBA_TO_UINT (r,g,b,a);
}
-uint32_t
-ARDOUR_UI_UTILS::contrasting_text_color (uint32_t c)
-{
- double r, g, b, a;
- ArdourCanvas::color_to_rgba (c, 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;
-
- /* 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 */
- return ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0);
- } else {
- /* use black */
- return ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0);
- }
-}
bool
ARDOUR_UI_UTILS::relay_key_press (GdkEventKey* ev, Gtk::Window* win)
diff --git a/libs/canvas/canvas/utils.h b/libs/canvas/canvas/utils.h
index cd9d884475..e269ca215c 100644
--- a/libs/canvas/canvas/utils.h
+++ b/libs/canvas/canvas/utils.h
@@ -31,5 +31,7 @@ namespace ArdourCanvas {
extern LIBCANVAS_API void set_source_rgba (Cairo::RefPtr<Cairo::Context>, Color);
Distance LIBCANVAS_API distance_to_segment_squared (Duple const & p, Duple const & p1, Duple const & p2, double& t, Duple& at);
+
+ uint32_t LIBCANVAS_API contrasting_text_color (uint32_t c);
}
diff --git a/libs/canvas/utils.cc b/libs/canvas/utils.cc
index bdc8fad039..99516c849b 100644
--- a/libs/canvas/utils.cc
+++ b/libs/canvas/utils.cc
@@ -220,3 +220,35 @@ ArdourCanvas::distance_to_segment_squared (Duple const & p, Duple const & p1, Du
return ((dpqx * dpqx) + (dpqy * dpqy));
}
+uint32_t
+ArdourCanvas::contrasting_text_color (uint32_t c)
+{
+ double r, g, b, a;
+ ArdourCanvas::color_to_rgba (c, 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;
+
+ /* 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 */
+ return ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0);
+ } else {
+ /* use black */
+ return ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0);
+ }
+}