mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 15:54:57 +01:00
move contrasting_text_color() into ArdourCanvas
This commit is contained in:
parent
4c1f4011fd
commit
471570705d
6 changed files with 37 additions and 35 deletions
|
|
@ -114,7 +114,7 @@ EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
|
||||||
cairo_text_extents_t ext;
|
cairo_text_extents_t ext;
|
||||||
cairo_text_extents (cr, tab.group->name().c_str(), &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);
|
ArdourCanvas::color_to_rgba (c, r, g, b, a);
|
||||||
|
|
||||||
cairo_set_source_rgb (cr, r, g, b);
|
cairo_set_source_rgb (cr, r, g, b);
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
|
||||||
cairo_text_extents_t ext;
|
cairo_text_extents_t ext;
|
||||||
cairo_text_extents (cr, tab.group->name().c_str(), &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);
|
ArdourCanvas::color_to_rgba (c, r, g, b, a);
|
||||||
|
|
||||||
cairo_set_source_rgb (cr, r, g, b);
|
cairo_set_source_rgb (cr, r, g, b);
|
||||||
|
|
|
||||||
|
|
@ -699,7 +699,7 @@ TimeAxisViewItem::set_name_text_color ()
|
||||||
f = get_fill_color ();
|
f = get_fill_color ();
|
||||||
}
|
}
|
||||||
|
|
||||||
name_text->set_color (contrasting_text_color (f));
|
name_text->set_color (ArdourCanvas::contrasting_text_color (f));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
|
||||||
|
|
@ -402,38 +402,6 @@ ARDOUR_UI_UTILS::gdk_color_to_rgba (Gdk::Color const& c)
|
||||||
return RGBA_TO_UINT (r,g,b,a);
|
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
|
bool
|
||||||
ARDOUR_UI_UTILS::relay_key_press (GdkEventKey* ev, Gtk::Window* win)
|
ARDOUR_UI_UTILS::relay_key_press (GdkEventKey* ev, Gtk::Window* win)
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,7 @@ namespace ArdourCanvas {
|
||||||
extern LIBCANVAS_API void set_source_rgba (Cairo::RefPtr<Cairo::Context>, Color);
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,3 +220,35 @@ ArdourCanvas::distance_to_segment_squared (Duple const & p, Duple const & p1, Du
|
||||||
return ((dpqx * dpqx) + (dpqy * dpqy));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue