mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 04:22:05 +00:00
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).
This commit is contained in:
parent
b625d94362
commit
daf19205e0
@ -83,8 +83,13 @@ update_actor_position (ClutterAlignConstraint *align)
|
|||||||
{
|
{
|
||||||
gfloat source_width, source_height;
|
gfloat source_width, source_height;
|
||||||
gfloat actor_width, actor_height;
|
gfloat actor_width, actor_height;
|
||||||
|
gfloat source_x, source_y;
|
||||||
|
gfloat new_position;
|
||||||
ClutterActor *actor;
|
ClutterActor *actor;
|
||||||
|
|
||||||
|
if (align->source == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (align)))
|
if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (align)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -92,35 +97,34 @@ update_actor_position (ClutterAlignConstraint *align)
|
|||||||
if (actor == NULL)
|
if (actor == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (align->source == NULL)
|
clutter_actor_get_position (align->source, &source_x, &source_y);
|
||||||
return;
|
|
||||||
|
|
||||||
clutter_actor_get_size (align->source, &source_width, &source_height);
|
clutter_actor_get_size (align->source, &source_width, &source_height);
|
||||||
clutter_actor_get_size (actor, &actor_width, &actor_height);
|
clutter_actor_get_size (actor, &actor_width, &actor_height);
|
||||||
|
|
||||||
switch (align->align_axis)
|
switch (align->align_axis)
|
||||||
{
|
{
|
||||||
case CLUTTER_ALIGN_X_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;
|
break;
|
||||||
|
|
||||||
case CLUTTER_ALIGN_Y_AXIS:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
source_position_changed (GObject *gobject,
|
source_position_changed (ClutterActor *actor,
|
||||||
GParamSpec *pspec,
|
const ClutterActorBox *allocation,
|
||||||
|
ClutterAllocationFlags flags,
|
||||||
ClutterAlignConstraint *align)
|
ClutterAlignConstraint *align)
|
||||||
{
|
|
||||||
if (strcmp (pspec->name, "width") == 0 ||
|
|
||||||
strcmp (pspec->name, "height") == 0)
|
|
||||||
{
|
{
|
||||||
update_actor_position (align);
|
update_actor_position (align);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
source_destroyed (ClutterActor *actor,
|
source_destroyed (ClutterActor *actor,
|
||||||
@ -320,7 +324,7 @@ clutter_align_constraint_set_source (ClutterAlignConstraint *align,
|
|||||||
|
|
||||||
if (align->source != NULL)
|
if (align->source != NULL)
|
||||||
{
|
{
|
||||||
g_signal_connect (align->source, "notify",
|
g_signal_connect (align->source, "allocation-changed",
|
||||||
G_CALLBACK (source_position_changed),
|
G_CALLBACK (source_position_changed),
|
||||||
align);
|
align);
|
||||||
g_signal_connect (align->source, "destroy",
|
g_signal_connect (align->source, "destroy",
|
||||||
|
Loading…
Reference in New Issue
Block a user