2007-07-25 Matthew Allum <mallum@openedhand.com>

* clutter/clutter-behaviour-rotate.c:
        * clutter/clutter-behaviour-rotate.h:
        Split 'center' prop into 3 seperate props for each axis.
        Use clutter_behaviour_actors_foreach() rather than
        clutter_behaviour_get_actors() to avoid copying list.
        Call fixed point rotation funcs internally.

        * clutter/clutter-effect.c:
        * clutter/clutter-effect.h:
        Add new simple rotation based effect funcs.
This commit is contained in:
Matthew Allum
2007-07-25 12:17:44 +00:00
parent b43f0994ca
commit c27b00d7ef
5 changed files with 377 additions and 60 deletions

View File

@ -59,7 +59,7 @@ struct _ClutterBehaviourRotatePrivate
ClutterRotateAxis axis;
ClutterRotateDirection direction;
ClutterKnot center;
gint center_x, center_y, center_z;
};
#define CLUTTER_BEHAVIOUR_ROTATE_GET_PRIVATE(obj) \
@ -75,9 +75,45 @@ enum
PROP_ANGLE_END,
PROP_AXIS,
PROP_DIRECTION,
PROP_CENTER
PROP_CENTER_X,
PROP_CENTER_Y,
PROP_CENTER_Z
};
static void
alpha_notify_foreach (ClutterBehaviour *behaviour,
ClutterActor *actor,
gpointer data)
{
ClutterFixed angle;
ClutterBehaviourRotate *rotate_behaviour;
ClutterBehaviourRotatePrivate *priv;
rotate_behaviour = CLUTTER_BEHAVIOUR_ROTATE (behaviour);
priv = rotate_behaviour->priv;
angle = GPOINTER_TO_UINT(data);
switch (priv->axis)
{
case CLUTTER_X_AXIS:
clutter_actor_rotate_xx (actor,
angle,
priv->center_y, priv->center_z);
break;
case CLUTTER_Y_AXIS:
clutter_actor_rotate_yx (actor,
angle,
priv->center_x, priv->center_z);
break;
case CLUTTER_Z_AXIS:
clutter_actor_rotate_zx (actor,
angle,
priv->center_x, priv->center_y);
break;
}
}
static void
clutter_behaviour_rotate_alpha_notify (ClutterBehaviour *behaviour,
guint32 alpha_value)
@ -85,7 +121,6 @@ clutter_behaviour_rotate_alpha_notify (ClutterBehaviour *behaviour,
ClutterFixed factor, angle;
ClutterBehaviourRotate *rotate_behaviour;
ClutterBehaviourRotatePrivate *priv;
GSList *actors, *l;
rotate_behaviour = CLUTTER_BEHAVIOUR_ROTATE (behaviour);
priv = rotate_behaviour->priv;
@ -105,31 +140,9 @@ clutter_behaviour_rotate_alpha_notify (ClutterBehaviour *behaviour,
break;
}
actors = clutter_behaviour_get_actors (behaviour);
for (l = actors; l; l = l->next)
{
ClutterActor *actor = l->data;
switch (priv->axis)
{
case CLUTTER_X_AXIS:
clutter_actor_rotate_x (actor,
CLUTTER_FIXED_TO_FLOAT (angle),
priv->center.x, priv->center.y);
break;
case CLUTTER_Y_AXIS:
clutter_actor_rotate_y (actor,
CLUTTER_FIXED_TO_FLOAT (angle),
priv->center.x, priv->center.y);
break;
case CLUTTER_Z_AXIS:
clutter_actor_rotate_z (actor,
CLUTTER_FIXED_TO_FLOAT (angle),
priv->center.x, priv->center.y);
break;
}
}
g_slist_free (actors);
clutter_behaviour_actors_foreach (behaviour,
alpha_notify_foreach,
GUINT_TO_POINTER ((guint)angle));
}
static void
@ -158,12 +171,23 @@ clutter_behaviour_rotate_set_property (GObject *gobject,
case PROP_DIRECTION:
priv->direction = g_value_get_enum (value);
break;
case PROP_CENTER:
{
ClutterKnot *knot = g_value_get_boxed (value);
if (knot)
clutter_behaviour_rotate_set_center (rotate, knot);
}
case PROP_CENTER_X:
clutter_behaviour_rotate_set_center (rotate,
g_value_get_int (value),
priv->center_y,
priv->center_z);
break;
case PROP_CENTER_Y:
clutter_behaviour_rotate_set_center (rotate,
priv->center_x,
g_value_get_int (value),
priv->center_z);
break;
case PROP_CENTER_Z:
clutter_behaviour_rotate_set_center (rotate,
priv->center_x,
priv->center_y,
g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
@ -195,8 +219,14 @@ clutter_behaviour_rotate_get_property (GObject *gobject,
case PROP_DIRECTION:
g_value_set_enum (value, priv->direction);
break;
case PROP_CENTER:
g_value_set_boxed (value, &priv->center);
case PROP_CENTER_X:
g_value_set_int (value, priv->center_x);
break;
case PROP_CENTER_Y:
g_value_set_int (value, priv->center_y);
break;
case PROP_CENTER_Z:
g_value_set_int (value, priv->center_z);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
@ -274,20 +304,51 @@ clutter_behaviour_rotate_class_init (ClutterBehaviourRotateClass *klass)
CLUTTER_ROTATE_CW,
CLUTTER_PARAM_READWRITE));
/**
* ClutterBehaviourRotate:center:
* ClutterBehaviourRotate:center-x:
*
* The center of rotation. The coordinates are relative to the plane normal
* to the axis of rotation.
* The x center of rotation.
*
* Since: 0.4
*/
g_object_class_install_property (gobject_class,
PROP_CENTER,
g_param_spec_boxed ("center",
"Center",
"Center of rotation",
CLUTTER_TYPE_KNOT,
CLUTTER_PARAM_READWRITE));
PROP_CENTER_X,
g_param_spec_int ("center-x",
"Center-X",
"X center of rotation",
-G_MAXINT, G_MAXINT,
0,
CLUTTER_PARAM_READWRITE));
/**
* ClutterBehaviourRotate:center-y:
*
* The y center of rotation.
*
* Since: 0.4
*/
g_object_class_install_property (gobject_class,
PROP_CENTER_Y,
g_param_spec_int ("center-y",
"Center-Y",
"Y center of rotation",
-G_MAXINT, G_MAXINT,
0,
CLUTTER_PARAM_READWRITE));
/**
* ClutterBehaviourRotate:center-z:
*
* The z center of rotation.
*
* Since: 0.4
*/
g_object_class_install_property (gobject_class,
PROP_CENTER_Z,
g_param_spec_int ("center-z",
"Center-Z",
"Z center of rotation",
-G_MAXINT, G_MAXINT,
0,
CLUTTER_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (ClutterBehaviourRotatePrivate));
}
@ -303,7 +364,7 @@ clutter_behaviour_rotate_init (ClutterBehaviourRotate *rotate)
priv->angle_end = CLUTTER_FLOAT_TO_FIXED (360.0);
priv->axis = CLUTTER_Z_AXIS;
priv->direction = CLUTTER_ROTATE_CW;
priv->center.x = priv->center.y = 0;
priv->center_x = priv->center_y = priv->center_z = 0;
}
/**
@ -573,7 +634,9 @@ clutter_behaviour_rotate_set_boundsx (ClutterBehaviourRotate *rotate,
/**
* clutter_behaviour_rotate_set_center:
* @rotate: a #ClutterBehaviourRotate
* @center: a #ClutterKnot
* @x: X axis center of rotation
* @y: Y axis center of rotation
* @z: Z axis center of rotation
*
* Sets the center of rotation. The coordinates are relative to the plane
* normal to the rotation axis set with clutter_behaviour_rotate_set_axis().
@ -582,28 +645,41 @@ clutter_behaviour_rotate_set_boundsx (ClutterBehaviourRotate *rotate,
*/
void
clutter_behaviour_rotate_set_center (ClutterBehaviourRotate *rotate,
const ClutterKnot *center)
gint x,
gint y,
gint z)
{
ClutterBehaviourRotatePrivate *priv;
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ROTATE (rotate));
g_return_if_fail (center != NULL);
priv = rotate->priv;
if (priv->center.x != center->x || priv->center.y != center->y)
if (priv->center_x != x)
{
priv->center.x = center->x;
priv->center.y = center->y;
priv->center_x = x;
g_object_notify (G_OBJECT (rotate), "center-x");
}
g_object_notify (G_OBJECT (rotate), "center");
if (priv->center_y != y)
{
priv->center_y = y;
g_object_notify (G_OBJECT (rotate), "center-y");
}
if (priv->center_z != z)
{
priv->center_z = z;
g_object_notify (G_OBJECT (rotate), "center-z");
}
}
/**
* clutter_behaviour_rotate_get_center:
* @rotate: a #ClutterBehaviourRotate
* @center: return location for the center of rotation
* @x: return location for the X center of rotation
* @y: return location for the Y center of rotation
* @z: return location for the Z center of rotation
*
* Retrieves the center of rotation set using
* clutter_behaviour_rotate_set_center().
@ -612,15 +688,20 @@ clutter_behaviour_rotate_set_center (ClutterBehaviourRotate *rotate,
*/
void
clutter_behaviour_rotate_get_center (ClutterBehaviourRotate *rotate,
ClutterKnot *center)
gint *x,
gint *y,
gint *z)
{
ClutterBehaviourRotatePrivate *priv;
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ROTATE (rotate));
g_return_if_fail (center != NULL);
priv = rotate->priv;
center->x = priv->center.x;
center->y = priv->center.y;
if (x)
*x = priv->center_x;
if (y)
*y = priv->center_y;
if (z)
*z = priv->center_x;
}