Move towards an alloc/init pair for base types
[profile/ivi/clutter.git] / clutter / clutter-actor-box.c
index 89bedd9..5389176 100644 (file)
@@ -2,6 +2,8 @@
 #include "config.h"
 #endif
 
+#include <math.h>
+
 #include "clutter-types.h"
 #include "clutter-interval.h"
 #include "clutter-private.h"
  * @y_2: Y coordinate of the bottom right point
  *
  * Allocates a new #ClutterActorBox using the passed coordinates
- * for the top left and bottom right points
+ * for the top left and bottom right points.
+ *
+ * This function is the logical equivalent of:
  *
- * Return value: the newly allocated #ClutterActorBox. Use
- *   clutter_actor_box_free() to free the resources
+ * |[
+ *   clutter_actor_box_init (clutter_actor_box_alloc (),
+ *                           x_1, y_1,
+ *                           x_2, y_2);
+ * ]|
+ *
+ * Return value: (transfer full): the newly allocated #ClutterActorBox.
+ *   Use clutter_actor_box_free() to free the resources
  *
  * Since: 1.0
  */
@@ -27,9 +37,50 @@ clutter_actor_box_new (gfloat x_1,
                        gfloat x_2,
                        gfloat y_2)
 {
-  ClutterActorBox *box;
+  return clutter_actor_box_init (clutter_actor_box_alloc (),
+                                 x_1, y_1,
+                                 x_2, y_2);
+}
+
+/**
+ * clutter_actor_box_alloc:
+ *
+ * Allocates a new #ClutterActorBox.
+ *
+ * Return value: (transfer full): the newly allocated #ClutterActorBox.
+ *   Use clutter_actor_box_free() to free its resources
+ *
+ * Since: 1.12
+ */
+ClutterActorBox *
+clutter_actor_box_alloc (void)
+{
+  return g_slice_new0 (ClutterActorBox);
+}
+
+/**
+ * clutter_actor_box_init:
+ * @box: a #ClutterActorBox
+ * @x_1: X coordinate of the top left point
+ * @y_1: Y coordinate of the top left point
+ * @x_2: X coordinate of the bottom right point
+ * @y_2: Y coordinate of the bottom right point
+ *
+ * Initializes @box with the given coordinates.
+ *
+ * Return value: (transfer none): the initialized #ClutterActorBox
+ *
+ * Since: 1.10
+ */
+ClutterActorBox *
+clutter_actor_box_init (ClutterActorBox *box,
+                        gfloat           x_1,
+                        gfloat           y_1,
+                        gfloat           x_2,
+                        gfloat           y_2)
+{
+  g_return_val_if_fail (box != NULL, NULL);
 
-  box = g_slice_new (ClutterActorBox);
   box->x1 = x_1;
   box->y1 = y_1;
   box->x2 = x_2;
@@ -39,6 +90,33 @@ clutter_actor_box_new (gfloat x_1,
 }
 
 /**
+ * clutter_actor_box_init_rect:
+ * @box: a #ClutterActorBox
+ * @x: X coordinate of the origin
+ * @y: Y coordinate of the origin
+ * @width: width of the box
+ * @height: height of the box
+ *
+ * Initializes @box with the given origin and size.
+ *
+ * Since: 1.10
+ */
+void
+clutter_actor_box_init_rect (ClutterActorBox *box,
+                             gfloat           x,
+                             gfloat           y,
+                             gfloat           width,
+                             gfloat           height)
+{
+  g_return_if_fail (box != NULL);
+
+  box->x1 = x;
+  box->y1 = y;
+  box->x2 = box->x1 + width;
+  box->y2 = box->y1 + height;
+}
+
+/**
  * clutter_actor_box_copy:
  * @box: a #ClutterActorBox
  *
@@ -420,6 +498,52 @@ clutter_actor_box_progress (const GValue *a,
   return TRUE;
 }
 
+/**
+ * clutter_actor_box_set_origin:
+ * @box: a #ClutterActorBox
+ * @x: the X coordinate of the new origin
+ * @y: the Y coordinate of the new origin
+ *
+ * Changes the origin of @box, maintaining the size of the #ClutterActorBox.
+ *
+ * Since: 1.6
+ */
+void
+clutter_actor_box_set_origin (ClutterActorBox *box,
+                              gfloat           x,
+                              gfloat           y)
+{
+  gfloat width, height;
+
+  g_return_if_fail (box != NULL);
+
+  width = box->x2 - box->x1;
+  height = box->y2 - box->y1;
+
+  clutter_actor_box_init_rect (box, x, y, width, height);
+}
+
+/**
+ * clutter_actor_box_set_size:
+ * @box: a #ClutterActorBox
+ * @width: the new width
+ * @height: the new height
+ *
+ * Sets the size of @box, maintaining the origin of the #ClutterActorBox.
+ *
+ * Since: 1.6
+ */
+void
+clutter_actor_box_set_size (ClutterActorBox *box,
+                            gfloat           width,
+                            gfloat           height)
+{
+  g_return_if_fail (box != NULL);
+
+  box->x2 = box->x1 + width;
+  box->y2 = box->y1 + height;
+}
+
 G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterActorBox, clutter_actor_box,
                                clutter_actor_box_copy,
                                clutter_actor_box_free,