[clutter/master-next: 9/51] color: Add initializers for ClutterColor



commit 844104ad9f3b99369f3e1017792d991d5310069d
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Apr 13 11:26:38 2012 +0100

    color: Add initializers for ClutterColor
    
    Similar to the ones we have for the other boxed types in Clutter.

 clutter/clutter-color.c |   56 +++++++++++++++++++++++++++++++++++++++++++---
 clutter/clutter-color.h |   19 ++++++++++++++++
 2 files changed, 71 insertions(+), 4 deletions(-)
---
diff --git a/clutter/clutter-color.c b/clutter/clutter-color.c
index cef0109..723349a 100644
--- a/clutter/clutter-color.c
+++ b/clutter/clutter-color.c
@@ -968,6 +968,12 @@ clutter_color_free (ClutterColor *color)
  *
  * Creates a new #ClutterColor with the given values.
  *
+ * This function is the equivalent of:
+ *
+ * |[
+ *   clutter_color_init (clutter_color_alloc (), red, green, blue, alpha);
+ * ]|
+ *
  * Return value: (transfer full): the newly allocated color.
  *   Use clutter_color_free() when done
  *
@@ -979,13 +985,55 @@ clutter_color_new (guint8 red,
                    guint8 blue,
                    guint8 alpha)
 {
-  ClutterColor *color;
+  return clutter_color_init (clutter_color_alloc (),
+                             red,
+                             green,
+                             blue,
+                             alpha);
+}
 
-  color = g_slice_new (ClutterColor);
+/**
+ * clutter_color_alloc:
+ *
+ * Allocates a new, transparent black #ClutterColor.
+ *
+ * Return value: (transfer full): the newly allocated #ClutterColor; use
+ *   clutter_color_free() to free its resources
+ *
+ * Since: 1.12
+ */
+ClutterColor *
+clutter_color_alloc (void)
+{
+  return g_slice_new0 (ClutterColor);
+}
+
+/**
+ * clutter_color_init:
+ * @color: a #ClutterColor
+ * @red: red component of the color, between 0 and 255
+ * @green: green component of the color, between 0 and 255
+ * @blue: blue component of the color, between 0 and 255
+ * @alpha: alpha component of the color, between 0 and 255
+ *
+ * Initializes @color with the given values.
+ *
+ * Return value: (transfer none): the initialized #ClutterColor
+ *
+ * Since: 1.12
+ */
+ClutterColor *
+clutter_color_init (ClutterColor *color,
+                    guint8        red,
+                    guint8        green,
+                    guint8        blue,
+                    guint8        alpha)
+{
+  g_return_val_if_fail (color != NULL, NULL);
 
-  color->red   = red;
+  color->red = red;
   color->green = green;
-  color->blue  = blue;
+  color->blue = blue;
   color->alpha = alpha;
 
   return color;
diff --git a/clutter/clutter-color.h b/clutter/clutter-color.h
index 4bfcb47..393eee4 100644
--- a/clutter/clutter-color.h
+++ b/clutter/clutter-color.h
@@ -55,12 +55,31 @@ struct _ClutterColor
   guint8 alpha;
 };
 
+/**
+ * CLUTTER_COLOR_INIT:
+ * @r: value for the red channel, between 0 and 255
+ * @g: value for the green channel, between 0 and 255
+ * @b: value for the blue channel, between 0 and 255
+ * @a: value for the alpha channel, between 0 and 255
+ *
+ * A macro that initializes a #ClutterColor, to be used when declaring it.
+ *
+ * Since: 1.12
+ */
+#define CLUTTER_COLOR_INIT(r,g,b,a)     { (r), (g), (b), (a) }
+
 GType         clutter_color_get_type   (void) G_GNUC_CONST;
 
 ClutterColor *clutter_color_new         (guint8              red,
                                          guint8              green,
                                          guint8              blue,
                                          guint8              alpha);
+ClutterColor *clutter_color_alloc       (void);
+ClutterColor *clutter_color_init        (ClutterColor       *color,
+                                         guint8              red,
+                                         guint8              green,
+                                         guint8              blue,
+                                         guint8              alpha);
 ClutterColor *clutter_color_copy        (const ClutterColor *color);
 void          clutter_color_free        (ClutterColor       *color);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]