[gtk+/gtk-style-context: 107/251] GtkSymbolicColor: Add method to resolve to a GdkColor.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 107/251] GtkSymbolicColor: Add method to resolve to a GdkColor.
- Date: Tue, 12 Oct 2010 02:04:06 +0000 (UTC)
commit ddbc46c18b76d65837f7aabf6871ab39e5019054
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jun 25 19:39:15 2010 +0200
GtkSymbolicColor: Add method to resolve to a GdkColor.
gtk/gtkstyleset.h | 4 +++
gtk/gtksymboliccolor.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkstyleset.h b/gtk/gtkstyleset.h
index 88a11ae..a716edf 100644
--- a/gtk/gtkstyleset.h
+++ b/gtk/gtkstyleset.h
@@ -98,6 +98,10 @@ void gtk_style_set_merge (GtkStyleSet *set,
const GtkStyleSet *set_to_merge,
gboolean replace);
+gboolean gtk_symbolic_color_resolve (GtkSymbolicColor *color,
+ GtkStyleSet *style_set,
+ GdkColor *resolved_color);
+
G_END_DECLS
#endif /* __GTK_STYLE_PROPERTY_SET_H__ */
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index 7a8513d..bd33efa 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -136,6 +136,73 @@ gtk_symbolic_color_unref (GtkSymbolicColor *color)
color->ref_count--;
}
+gboolean
+gtk_symbolic_color_resolve (GtkSymbolicColor *color,
+ GtkStyleSet *style_set,
+ GdkColor *resolved_color)
+{
+ g_return_val_if_fail (color != NULL, FALSE);
+ g_return_val_if_fail (GTK_IS_STYLE_SET (style_set), FALSE);
+ g_return_val_if_fail (resolved_color != NULL, FALSE);
+
+ switch (color->type)
+ {
+ case COLOR_TYPE_LITERAL:
+ *resolved_color = color->color;
+ return TRUE;
+ case COLOR_TYPE_NAME:
+ {
+ GtkSymbolicColor *named_color;
+
+ named_color = gtk_style_set_lookup_color (style_set, color->name);
+
+ if (!named_color)
+ return FALSE;
+
+ return gtk_symbolic_color_resolve (named_color, style_set, resolved_color);
+ }
+
+ break;
+ case COLOR_TYPE_SHADE:
+ {
+ GdkColor shade;
+
+ if (!gtk_symbolic_color_resolve (color->shade.color, style_set, &shade))
+ return FALSE;
+
+ resolved_color->red = CLAMP (shade.red * color->shade.factor, 0, 65535);
+ resolved_color->green = CLAMP (shade.green * color->shade.factor, 0, 65535);
+ resolved_color->blue = CLAMP (shade.blue * color->shade.factor, 0, 65535);
+
+ return TRUE;
+ }
+
+ break;
+ case COLOR_TYPE_MIX:
+ {
+ GdkColor color1, color2;
+
+ if (!gtk_symbolic_color_resolve (color->mix.color1, style_set, &color1))
+ return FALSE;
+
+ if (!gtk_symbolic_color_resolve (color->mix.color2, style_set, &color2))
+ return FALSE;
+
+ resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 65535);
+ resolved_color->green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 65535);
+ resolved_color->blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 65535);
+
+ return TRUE;
+ }
+
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ return FALSE;
+}
+
GType
gtk_symbolic_color_get_type (void)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]