theme: Add helper functions for light/dark colors

GtkStyleContext no longer has dark/light colors GtkStyle used to
have. We already have compatibility code for them in theme.c, so
add two helper functions to make it available outside theme.c.

https://bugzilla.gnome.org/show_bug.cgi?id=650586
This commit is contained in:
Florian Müllner 2011-05-18 21:22:03 +02:00
parent e16beba111
commit f8d900c3ea
2 changed files with 47 additions and 28 deletions

View File

@ -1217,6 +1217,13 @@ const char* meta_gtk_arrow_to_string (GtkArrowType a
MetaImageFillType meta_image_fill_type_from_string (const char *str);
const char* meta_image_fill_type_to_string (MetaImageFillType fill_type);
void meta_gtk_style_get_light_color (GtkStyleContext *style,
GtkStateFlags state,
GdkRGBA *color);
void meta_gtk_style_get_dark_color (GtkStyleContext *style,
GtkStateFlags state,
GdkRGBA *color);
guint meta_theme_earliest_version_with_button (MetaButtonType type);

View File

@ -1415,12 +1415,31 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component,
/* Based on set_color() in gtkstyle.c */
#define LIGHTNESS_MULT 1.3
#define DARKNESS_MULT 0.7
void
meta_gtk_style_get_light_color (GtkStyleContext *style,
GtkStateFlags state,
GdkRGBA *color)
{
gtk_style_context_get_background_color (style, state, color);
gtk_style_shade (color, color, LIGHTNESS_MULT);
}
void
meta_gtk_style_get_dark_color (GtkStyleContext *style,
GtkStateFlags state,
GdkRGBA *color)
{
gtk_style_context_get_background_color (style, state, color);
gtk_style_shade (color, color, DARKNESS_MULT);
}
static void
meta_set_color_from_style (GdkRGBA *color,
GtkStyleContext *context,
GtkStateType state,
MetaGtkColorComponent component)
{
GdkRGBA other;
GtkStateFlags flags;
switch (state)
@ -1445,45 +1464,38 @@ meta_set_color_from_style (GdkRGBA *color,
{
case META_GTK_COLOR_BG:
case META_GTK_COLOR_BASE:
case META_GTK_COLOR_MID:
case META_GTK_COLOR_LIGHT:
case META_GTK_COLOR_DARK:
gtk_style_context_get_background_color (context, flags, color);
break;
case META_GTK_COLOR_FG:
case META_GTK_COLOR_TEXT:
gtk_style_context_get_color (context, flags, color);
break;
case META_GTK_COLOR_TEXT_AA:
gtk_style_context_get_color (context, flags, color);
meta_set_color_from_style (&other, context, state, META_GTK_COLOR_BASE);
color->red = (color->red + other.red) / 2;
color->green = (color->green + other.green) / 2;
color->blue = (color->blue + other.blue) / 2;
break;
case META_GTK_COLOR_MID:
meta_gtk_style_get_light_color (context, flags, color);
meta_gtk_style_get_dark_color (context, flags, &other);
color->red = (color->red + other.red) / 2;
color->green = (color->green + other.green) / 2;
color->blue = (color->blue + other.blue) / 2;
break;
case META_GTK_COLOR_LIGHT:
meta_gtk_style_get_light_color (context, flags, color);
break;
case META_GTK_COLOR_DARK:
meta_gtk_style_get_dark_color (context, flags, color);
break;
case META_GTK_COLOR_LAST:
g_assert_not_reached ();
break;
}
if (component == META_GTK_COLOR_LIGHT)
gtk_style_shade (color, color, LIGHTNESS_MULT);
else if (component == META_GTK_COLOR_DARK)
gtk_style_shade (color, color, DARKNESS_MULT);
else if (component == META_GTK_COLOR_MID)
{
GdkRGBA light, dark;
gtk_style_shade (color, &light, LIGHTNESS_MULT);
gtk_style_shade (color, &dark, DARKNESS_MULT);
color->red = (light.red + dark.red) / 2;
color->green = (light.green + dark.green) / 2;
color->blue = (light.blue + dark.blue) / 2;
}
else if (component == META_GTK_COLOR_TEXT_AA)
{
GdkRGBA base;
meta_set_color_from_style (&base, context, state, META_GTK_COLOR_BASE);
color->red = (color->red + base.red) / 2;
color->green = (color->green + base.green) / 2;
color->blue = (color->blue + base.blue) / 2;
}
}
void