[mutter] theme: Add helper functions for light/dark colors
- From: Florian MÃllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] theme: Add helper functions for light/dark colors
- Date: Fri, 8 Jul 2011 19:41:59 +0000 (UTC)
commit f8d900c3eae9ea9c028ff663e7451b0e888969e9
Author: Florian MÃllner <fmuellner gnome org>
Date: Wed May 18 21:22:03 2011 +0200
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
src/ui/theme-private.h | 7 +++++
src/ui/theme.c | 68 ++++++++++++++++++++++++++++-------------------
2 files changed, 47 insertions(+), 28 deletions(-)
---
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 92b9b21..b2e7bb4 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -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);
diff --git a/src/ui/theme.c b/src/ui/theme.c
index f040790..e9f6883 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]