From b45b8440047bb6a277efd7fe2ad7b937615c993b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 5 Dec 2006 04:56:24 +0000 Subject: [PATCH] 2006-12-05 Emmanuele Bassi * clutter/clutter-color.h: * clutter/clutter-color.c: Add clutter_color_parse(), which parses a string containing a color definition as understood by XParseColor() (or pango_color_parse()). --- ChangeLog | 7 ++++++ clutter/clutter-color.c | 42 +++++++++++++++++++++++++++++++++ clutter/clutter-color.h | 52 +++++++++++++++++++++-------------------- 3 files changed, 76 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74615a35d..f66603075 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-12-05 Emmanuele Bassi + + * clutter/clutter-color.h: + * clutter/clutter-color.c: Add clutter_color_parse(), + which parses a string containing a color definition as + understood by XParseColor() (or pango_color_parse()). + 2006-12-04 Emmanuele Bassi Avoid clutter segfaulting when used without invoking diff --git a/clutter/clutter-color.c b/clutter/clutter-color.c index b565b7795..afac4eb78 100644 --- a/clutter/clutter-color.c +++ b/clutter/clutter-color.c @@ -34,7 +34,10 @@ #include "config.h" #endif +#include "clutter-main.h" #include "clutter-color.h" +#include "clutter-private.h" +#include "clutter-debug.h" /** * clutter_color_add: @@ -374,6 +377,45 @@ clutter_color_from_pixel (ClutterColor *dest, dest->alpha = pixel % 0xff; } +/** + * clutter_color_parse: + * @color: a string specifiying a color + * @dest: return location for a #ClutterColor + * + * Parses a string definition of a color, filling the + * red, green and + * blue channels of @dest. The + * alpha channel is not changed. The + * color in @dest is not allocated. + * + * The color may be defined by any of the formats understood by + * XParseColor; these include literal color + * names, like Red or DarkSlateGray, + * or hexadecimal specifications like #3050b2 or + * #333. + * + * Return value: %TRUE if parsing succeeded. + * + * Since: 0.2 + */ +gboolean +clutter_color_parse (const gchar *color, + ClutterColor *dest) +{ + PangoColor pango_color; + + if (pango_color_parse (&pango_color, color)) + { + dest->red = pango_color.red; + dest->green = pango_color.green; + dest->blue = pango_color.blue; + + return TRUE; + } + else + return FALSE; +} + static ClutterColor * clutter_color_copy (ClutterColor *color) { diff --git a/clutter/clutter-color.h b/clutter/clutter-color.h index 31850ea03..c927a2b3f 100644 --- a/clutter/clutter-color.h +++ b/clutter/clutter-color.h @@ -43,35 +43,37 @@ struct _ClutterColor guint8 alpha; }; -GType clutter_color_get_type (void) G_GNUC_CONST; +GType clutter_color_get_type (void) G_GNUC_CONST; -void clutter_color_add (const ClutterColor *src1, - const ClutterColor *src2, - ClutterColor *dest); -void clutter_color_subtract (const ClutterColor *src1, - const ClutterColor *src2, - ClutterColor *dest); +gboolean clutter_color_parse (const gchar *color, + ClutterColor *dest); +void clutter_color_add (const ClutterColor *src1, + const ClutterColor *src2, + ClutterColor *dest); +void clutter_color_subtract (const ClutterColor *src1, + const ClutterColor *src2, + ClutterColor *dest); -void clutter_color_lighten (const ClutterColor *src, - ClutterColor *dest); -void clutter_color_darken (const ClutterColor *src, - ClutterColor *dest); -void clutter_color_shade (const ClutterColor *src, - ClutterColor *dest, - gdouble shade); +void clutter_color_lighten (const ClutterColor *src, + ClutterColor *dest); +void clutter_color_darken (const ClutterColor *src, + ClutterColor *dest); +void clutter_color_shade (const ClutterColor *src, + ClutterColor *dest, + gdouble shade); -void clutter_color_to_hls (const ClutterColor *src, - guint8 *hue, - guint8 *luminance, - guint8 *saturation); -void clutter_color_from_hls (ClutterColor *dest, - guint8 hue, - guint8 luminance, - guint8 saturation); +void clutter_color_to_hls (const ClutterColor *src, + guint8 *hue, + guint8 *luminance, + guint8 *saturation); +void clutter_color_from_hls (ClutterColor *dest, + guint8 hue, + guint8 luminance, + guint8 saturation); -guint32 clutter_color_to_pixel (const ClutterColor *src); -void clutter_color_from_pixel (ClutterColor *dest, - guint32 pixel); +guint32 clutter_color_to_pixel (const ClutterColor *src); +void clutter_color_from_pixel (ClutterColor *dest, + guint32 pixel); G_END_DECLS