From daf19205e0fe367acb6b79f240c2123156a13348 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 1 Jul 2010 14:09:37 +0100 Subject: [PATCH] align-constraint: Follow the position of the source The AlignConstraint update is using only the width/height of the source, but it should also take into account the position. Also, instead of using the ::notify signal, it should follow the BindConstraint, and switch to the ::allocation-changed signal, since it's less expensive (one emission instead of four notifications, one for each property we use). --- clutter/clutter-align-constraint.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/clutter/clutter-align-constraint.c b/clutter/clutter-align-constraint.c index e208a2f..23de475 100644 --- a/clutter/clutter-align-constraint.c +++ b/clutter/clutter-align-constraint.c @@ -83,8 +83,13 @@ update_actor_position (ClutterAlignConstraint *align) { gfloat source_width, source_height; gfloat actor_width, actor_height; + gfloat source_x, source_y; + gfloat new_position; ClutterActor *actor; + if (align->source == NULL) + return; + if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (align))) return; @@ -92,34 +97,33 @@ update_actor_position (ClutterAlignConstraint *align) if (actor == NULL) return; - if (align->source == NULL) - return; - + clutter_actor_get_position (align->source, &source_x, &source_y); clutter_actor_get_size (align->source, &source_width, &source_height); clutter_actor_get_size (actor, &actor_width, &actor_height); switch (align->align_axis) { case CLUTTER_ALIGN_X_AXIS: - clutter_actor_set_x (actor, (source_width - actor_width) * align->factor); + new_position = ((source_width - actor_width) + source_x) + * align->factor; + clutter_actor_set_x (actor, new_position); break; case CLUTTER_ALIGN_Y_AXIS: - clutter_actor_set_y (actor, (source_height - actor_height) * align->factor); + new_position = ((source_height - actor_height) + source_y) + * align->factor; + clutter_actor_set_y (actor, new_position); break; } } static void -source_position_changed (GObject *gobject, - GParamSpec *pspec, +source_position_changed (ClutterActor *actor, + const ClutterActorBox *allocation, + ClutterAllocationFlags flags, ClutterAlignConstraint *align) { - if (strcmp (pspec->name, "width") == 0 || - strcmp (pspec->name, "height") == 0) - { - update_actor_position (align); - } + update_actor_position (align); } static void @@ -320,7 +324,7 @@ clutter_align_constraint_set_source (ClutterAlignConstraint *align, if (align->source != NULL) { - g_signal_connect (align->source, "notify", + g_signal_connect (align->source, "allocation-changed", G_CALLBACK (source_position_changed), align); g_signal_connect (align->source, "destroy", -- 2.7.4