2007-01-30 Tomas Frydrych <tf@openedhand.com>

* clutter/clutter-actor.c:
        * clutter/clutter-actor.h:
	Added new clutter_actor_move_anchor_point_ API.

        * clutter/clutter-behaviour-scale.c:
        * clutter/clutter-behaviour-scale.h:
        * clutter/clutter-effect.c:
        * clutter/clutter-effect.h:
        * tests/test-actors.c:
        * tests/test-effects.c:
        * tests/test-scale.c:
	Removed gravity from ClutterBehaviourScale.
This commit is contained in:
Tomas Frydrych 2008-01-30 12:13:26 +00:00
parent 5bf265fbae
commit 4a1e765e19
10 changed files with 221 additions and 172 deletions

View File

@ -1,3 +1,18 @@
2007-01-30 Tomas Frydrych <tf@openedhand.com>
* clutter/clutter-actor.c:
* clutter/clutter-actor.h:
Added new clutter_actor_move_anchor_point_ API.
* clutter/clutter-behaviour-scale.c:
* clutter/clutter-behaviour-scale.h:
* clutter/clutter-effect.c:
* clutter/clutter-effect.h:
* tests/test-actors.c:
* tests/test-effects.c:
* tests/test-scale.c:
Removed gravity from ClutterBehaviourScale.
2008-01-27 Emmanuele Bassi <ebassi@openedhand.com>
* tests/test-depth.c (main): Use a group instead of pushing

View File

@ -49,6 +49,9 @@
* </listitem>
* </orderedlist>
*
* NB: the position of any children is referenced from the top-left corner of
* the parent, not the parent's anchor point.
*
* Event handling
* <orderedlist>
* <listitem><para>Actors emit pointer events if set reactive, see
@ -4035,6 +4038,44 @@ clutter_actor_set_anchor_point (ClutterActor *self,
priv->anchor_y = CLUTTER_UNITS_FROM_DEVICE (anchor_y);
}
/**
* clutter_actor_move_anchor_point:
* @self: a #ClutterActor
* @anchor_x: X coordinate of the anchor point
* @anchor_y: Y coordinate of the anchor point
*
* Sets an anchor point for the @actor, and adjusts the actor postion so that
* the relative position of the actor toward its parent remains the same.
*
* Since: 0.6
*/
void
clutter_actor_move_anchor_point (ClutterActor *self,
gint anchor_x,
gint anchor_y)
{
ClutterActorPrivate *priv;
ClutterUnit ax = CLUTTER_UNITS_FROM_DEVICE (anchor_x);
ClutterUnit ay = CLUTTER_UNITS_FROM_DEVICE (anchor_y);
ClutterUnit dx;
ClutterUnit dy;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
priv = self->priv;
dx = ax - priv->anchor_x;
dy = ay - priv->anchor_y;
priv->anchor_x = ax;
priv->anchor_y = ay;
priv->coords.x1 -= dx;
priv->coords.x2 -= dx;
priv->coords.y1 -= dy;
priv->coords.y2 -= dy;
}
/**
* clutter_actor_get_anchor_point:
* @self: a #ClutterActor
@ -4091,6 +4132,42 @@ clutter_actor_set_anchor_pointu (ClutterActor *self,
priv->anchor_y = anchor_y;
}
/**
* clutter_actor_move_anchor_pointu:
* @self: a #ClutterActor
* @anchor_x: X coordinate of the anchor point
* @anchor_y: Y coordinate of the anchor point
*
* Sets an anchor point for the @actor, and adjusts the actor postion so that
* the relative position of the actor toward its parent remains the same.
*
* Since: 0.6
*/
void
clutter_actor_move_anchor_pointu (ClutterActor *self,
ClutterUnit anchor_x,
ClutterUnit anchor_y)
{
ClutterActorPrivate *priv;
ClutterUnit dx;
ClutterUnit dy;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
priv = self->priv;
dx = anchor_x - priv->anchor_x;
dy = anchor_y - priv->anchor_y;
priv->anchor_x = anchor_x;
priv->anchor_y = anchor_y;
priv->coords.x1 -= dx;
priv->coords.x2 -= dx;
priv->coords.y1 -= dy;
priv->coords.y2 -= dy;
}
/**
* clutter_actor_get_anchor_pointu:
* @self: a #ClutterActor
@ -4119,6 +4196,42 @@ clutter_actor_get_anchor_pointu (ClutterActor *self,
*anchor_y = priv->anchor_y;
}
/**
* clutter_actor_move_anchor_point_from_gravity:
* @self: a #ClutterActor
* @gravity: #ClutterGravity.
*
* Sets an anchor point of the actor based on the given gravity, adjusting the
* actor postion so that its relative position within its parent remainst
* unchanged.
*
* Since: 0.6
*/
void
clutter_actor_move_anchor_point_from_gravity (ClutterActor *self,
ClutterGravity gravity)
{
ClutterUnit ax, ay, dx, dy;
ClutterActorPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
priv = self->priv;
ax = priv->anchor_x;
ay = priv->anchor_y;
clutter_actor_set_anchor_point_from_gravity (self, gravity);
dx = ax - priv->anchor_x;
dy = ay - priv->anchor_y;
priv->coords.x1 -= dx;
priv->coords.x2 -= dx;
priv->coords.y1 -= dy;
priv->coords.y2 -= dy;
}
/**
* clutter_actor_set_anchor_point_from_gravity:
* @self: a #ClutterActor

View File

@ -432,18 +432,26 @@ void clutter_actor_set_shader_param (ClutterActor *self,
void clutter_actor_set_anchor_point (ClutterActor *self,
gint anchor_x,
gint anchor_y);
void clutter_actor_move_anchor_point (ClutterActor *self,
gint anchor_x,
gint anchor_y);
void clutter_actor_get_anchor_point (ClutterActor *self,
gint *anchor_x,
gint *anchor_y);
void clutter_actor_set_anchor_pointu (ClutterActor *self,
ClutterUnit anchor_x,
ClutterUnit anchor_y);
void clutter_actor_move_anchor_pointu (ClutterActor *self,
ClutterUnit anchor_x,
ClutterUnit anchor_y);
void clutter_actor_get_anchor_pointu (ClutterActor *self,
ClutterUnit *anchor_x,
ClutterUnit *anchor_y);
void clutter_actor_set_anchor_point_from_gravity (ClutterActor *self,
ClutterGravity gravity);
void clutter_actor_move_anchor_point_from_gravity (ClutterActor *self,
ClutterGravity gravity);
gboolean clutter_actor_transform_stage_point (ClutterActor *self,
ClutterUnit x,
ClutterUnit y,

View File

@ -56,8 +56,6 @@ struct _ClutterBehaviourScalePrivate
ClutterFixed y_scale_start;
ClutterFixed x_scale_end;
ClutterFixed y_scale_end;
ClutterGravity gravity;
};
#define CLUTTER_BEHAVIOUR_SCALE_GET_PRIVATE(obj) \
@ -73,7 +71,6 @@ enum
PROP_Y_SCALE_START,
PROP_X_SCALE_END,
PROP_Y_SCALE_END,
PROP_SCALE_GRAVITY
};
typedef struct {
@ -89,13 +86,6 @@ scale_frame_foreach (ClutterBehaviour *behaviour,
ClutterBehaviourScalePrivate *priv =
CLUTTER_BEHAVIOUR_SCALE (behaviour)->priv;
ScaleFrameClosure *closure = data;
ClutterGravity gravity = priv->gravity;
/* Don't mess with the actor anchor point of gravity is set to
* none
*/
if (gravity != CLUTTER_GRAVITY_NONE)
clutter_actor_set_anchor_point_from_gravity (actor, gravity);
clutter_actor_set_scalex (actor, closure->scale_x, closure->scale_y);
}
@ -152,9 +142,6 @@ clutter_behaviour_scale_set_property (GObject *gobject,
case PROP_Y_SCALE_END:
priv->y_scale_end = CLUTTER_FLOAT_TO_FIXED (g_value_get_double (value));
break;
case PROP_SCALE_GRAVITY:
priv->gravity = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -185,9 +172,6 @@ clutter_behaviour_scale_get_property (GObject *gobject,
case PROP_Y_SCALE_END:
g_value_set_double (value, CLUTTER_FIXED_TO_FLOAT (priv->y_scale_end));
break;
case PROP_SCALE_GRAVITY:
g_value_set_enum (value, priv->gravity);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -263,22 +247,6 @@ clutter_behaviour_scale_class_init (ClutterBehaviourScaleClass *klass)
0.0, G_MAXDOUBLE,
1.0,
CLUTTER_PARAM_READWRITE));
/**
* ClutterBehaviourScale:gravity:
*
* The gravity of the scaling.
*
* Since: 0.2
*/
g_object_class_install_property (gobject_class,
PROP_SCALE_GRAVITY,
g_param_spec_enum ("scale-gravity",
"Scale Gravity",
"The gravity of the scaling",
CLUTTER_TYPE_GRAVITY,
CLUTTER_GRAVITY_CENTER,
CLUTTER_PARAM_READWRITE));
behave_class->alpha_notify = clutter_behaviour_scale_alpha_notify;
@ -294,7 +262,6 @@ clutter_behaviour_scale_init (ClutterBehaviourScale *self)
priv->x_scale_start = priv->x_scale_end = CFX_ONE;
priv->y_scale_start = priv->y_scale_end = CFX_ONE;
priv->gravity = CLUTTER_GRAVITY_CENTER;
}
/**
@ -304,7 +271,6 @@ clutter_behaviour_scale_init (ClutterBehaviourScale *self)
* @y_scale_start: initial scale factor on the Y axis
* @x_scale_end: final scale factor on the X axis
* @y_scale_end: final scale factor on the Y axis
* @gravity: a #ClutterGravity for the scale.
*
* Creates a new #ClutterBehaviourScale instance.
*
@ -317,8 +283,7 @@ clutter_behaviour_scale_new (ClutterAlpha *alpha,
gdouble x_scale_start,
gdouble y_scale_start,
gdouble x_scale_end,
gdouble y_scale_end,
ClutterGravity gravity)
gdouble y_scale_end)
{
g_return_val_if_fail (alpha == NULL || CLUTTER_IS_ALPHA (alpha), NULL);
@ -326,8 +291,7 @@ clutter_behaviour_scale_new (ClutterAlpha *alpha,
CLUTTER_FLOAT_TO_FIXED (x_scale_start),
CLUTTER_FLOAT_TO_FIXED (y_scale_start),
CLUTTER_FLOAT_TO_FIXED (x_scale_end),
CLUTTER_FLOAT_TO_FIXED (y_scale_end),
gravity);
CLUTTER_FLOAT_TO_FIXED (y_scale_end));
}
/**
@ -337,7 +301,6 @@ clutter_behaviour_scale_new (ClutterAlpha *alpha,
* @y_scale_start: initial scale factor on the Y axis
* @x_scale_end: final scale factor on the X axis
* @y_scale_end: final scale factor on the Y axis
* @gravity: a #ClutterGravity for the scale.
*
* A fixed point implementation of clutter_behaviour_scale_new()
*
@ -350,8 +313,7 @@ clutter_behaviour_scale_newx (ClutterAlpha *alpha,
ClutterFixed x_scale_start,
ClutterFixed y_scale_start,
ClutterFixed x_scale_end,
ClutterFixed y_scale_end,
ClutterGravity gravity)
ClutterFixed y_scale_end)
{
ClutterBehaviourScale *behave;
@ -364,8 +326,6 @@ clutter_behaviour_scale_newx (ClutterAlpha *alpha,
behave->priv->x_scale_end = x_scale_end;
behave->priv->y_scale_end = y_scale_end;
behave->priv->gravity = gravity;
return CLUTTER_BEHAVIOUR (behave);
}
@ -539,42 +499,3 @@ clutter_behaviour_scale_get_boundsx (ClutterBehaviourScale *scale,
*y_scale_end = priv->y_scale_end;
}
/**
* clutter_behaviour_scale_set_gravity:
* @scale: a #ClutterBehaviourScale
* @gravity: the gravity of the scaling
*
* Sets the #ClutterGravity applied by the scale behaviour.
*
* Since: 0.6
*/
void
clutter_behaviour_scale_set_gravity (ClutterBehaviourScale *scale,
ClutterGravity gravity)
{
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_SCALE (scale));
if (scale->priv->gravity != gravity)
{
scale->priv->gravity = gravity;
g_object_notify (G_OBJECT (scale), "scale-gravity");
}
}
/**
* clutter_behaviour_scale_get_gravity:
* @scale: a #ClutterBehaviourScale
*
* Retrieves the #ClutterGravity applied by the scale behaviour.
*
* Return value: the gravity used by the behaviour
*
* Since: 0.4
*/
ClutterGravity
clutter_behaviour_scale_get_gravity (ClutterBehaviourScale *scale)
{
g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_SCALE (scale), CLUTTER_GRAVITY_NONE);
return scale->priv->gravity;
}

View File

@ -80,14 +80,12 @@ ClutterBehaviour *clutter_behaviour_scale_new (ClutterAlpha *alpha,
gdouble x_scale_start,
gdouble y_scale_start,
gdouble x_scale_end,
gdouble y_scale_end,
ClutterGravity gravity);
gdouble y_scale_end);
ClutterBehaviour *clutter_behaviour_scale_newx (ClutterAlpha *alpha,
ClutterFixed x_scale_start,
ClutterFixed y_scale_start,
ClutterFixed x_scale_end,
ClutterFixed y_scale_end,
ClutterGravity gravity);
ClutterFixed y_scale_end);
void clutter_behaviour_scale_set_bounds (ClutterBehaviourScale *scale,
gdouble x_scale_start,
@ -110,10 +108,6 @@ void clutter_behaviour_scale_get_boundsx (ClutterBehaviourScale *scale,
ClutterFixed *x_scale_end,
ClutterFixed *y_scale_end);
void clutter_behaviour_scale_set_gravity (ClutterBehaviourScale *scale,
ClutterGravity gravity);
ClutterGravity clutter_behaviour_scale_get_gravity (ClutterBehaviourScale *scale);
G_END_DECLS
#endif /* __CLUTTER_BEHAVIOUR_SCALE_H__ */

View File

@ -733,7 +733,6 @@ clutter_effect_path (ClutterEffectTemplate *template_,
* @actor: A #ClutterActor to apply the effect to.
* @x_scale_end: Final X axis scale factor to apply to actor
* @y_scale_end: Final Y axis scale factor to apply to actor
* @gravity: A #ClutterGravity for the scale.
* @func: A #ClutterEffectCompleteFunc to call on effect
* completion or NULL
* @data: Data to pass to supplied #ClutterEffectCompleteFunc
@ -751,7 +750,6 @@ clutter_effect_scale (ClutterEffectTemplate *template_,
ClutterActor *actor,
gdouble x_scale_end,
gdouble y_scale_end,
ClutterGravity gravity,
ClutterEffectCompleteFunc func,
gpointer data)
{
@ -768,8 +766,7 @@ clutter_effect_scale (ClutterEffectTemplate *template_,
clutter_actor_get_scale (actor, &x_scale_start, &y_scale_start);
c->behave = clutter_behaviour_scale_new (c->alpha,
x_scale_start, y_scale_start,
x_scale_end, y_scale_end,
gravity);
x_scale_end, y_scale_end);
clutter_behaviour_apply (c->behave, actor);
clutter_timeline_start (c->timeline);

View File

@ -142,7 +142,6 @@ ClutterTimeline *clutter_effect_scale (ClutterEffectTemplate *template_,
ClutterActor *actor,
gdouble x_scale_end,
gdouble y_scale_end,
ClutterGravity gravity,
ClutterEffectCompleteFunc func,
gpointer data);
ClutterTimeline *clutter_effect_rotate (ClutterEffectTemplate *template_,

View File

@ -180,13 +180,11 @@ main (int argc, char *argv[])
scaler_1 = clutter_behaviour_scale_new (alpha,
0.5, 0.5,
1.0, 1.0,
CLUTTER_GRAVITY_CENTER);
1.0, 1.0);
scaler_2 = clutter_behaviour_scale_new (alpha,
1.0, 1.0,
0.5, 0.5,
CLUTTER_GRAVITY_CENTER);
0.5, 0.5);
/* create a new group to hold multiple actors in a group */
oh->group = clutter_group_new();
@ -218,6 +216,10 @@ main (int argc, char *argv[])
clutter_actor_set_position (oh->hand[i], x, y);
clutter_actor_set_anchor_point_from_gravity (oh->hand[i],
CLUTTER_GRAVITY_CENTER);
/* Add to our group group */
clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]);

View File

@ -69,8 +69,9 @@ main (int argc, char *argv[])
clutter_container_add_actor (container, actor);
clutter_actor_set_size (actor, 50, 50);
clutter_actor_set_position (actor, 50, 280);
clutter_effect_scale (tmpl, actor, 2.0, 2.0,
CLUTTER_GRAVITY_CENTER, NULL, NULL);
clutter_actor_set_anchor_point_from_gravity (actor, CLUTTER_GRAVITY_CENTER);
clutter_effect_scale (tmpl, actor, 2.0, 2.0, NULL, NULL);
clutter_actor_show (actor);
actor = clutter_rectangle_new_with_color (&rect_color);

View File

@ -20,12 +20,12 @@ void
on_timeline_completed (ClutterTimeline *cluttertimeline,
gpointer data)
{
ClutterBehaviourScale *behave = CLUTTER_BEHAVIOUR_SCALE(data);
ClutterActor *actor = CLUTTER_ACTOR (data);
if (++gindex >= G_N_ELEMENTS (gravities))
gindex = 0;
g_object_set (behave, "scale-gravity", gravities[gindex], NULL);
clutter_actor_move_anchor_point_from_gravity (actor, gravities[gindex]);
}
int
@ -53,9 +53,9 @@ main (int argc, char *argv[])
rect_color.alpha = 0xff;
rect = clutter_rectangle_new_with_color (&rect_color);
clutter_actor_set_anchor_point_from_gravity (rect, CLUTTER_GRAVITY_CENTER);
clutter_actor_set_position (rect, 100, 100);
clutter_actor_set_size (rect, 100, 100);
clutter_actor_set_position (rect, 150, 150);
clutter_actor_move_anchor_point_from_gravity (rect, CLUTTER_GRAVITY_CENTER);
clutter_group_add (CLUTTER_GROUP (stage), rect);
@ -66,14 +66,13 @@ main (int argc, char *argv[])
behave = clutter_behaviour_scale_new (alpha,
0.0, 0.0, /* scale start */
1.5, 1.5, /* scale end */
gravities[gindex]);
1.0, 1.0); /* scale end */
clutter_behaviour_apply (behave, rect);
clutter_timeline_set_loop (timeline, TRUE);
g_signal_connect (timeline, "completed",
G_CALLBACK(on_timeline_completed), behave);
G_CALLBACK(on_timeline_completed), rect);
clutter_timeline_start (timeline);
clutter_actor_show_all (stage);