[clutter] align-constraint: Add CLUTTER_ALIGN_BOTH



commit 1e51961f7a19c4c2ddca1ad75e6bbae12d51bbbb
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Sat Oct 15 18:33:49 2011 +0100

    align-constraint: Add CLUTTER_ALIGN_BOTH
    
    Just like ClutterBindConstraint has two shorthand enumerations for binding
    position and size and avoid using multiple instances, ClutterAlignConstraint
    should have a way to align an actor with the same alignment factor on both
    axis at the same time; this is especially useful for centering actors.

 clutter/clutter-align-constraint.c |   15 +++++++++++++--
 clutter/clutter-enums.h            |    6 ++++--
 2 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/clutter/clutter-align-constraint.c b/clutter/clutter-align-constraint.c
index c7f415d..83136c2 100644
--- a/clutter/clutter-align-constraint.c
+++ b/clutter/clutter-align-constraint.c
@@ -142,13 +142,14 @@ clutter_align_constraint_update_allocation (ClutterConstraint *constraint,
   if (align->source == NULL)
     return;
 
+  clutter_actor_box_get_size (allocation, &actor_width, &actor_height);
+
   clutter_actor_get_position (align->source, &source_x, &source_y);
   clutter_actor_get_size (align->source, &source_width, &source_height);
 
   switch (align->align_axis)
     {
     case CLUTTER_ALIGN_X_AXIS:
-      actor_width = clutter_actor_box_get_width (allocation);
       allocation->x1 = ((source_width - actor_width) * align->factor)
                      + source_x;
       allocation->x1 = floorf (allocation->x1 + 0.5);
@@ -156,13 +157,23 @@ clutter_align_constraint_update_allocation (ClutterConstraint *constraint,
       break;
 
     case CLUTTER_ALIGN_Y_AXIS:
-      actor_height = clutter_actor_box_get_height (allocation);
       allocation->y1 = ((source_height - actor_height) * align->factor)
                      + source_y;
       allocation->y1 = floorf (allocation->y1 + 0.5);
       allocation->y2 = allocation->y1 + actor_height;
       break;
 
+    case CLUTTER_ALIGN_BOTH:
+      allocation->x1 = ((source_width - actor_width) * align->factor)
+                     + source_x;
+      allocation->y1 = ((source_height - actor_height) * align->factor)
+                     + source_y;
+      allocation->x1 = floorf (allocation->x1 + 0.5f);
+      allocation->y1 = floorf (allocation->y1 + 0.5f);
+      allocation->x2 = allocation->x1 + actor_width;
+      allocation->y2 = allocation->y1 + actor_height;
+      break;
+
     default:
       g_assert_not_reached ();
       break;
diff --git a/clutter/clutter-enums.h b/clutter/clutter-enums.h
index e9358ad..bf381f6 100644
--- a/clutter/clutter-enums.h
+++ b/clutter/clutter-enums.h
@@ -416,15 +416,17 @@ typedef enum {
  * ClutterAlignAxis:
  * @CLUTTER_ALIGN_X_AXIS: Maintain the alignment on the X axis
  * @CLUTTER_ALIGN_Y_AXIS: Maintain the alignment on the Y axis
+ * @CLUTTER_ALIGN_BOTH: Maintain the alignment on both the X and Y axis
  *
  * Specifies the axis on which #ClutterAlignConstraint should maintain
- * the alignment
+ * the alignment.
  *
  * Since: 1.4
  */
 typedef enum { /*< prefix=CLUTTER_ALIGN >*/
   CLUTTER_ALIGN_X_AXIS,
-  CLUTTER_ALIGN_Y_AXIS
+  CLUTTER_ALIGN_Y_AXIS,
+  CLUTTER_ALIGN_BOTH
 } ClutterAlignAxis;
 
 /**



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