interactive/actor: Add more animations

Rotation along the Y axis and depth change.
This commit is contained in:
Emmanuele Bassi 2012-02-14 16:50:52 +00:00
parent c44ffb02f5
commit 553f446315

View File

@ -5,9 +5,8 @@
#define SIZE 128 #define SIZE 128
static gboolean static gboolean
on_button_press (ClutterActor *actor, animate_color (ClutterActor *actor,
ClutterEvent *event, ClutterEvent *event)
gpointer data)
{ {
static gboolean toggled = TRUE; static gboolean toggled = TRUE;
const ClutterColor *end_color; const ClutterColor *end_color;
@ -26,6 +25,58 @@ on_button_press (ClutterActor *actor,
return CLUTTER_EVENT_STOP; return CLUTTER_EVENT_STOP;
} }
static gboolean
on_crossing (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
gboolean is_enter = GPOINTER_TO_UINT (data);
float depth;
if (is_enter)
depth = -250.0;
else
depth = 0.0;
clutter_actor_animate (actor, CLUTTER_EASE_OUT_BOUNCE, 500,
"depth", depth,
NULL);
return CLUTTER_EVENT_STOP;
}
static void
restore_actor (ClutterActor *actor)
{
clutter_actor_set_rotation (actor, CLUTTER_Y_AXIS, 0.0,
SIZE / 2.0,
0.f,
0.f);
clutter_actor_set_reactive (actor, TRUE);
}
static gboolean
animate_rotation (ClutterActor *actor,
ClutterEvent *event)
{
ClutterVertex center;
center.x = SIZE / 2.0;
center.y = 0.f;
center.z = 0.f;
clutter_actor_animate (actor, CLUTTER_EASE_OUT_EXPO, 500,
"fixed::reactive", FALSE,
"fixed::rotation-center-y", &center,
"rotation-angle-y", 360.0,
"signal-swapped-after::completed",
G_CALLBACK (restore_actor),
actor,
NULL);
return CLUTTER_EVENT_STOP;
}
G_MODULE_EXPORT int G_MODULE_EXPORT int
test_actor_main (int argc, char *argv[]) test_actor_main (int argc, char *argv[])
{ {
@ -56,23 +107,34 @@ test_actor_main (int argc, char *argv[])
clutter_actor_set_size (flowers[0], SIZE, SIZE); clutter_actor_set_size (flowers[0], SIZE, SIZE);
clutter_actor_set_background_color (flowers[0], CLUTTER_COLOR_Red); clutter_actor_set_background_color (flowers[0], CLUTTER_COLOR_Red);
clutter_actor_set_reactive (flowers[0], TRUE); clutter_actor_set_reactive (flowers[0], TRUE);
g_signal_connect (flowers[0], "button-press-event",
G_CALLBACK (on_button_press),
GUINT_TO_POINTER (0));
clutter_actor_add_child (vase, flowers[0]); clutter_actor_add_child (vase, flowers[0]);
g_signal_connect (flowers[0], "button-press-event",
G_CALLBACK (animate_color),
NULL);
flowers[1] = clutter_actor_new (); flowers[1] = clutter_actor_new ();
clutter_actor_set_name (flowers[1], "flower.2"); clutter_actor_set_name (flowers[1], "flower.2");
clutter_actor_set_size (flowers[1], SIZE, SIZE); clutter_actor_set_size (flowers[1], SIZE, SIZE);
clutter_actor_set_background_color (flowers[1], CLUTTER_COLOR_Yellow); clutter_actor_set_background_color (flowers[1], CLUTTER_COLOR_Yellow);
clutter_actor_set_reactive (flowers[1], TRUE);
clutter_actor_add_child (vase, flowers[1]); clutter_actor_add_child (vase, flowers[1]);
g_signal_connect (flowers[1], "enter-event",
G_CALLBACK (on_crossing),
GUINT_TO_POINTER (TRUE));
g_signal_connect (flowers[1], "leave-event",
G_CALLBACK (on_crossing),
GUINT_TO_POINTER (FALSE));
/* the third one is green */ /* the third one is green */
flowers[2] = clutter_actor_new (); flowers[2] = clutter_actor_new ();
clutter_actor_set_name (flowers[2], "flower.3"); clutter_actor_set_name (flowers[2], "flower.3");
clutter_actor_set_size (flowers[2], SIZE, SIZE); clutter_actor_set_size (flowers[2], SIZE, SIZE);
clutter_actor_set_background_color (flowers[2], CLUTTER_COLOR_Green); clutter_actor_set_background_color (flowers[2], CLUTTER_COLOR_Green);
clutter_actor_set_reactive (flowers[2], TRUE);
clutter_actor_add_child (vase, flowers[2]); clutter_actor_add_child (vase, flowers[2]);
g_signal_connect (flowers[2], "button-press-event",
G_CALLBACK (animate_rotation),
NULL);
clutter_actor_show (stage); clutter_actor_show (stage);