4 * An OpenGL based 'interactive canvas' library.
6 * Authored By Matthew Allum <mallum@openedhand.com>
8 * Copyright (C) 2006 OpenedHand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
25 * SECTION:clutter-color
26 * @short_description: Color management and manipulation.
28 * #ClutterColor is a simple type for representing colors in Clutter.
30 * A #ClutterColor is expressed as a 4-tuple of values ranging from
31 * zero to 255, one for each color channel plus one for the alpha.
33 * The alpha channel is fully opaque at 255 and fully transparent at 0.
42 #include <pango/pango-attributes.h>
44 #include "clutter-interval.h"
45 #include "clutter-main.h"
46 #include "clutter-color.h"
47 #include "clutter-private.h"
48 #include "clutter-debug.h"
50 /* XXX - keep in sync with the ClutterStaticColor enumeration order */
51 static const ClutterColor const static_colors[] = {
52 /* CGA/EGA color palette */
53 { 0xff, 0xff, 0xff, 0xff }, /* white */
54 { 0x00, 0x00, 0x00, 0xff }, /* black */
55 { 0xff, 0x00, 0x00, 0xff }, /* red */
56 { 0x80, 0x00, 0x00, 0xff }, /* dark red */
57 { 0x00, 0xff, 0x00, 0xff }, /* green */
58 { 0x00, 0x80, 0x00, 0xff }, /* dark green */
59 { 0x00, 0x00, 0xff, 0xff }, /* blue */
60 { 0x00, 0x00, 0x80, 0xff }, /* dark blue */
61 { 0x00, 0xff, 0xff, 0xff }, /* cyan */
62 { 0x00, 0x80, 0x80, 0xff }, /* dark cyan */
63 { 0xff, 0x00, 0xff, 0xff }, /* magenta */
64 { 0x80, 0x00, 0x80, 0xff }, /* dark magenta */
65 { 0xff, 0xff, 0x00, 0xff }, /* yellow */
66 { 0x80, 0x80, 0x00, 0xff }, /* dark yellow */
67 { 0xa0, 0xa0, 0xa4, 0xff }, /* gray */
68 { 0x80, 0x80, 0x80, 0xff }, /* dark gray */
69 { 0xc0, 0xc0, 0xc0, 0xff }, /* light gray */
71 /* Tango Icon color palette */
72 { 0xed, 0xd4, 0x00, 0xff }, /* butter */
73 { 0xfc, 0xe9, 0x4f, 0xff }, /* butter light */
74 { 0xc4, 0xa0, 0x00, 0xff }, /* butter dark */
75 { 0xf5, 0x79, 0x00, 0xff }, /* orange */
76 { 0xfc, 0xaf, 0x3e, 0xff }, /* orange light */
77 { 0xce, 0x5c, 0x00, 0xff }, /* orange dark */
78 { 0xc1, 0x7d, 0x11, 0xff }, /* chocolate */
79 { 0xe9, 0xb9, 0x6e, 0xff }, /* chocolate light */
80 { 0x8f, 0x59, 0x02, 0xff }, /* chocolate dark */
81 { 0x73, 0xd2, 0x16, 0xff }, /* chameleon */
82 { 0x8a, 0xe2, 0x34, 0xff }, /* chameleon light */
83 { 0x4e, 0x9a, 0x06, 0xff }, /* chameleon dark */
84 { 0x34, 0x65, 0xa4, 0xff }, /* sky blue */
85 { 0x72, 0x9f, 0xcf, 0xff }, /* sky blue light */
86 { 0x20, 0x4a, 0x87, 0xff }, /* sky blue dark */
87 { 0x75, 0x50, 0x7b, 0xff }, /* plum */
88 { 0xad, 0x7f, 0xa8, 0xff }, /* plum light */
89 { 0x5c, 0x35, 0x66, 0xff }, /* plum dark */
90 { 0xcc, 0x00, 0x00, 0xff }, /* scarlet red */
91 { 0xef, 0x29, 0x29, 0xff }, /* scarlet red light */
92 { 0xa4, 0x00, 0x00, 0xff }, /* scarlet red dark */
93 { 0xee, 0xee, 0xec, 0xff }, /* aluminium 1 */
94 { 0xd3, 0xd7, 0xcf, 0xff }, /* aluminium 2 */
95 { 0xba, 0xbd, 0xb6, 0xff }, /* aluminium 3 */
96 { 0x88, 0x8a, 0x85, 0xff }, /* aluminium 4 */
97 { 0x55, 0x57, 0x53, 0xff }, /* aluminium 5 */
98 { 0x2e, 0x34, 0x36, 0xff }, /* aluminium 6 */
101 { 0x00, 0x00, 0x00, 0x00 } /* transparent */
105 * clutter_color_get_static:
106 * @color: the named global color
108 * Retrieves a static color for the given @color name
110 * Static colors are created by Clutter and are guaranteed to always be
111 * available and valid
113 * Return value: a pointer to a static color; the returned pointer
114 * is owned by Clutter and it should never be modified or freed
119 clutter_color_get_static (ClutterStaticColor color)
121 g_return_val_if_fail (color >= CLUTTER_COLOR_WHITE &&
122 color <= CLUTTER_COLOR_TRANSPARENT, NULL);
124 return &static_colors[color];
129 * @a: a #ClutterColor
130 * @b: a #ClutterColor
131 * @result: (out caller-allocates): return location for the result
133 * Adds @a to @b and saves the resulting color inside @result.
135 * The alpha channel of @result is set as as the maximum value
136 * between the alpha channels of @a and @b.
139 clutter_color_add (const ClutterColor *a,
140 const ClutterColor *b,
141 ClutterColor *result)
143 g_return_if_fail (a != NULL);
144 g_return_if_fail (b != NULL);
145 g_return_if_fail (result != NULL);
147 result->red = CLAMP (a->red + b->red, 0, 255);
148 result->green = CLAMP (a->green + b->green, 0, 255);
149 result->blue = CLAMP (a->blue + b->blue, 0, 255);
151 result->alpha = MAX (a->alpha, b->alpha);
155 * clutter_color_subtract:
156 * @a: a #ClutterColor
157 * @b: a #ClutterColor
158 * @result: (out caller-allocates): return location for the result
160 * Subtracts @b from @a and saves the resulting color inside @result.
162 * This function assumes that the components of @a are greater than the
163 * components of @b; the result is, otherwise, undefined.
165 * The alpha channel of @result is set as the minimum value
166 * between the alpha channels of @a and @b.
169 clutter_color_subtract (const ClutterColor *a,
170 const ClutterColor *b,
171 ClutterColor *result)
173 g_return_if_fail (a != NULL);
174 g_return_if_fail (b != NULL);
175 g_return_if_fail (result != NULL);
177 result->red = CLAMP (a->red - b->red, 0, 255);
178 result->green = CLAMP (a->green - b->green, 0, 255);
179 result->blue = CLAMP (a->blue - b->blue, 0, 255);
181 result->alpha = MIN (a->alpha, b->alpha);
185 * clutter_color_lighten:
186 * @color: a #ClutterColor
187 * @result: (out caller-allocates): return location for the lighter color
189 * Lightens @color by a fixed amount, and saves the changed color
193 clutter_color_lighten (const ClutterColor *color,
194 ClutterColor *result)
196 clutter_color_shade (color, 1.3, result);
200 * clutter_color_darken:
201 * @color: a #ClutterColor
202 * @result: (out caller-allocates): return location for the darker color
204 * Darkens @color by a fixed amount, and saves the changed color
208 clutter_color_darken (const ClutterColor *color,
209 ClutterColor *result)
211 clutter_color_shade (color, 0.7, result);
215 * clutter_color_to_hls:
216 * @color: a #ClutterColor
217 * @hue: (out): return location for the hue value or %NULL
218 * @luminance: (out): return location for the luminance value or %NULL
219 * @saturation: (out): return location for the saturation value or %NULL
221 * Converts @color to the HLS format.
223 * The @hue value is in the 0 .. 360 range. The @luminance and
224 * @saturation values are in the 0 .. 1 range.
227 clutter_color_to_hls (const ClutterColor *color,
232 float red, green, blue;
233 float min, max, delta;
236 g_return_if_fail (color != NULL);
238 red = color->red / 255.0;
239 green = color->green / 255.0;
240 blue = color->blue / 255.0;
274 s = (max - min) / (max + min);
276 s = (max - min) / (2.0 - max - min);
281 h = (green - blue) / delta;
282 else if (green == max)
283 h = 2.0 + (blue - red) / delta;
284 else if (blue == max)
285 h = 4.0 + (red - green) / delta;
304 * clutter_color_from_hls:
305 * @color: (out): return location for a #ClutterColor
306 * @hue: hue value, in the 0 .. 360 range
307 * @luminance: luminance value, in the 0 .. 1 range
308 * @saturation: saturation value, in the 0 .. 1 range
310 * Converts a color expressed in HLS (hue, luminance and saturation)
311 * values into a #ClutterColor.
314 clutter_color_from_hls (ClutterColor *color,
328 color->red = color->green = color->blue = (luminance * 255);
333 if (luminance <= 0.5)
334 tmp2 = luminance * (1.0 + saturation);
336 tmp2 = luminance + saturation - (luminance * saturation);
338 tmp1 = 2.0 * luminance - tmp2;
340 tmp3[0] = hue + 1.0 / 3.0;
342 tmp3[2] = hue - 1.0 / 3.0;
344 for (i = 0; i < 3; i++)
352 if (6.0 * tmp3[i] < 1.0)
353 clr[i] = tmp1 + (tmp2 - tmp1) * tmp3[i] * 6.0;
354 else if (2.0 * tmp3[i] < 1.0)
356 else if (3.0 * tmp3[i] < 2.0)
357 clr[i] = (tmp1 + (tmp2 - tmp1) * ((2.0 / 3.0) - tmp3[i]) * 6.0);
362 color->red = floorf (clr[0] * 255.0 + 0.5);
363 color->green = floorf (clr[1] * 255.0 + 0.5);
364 color->blue = floorf (clr[2] * 255.0 + 0.5);
368 * clutter_color_shade:
369 * @color: a #ClutterColor
370 * @factor: the shade factor to apply
371 * @result: (out caller-allocates): return location for the shaded color
373 * Shades @color by @factor and saves the modified color into @result.
376 clutter_color_shade (const ClutterColor *color,
378 ClutterColor *result)
382 g_return_if_fail (color != NULL);
383 g_return_if_fail (result != NULL);
385 clutter_color_to_hls (color, &h, &l, &s);
399 clutter_color_from_hls (result, h, l, s);
401 result->alpha = color->alpha;
405 * clutter_color_to_pixel:
406 * @color: a #ClutterColor
408 * Converts @color into a packed 32 bit integer, containing
409 * all the four 8 bit channels used by #ClutterColor.
411 * Return value: a packed color
414 clutter_color_to_pixel (const ClutterColor *color)
416 g_return_val_if_fail (color != NULL, 0);
418 return (color->alpha |
425 * clutter_color_from_pixel:
426 * @color: (out caller-allocates): return location for a #ClutterColor
427 * @pixel: a 32 bit packed integer containing a color
429 * Converts @pixel from the packed representation of a four 8 bit channel
430 * color to a #ClutterColor.
433 clutter_color_from_pixel (ClutterColor *color,
436 g_return_if_fail (color != NULL);
438 color->red = pixel >> 24;
439 color->green = (pixel >> 16) & 0xff;
440 color->blue = (pixel >> 8) & 0xff;
441 color->alpha = pixel & 0xff;
445 skip_whitespace (gchar **str)
447 while (g_ascii_isspace (**str))
452 parse_rgb_value (gchar *str,
459 skip_whitespace (&str);
461 number = g_ascii_strtod (str, endp);
465 skip_whitespace (&p);
469 *endp = (gchar *) (p + 1);
471 *color = CLAMP (number / 100.0, 0.0, 1.0) * 255;
474 *color = CLAMP (number, 0, 255);
478 parse_rgba (ClutterColor *color,
482 skip_whitespace (&str);
490 parse_rgb_value (str, &color->red, &str);
491 skip_whitespace (&str);
498 parse_rgb_value (str, &color->green, &str);
499 skip_whitespace (&str);
506 parse_rgb_value (str, &color->blue, &str);
507 skip_whitespace (&str);
509 /* alpha (optional); since the alpha channel value can only
510 * be between 0 and 1 we don't use the parse_rgb_value()
522 skip_whitespace (&str);
523 number = g_ascii_strtod (str, &str);
525 color->alpha = CLAMP (number * 255.0, 0, 255);
530 skip_whitespace (&str);
538 parse_hsla (ClutterColor *color,
545 skip_whitespace (&str);
553 skip_whitespace (&str);
554 /* we don't do any angle normalization here because
555 * clutter_color_from_hls() will do it for us
557 number = g_ascii_strtod (str, &str);
558 skip_whitespace (&str);
567 skip_whitespace (&str);
568 number = g_ascii_strtod (str, &str);
569 skip_whitespace (&str);
575 s = CLAMP (number / 100.0, 0.0, 1.0);
576 skip_whitespace (&str);
583 skip_whitespace (&str);
584 number = g_ascii_strtod (str, &str);
585 skip_whitespace (&str);
591 l = CLAMP (number / 100.0, 0.0, 1.0);
592 skip_whitespace (&str);
594 /* alpha (optional); since the alpha channel value can only
595 * be between 0 and 1 we don't use the parse_rgb_value()
605 skip_whitespace (&str);
606 number = g_ascii_strtod (str, &str);
608 color->alpha = CLAMP (number * 255.0, 0, 255);
613 skip_whitespace (&str);
617 clutter_color_from_hls (color, h, l, s);
623 * clutter_color_from_string:
624 * @color: (out caller-allocates): return location for a #ClutterColor
625 * @str: a string specifiying a color
627 * Parses a string definition of a color, filling the
628 * <structfield>red</structfield>, <structfield>green</structfield>,
629 * <structfield>blue</structfield> and <structfield>alpha</structfield>
630 * channels of @color.
632 * The @color is not allocated.
634 * The format of @str can be either one of:
638 * <para>a standard name (as taken from the X11 rgb.txt file)</para>
641 * <para>an hexadecimal value in the form: <literal>#rgb</literal>,
642 * <literal>#rrggbb</literal>, <literal>#rgba</literal> or
643 * <literal>#rrggbbaa</literal></para>
646 * <para>a RGB color in the form: <literal>rgb(r, g, b)</literal></para>
649 * <para>a RGB color in the form: <literal>rgba(r, g, b, a)</literal></para>
652 * <para>a HSL color in the form: <literal>hsl(h, s, l)</literal></para>
655 * <para>a HSL color in the form: <literal>hsla(h, s, l, a)</literal></para>
659 * where 'r', 'g', 'b' and 'a' are (respectively) the red, green, blue color
660 * intensities and the opacity. The 'h', 's' and 'l' are (respectively) the
661 * hue, saturation and luminance values.
663 * In the rgb() and rgba() formats, the 'r', 'g', and 'b' values are either
664 * integers between 0 and 255, or percentage values in the range between 0%
665 * and 100%; the percentages require the '%' character. The 'a' value, if
666 * specified, can only be a floating point value between 0.0 and 1.0.
668 * In the hls() and hlsa() formats, the 'h' value (hue) it's an angle between
669 * 0 and 360.0 degrees; the 'l' and 's' values (luminance and saturation) are
670 * a floating point value between 0.0 and 1.0. The 'a' value, if specified,
671 * can only be a floating point value between 0.0 and 1.0.
673 * Whitespace inside the definitions is ignored; no leading whitespace
676 * If the alpha component is not specified then it is assumed to be set to
679 * Return value: %TRUE if parsing succeeded, and %FALSE otherwise
684 clutter_color_from_string (ClutterColor *color,
687 PangoColor pango_color = { 0, };
689 g_return_val_if_fail (color != NULL, FALSE);
690 g_return_val_if_fail (str != NULL, FALSE);
692 if (strncmp (str, "rgb", 3) == 0)
694 gchar *s = (gchar *) str;
697 if (strncmp (str, "rgba", 4) == 0)
698 res = parse_rgba (color, s + 4, TRUE);
700 res = parse_rgba (color, s + 3, FALSE);
705 if (strncmp (str, "hsl", 3) == 0)
707 gchar *s = (gchar *) str;
710 if (strncmp (str, "hsla", 4) == 0)
711 res = parse_hsla (color, s + 4, TRUE);
713 res = parse_hsla (color, s + 3, FALSE);
718 /* if the string contains a color encoded using the hexadecimal
719 * notations (#rrggbbaa or #rgba) we attempt a rough pass at
720 * parsing the color ourselves, as we need the alpha channel that
721 * Pango can't retrieve.
723 if (str[0] == '#' && str[1] != '\0')
725 gsize length = strlen (str + 1);
728 if (sscanf (str + 1, "%x", &result) == 1)
732 case 8: /* rrggbbaa */
733 color->red = (result >> 24) & 0xff;
734 color->green = (result >> 16) & 0xff;
735 color->blue = (result >> 8) & 0xff;
737 color->alpha = result & 0xff;
741 case 6: /* #rrggbb */
742 color->red = (result >> 16) & 0xff;
743 color->green = (result >> 8) & 0xff;
744 color->blue = result & 0xff;
751 color->red = ((result >> 12) & 0xf);
752 color->green = ((result >> 8) & 0xf);
753 color->blue = ((result >> 4) & 0xf);
754 color->alpha = result & 0xf;
756 color->red = (color->red << 4) | color->red;
757 color->green = (color->green << 4) | color->green;
758 color->blue = (color->blue << 4) | color->blue;
759 color->alpha = (color->alpha << 4) | color->alpha;
764 color->red = ((result >> 8) & 0xf);
765 color->green = ((result >> 4) & 0xf);
766 color->blue = result & 0xf;
768 color->red = (color->red << 4) | color->red;
769 color->green = (color->green << 4) | color->green;
770 color->blue = (color->blue << 4) | color->blue;
782 /* fall back to pango for X11-style named colors; see:
784 * http://en.wikipedia.org/wiki/X11_color_names
786 * for a list. at some point we might even ship with our own list generated
787 * from X11/rgb.txt, like we generate the key symbols.
789 if (pango_color_parse (&pango_color, str))
791 color->red = pango_color.red;
792 color->green = pango_color.green;
793 color->blue = pango_color.blue;
804 * clutter_color_to_string:
805 * @color: a #ClutterColor
807 * Returns a textual specification of @color in the hexadecimal form
808 * <literal>#rrggbbaa</literal>, where <literal>r</literal>,
809 * <literal>g</literal>, <literal>b</literal> and <literal>a</literal> are
810 * hexadecimal digits representing the red, green, blue and alpha components
813 * Return value: (transfer full): a newly-allocated text string
818 clutter_color_to_string (const ClutterColor *color)
820 g_return_val_if_fail (color != NULL, NULL);
822 return g_strdup_printf ("#%02x%02x%02x%02x",
830 * clutter_color_equal:
831 * @v1: a #ClutterColor
832 * @v2: a #ClutterColor
834 * Compares two #ClutterColor<!-- -->s and checks if they are the same.
836 * This function can be passed to g_hash_table_new() as the @key_equal_func
837 * parameter, when using #ClutterColor<!-- -->s as keys in a #GHashTable.
839 * Return value: %TRUE if the two colors are the same.
844 clutter_color_equal (gconstpointer v1,
847 const ClutterColor *a, *b;
849 g_return_val_if_fail (v1 != NULL, FALSE);
850 g_return_val_if_fail (v2 != NULL, FALSE);
858 return (a->red == b->red &&
859 a->green == b->green &&
860 a->blue == b->blue &&
861 a->alpha == b->alpha);
865 * clutter_color_hash:
866 * @v: a #ClutterColor
868 * Converts a #ClutterColor to a hash value.
870 * This function can be passed to g_hash_table_new() as the @hash_func
871 * parameter, when using #ClutterColor<!-- -->s as keys in a #GHashTable.
873 * Return value: a hash value corresponding to the color
878 clutter_color_hash (gconstpointer v)
880 return clutter_color_to_pixel ((const ClutterColor *) v);
884 * clutter_color_interpolate:
885 * @initial: the initial #ClutterColor
886 * @final: the final #ClutterColor
887 * @progress: the interpolation progress
888 * @result: (out): return location for the interpolation
890 * Interpolates between @initial and @final #ClutterColor<!-- -->s
896 clutter_color_interpolate (const ClutterColor *initial,
897 const ClutterColor *final,
899 ClutterColor *result)
901 g_return_if_fail (initial != NULL);
902 g_return_if_fail (final != NULL);
903 g_return_if_fail (result != NULL);
905 result->red = initial->red + (final->red - initial->red) * progress;
906 result->green = initial->green + (final->green - initial->green) * progress;
907 result->blue = initial->blue + (final->blue - initial->blue) * progress;
908 result->alpha = initial->alpha + (final->alpha - initial->alpha) * progress;
912 clutter_color_progress (const GValue *a,
917 const ClutterColor *a_color = clutter_value_get_color (a);
918 const ClutterColor *b_color = clutter_value_get_color (b);
919 ClutterColor res = { 0, };
921 clutter_color_interpolate (a_color, b_color, progress, &res);
922 clutter_value_set_color (retval, &res);
928 * clutter_color_copy:
929 * @color: a #ClutterColor
931 * Makes a copy of the color structure. The result must be
932 * freed using clutter_color_free().
934 * Return value: (transfer full): an allocated copy of @color.
939 clutter_color_copy (const ClutterColor *color)
941 if (G_LIKELY (color != NULL))
942 return g_slice_dup (ClutterColor, color);
948 * clutter_color_free:
949 * @color: a #ClutterColor
951 * Frees a color structure created with clutter_color_copy().
956 clutter_color_free (ClutterColor *color)
958 if (G_LIKELY (color != NULL))
959 g_slice_free (ClutterColor, color);
964 * @red: red component of the color, between 0 and 255
965 * @green: green component of the color, between 0 and 255
966 * @blue: blue component of the color, between 0 and 255
967 * @alpha: alpha component of the color, between 0 and 255
969 * Creates a new #ClutterColor with the given values.
971 * Return value: (transfer full): the newly allocated color.
972 * Use clutter_color_free() when done
977 clutter_color_new (guint8 red,
984 color = g_slice_new (ClutterColor);
987 color->green = green;
989 color->alpha = alpha;
995 clutter_value_transform_color_string (const GValue *src,
998 const ClutterColor *color = g_value_get_boxed (src);
1002 gchar *string = clutter_color_to_string (color);
1004 g_value_take_string (dest, string);
1007 g_value_set_string (dest, NULL);
1011 clutter_value_transform_string_color (const GValue *src,
1014 const char *str = g_value_get_string (src);
1018 ClutterColor color = { 0, };
1020 clutter_color_from_string (&color, str);
1022 clutter_value_set_color (dest, &color);
1025 clutter_value_set_color (dest, NULL);
1028 G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterColor, clutter_color,
1031 CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_STRING, clutter_value_transform_color_string)
1032 CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_STRING, clutter_value_transform_string_color)
1033 CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_color_progress));
1036 * clutter_value_set_color:
1037 * @value: a #GValue initialized to #CLUTTER_TYPE_COLOR
1038 * @color: the color to set
1040 * Sets @value to @color.
1045 clutter_value_set_color (GValue *value,
1046 const ClutterColor *color)
1048 g_return_if_fail (CLUTTER_VALUE_HOLDS_COLOR (value));
1050 g_value_set_boxed (value, color);
1054 * clutter_value_get_color:
1055 * @value: a #GValue initialized to #CLUTTER_TYPE_COLOR
1057 * Gets the #ClutterColor contained in @value.
1059 * Return value: (transfer none): the color inside the passed #GValue
1063 const ClutterColor *
1064 clutter_value_get_color (const GValue *value)
1066 g_return_val_if_fail (CLUTTER_VALUE_HOLDS_COLOR (value), NULL);
1068 return g_value_get_boxed (value);
1072 param_color_init (GParamSpec *pspec)
1074 ClutterParamSpecColor *cspec = CLUTTER_PARAM_SPEC_COLOR (pspec);
1076 cspec->default_value = NULL;
1080 param_color_finalize (GParamSpec *pspec)
1082 ClutterParamSpecColor *cspec = CLUTTER_PARAM_SPEC_COLOR (pspec);
1084 clutter_color_free (cspec->default_value);
1088 param_color_set_default (GParamSpec *pspec,
1091 const ClutterColor *default_value =
1092 CLUTTER_PARAM_SPEC_COLOR (pspec)->default_value;
1093 clutter_value_set_color (value, default_value);
1097 param_color_values_cmp (GParamSpec *pspec,
1098 const GValue *value1,
1099 const GValue *value2)
1101 const ClutterColor *color1 = g_value_get_boxed (value1);
1102 const ClutterColor *color2 = g_value_get_boxed (value2);
1106 return color2 == NULL ? 0 : -1;
1108 pixel1 = clutter_color_to_pixel (color1);
1109 pixel2 = clutter_color_to_pixel (color2);
1111 if (pixel1 < pixel2)
1113 else if (pixel1 == pixel2)
1120 clutter_param_color_get_type (void)
1122 static GType pspec_type = 0;
1124 if (G_UNLIKELY (pspec_type == 0))
1126 const GParamSpecTypeInfo pspec_info = {
1127 sizeof (ClutterParamSpecColor),
1131 param_color_finalize,
1132 param_color_set_default,
1134 param_color_values_cmp,
1137 pspec_type = g_param_type_register_static (I_("ClutterParamSpecColor"),
1145 * clutter_param_spec_color: (skip)
1146 * @name: name of the property
1148 * @blurb: description (can be translatable)
1149 * @default_value: default value
1150 * @flags: flags for the param spec
1152 * Creates a #GParamSpec for properties using #ClutterColor.
1154 * Return value: the newly created #GParamSpec
1159 clutter_param_spec_color (const gchar *name,
1162 const ClutterColor *default_value,
1165 ClutterParamSpecColor *cspec;
1167 cspec = g_param_spec_internal (CLUTTER_TYPE_PARAM_COLOR,
1168 name, nick, blurb, flags);
1170 cspec->default_value = clutter_color_copy (default_value);
1172 return G_PARAM_SPEC (cspec);