2010-09-21 12:44:00 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gchar *axis;
|
|
|
|
gfloat target;
|
|
|
|
} AnimationSpec;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
button_pressed_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-03-19 14:10:26 -04:00
|
|
|
AnimationSpec *animation_spec = user_data;
|
|
|
|
ClutterTransition *transition;
|
2010-11-12 04:32:04 -05:00
|
|
|
|
2012-03-19 14:10:26 -04:00
|
|
|
if (clutter_actor_get_transition (actor, animation_spec->axis) != NULL)
|
2010-09-21 12:44:00 -04:00
|
|
|
return TRUE;
|
|
|
|
|
2012-03-19 14:10:26 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
|
|
|
clutter_actor_set_easing_duration (actor, 500);
|
|
|
|
|
|
|
|
g_object_set (actor, animation_spec->axis, animation_spec->target, NULL);
|
|
|
|
transition = clutter_actor_get_transition (actor, animation_spec->axis);
|
|
|
|
clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (transition), TRUE);
|
|
|
|
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), 1);
|
2010-09-21 12:44:00 -04:00
|
|
|
|
2012-03-19 14:10:26 -04:00
|
|
|
clutter_actor_restore_easing_state (actor);
|
2010-09-21 12:44:00 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *rectangle1;
|
|
|
|
ClutterActor *rectangle2;
|
|
|
|
ClutterActor *rectangle3;
|
|
|
|
|
|
|
|
AnimationSpec x_move = { "x", 50.0 };
|
|
|
|
AnimationSpec y_move = { "y", 400.0 };
|
|
|
|
AnimationSpec z_move = { "depth", -1000.0 };
|
|
|
|
|
2011-02-21 19:44:55 -05:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2010-09-21 12:44:00 -04:00
|
|
|
|
2011-11-09 12:49:25 -05:00
|
|
|
stage = clutter_stage_new ();
|
2010-09-21 12:44:00 -04:00
|
|
|
clutter_actor_set_size (stage, 500, 500);
|
2012-03-19 14:10:26 -04:00
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Aluminium2);
|
2010-09-21 12:44:00 -04:00
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
|
|
|
2012-03-19 14:10:26 -04:00
|
|
|
rectangle1 = clutter_actor_new ();
|
|
|
|
clutter_actor_set_background_color (rectangle1, CLUTTER_COLOR_ScarletRed);
|
2010-09-21 12:44:00 -04:00
|
|
|
clutter_actor_set_reactive (rectangle1, TRUE);
|
|
|
|
clutter_actor_set_size (rectangle1, 50, 50);
|
|
|
|
clutter_actor_set_position (rectangle1, 400, 400);
|
2012-03-19 14:10:26 -04:00
|
|
|
clutter_actor_add_child (stage, rectangle1);
|
2010-09-21 12:44:00 -04:00
|
|
|
|
2012-03-19 14:10:26 -04:00
|
|
|
rectangle2 = clutter_actor_new ();
|
|
|
|
clutter_actor_set_background_color (rectangle2, CLUTTER_COLOR_Chameleon);
|
2010-09-21 12:44:00 -04:00
|
|
|
clutter_actor_set_reactive (rectangle2, TRUE);
|
|
|
|
clutter_actor_set_size (rectangle2, 50, 50);
|
|
|
|
clutter_actor_set_position (rectangle2, 50, 50);
|
2012-03-19 14:10:26 -04:00
|
|
|
clutter_actor_add_child (stage, rectangle2);
|
2010-09-21 12:44:00 -04:00
|
|
|
|
2012-03-19 14:10:26 -04:00
|
|
|
rectangle3 = clutter_actor_new ();
|
|
|
|
clutter_actor_set_background_color (rectangle3, CLUTTER_COLOR_SkyBlue);
|
2010-09-21 12:44:00 -04:00
|
|
|
clutter_actor_set_reactive (rectangle3, TRUE);
|
|
|
|
clutter_actor_set_size (rectangle3, 50, 50);
|
|
|
|
clutter_actor_set_position (rectangle3, 225, 225);
|
2012-03-19 14:10:26 -04:00
|
|
|
clutter_actor_add_child (stage, rectangle3);
|
2010-09-21 12:44:00 -04:00
|
|
|
|
|
|
|
g_signal_connect (rectangle1,
|
|
|
|
"button-press-event",
|
|
|
|
G_CALLBACK (button_pressed_cb),
|
|
|
|
&x_move);
|
|
|
|
|
|
|
|
g_signal_connect (rectangle2,
|
|
|
|
"button-press-event",
|
|
|
|
G_CALLBACK (button_pressed_cb),
|
|
|
|
&y_move);
|
|
|
|
|
|
|
|
g_signal_connect (rectangle3,
|
|
|
|
"button-press-event",
|
|
|
|
G_CALLBACK (button_pressed_cb),
|
|
|
|
&z_move);
|
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|