2011-12-20 09:47:35 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#define SIZE 128
|
|
|
|
|
2012-02-02 09:07:38 -05:00
|
|
|
static gboolean
|
2012-02-14 11:50:52 -05:00
|
|
|
animate_color (ClutterActor *actor,
|
|
|
|
ClutterEvent *event)
|
2012-02-02 09:07:38 -05:00
|
|
|
{
|
|
|
|
static gboolean toggled = TRUE;
|
|
|
|
const ClutterColor *end_color;
|
|
|
|
|
|
|
|
if (toggled)
|
|
|
|
end_color = CLUTTER_COLOR_Blue;
|
|
|
|
else
|
|
|
|
end_color = CLUTTER_COLOR_Red;
|
|
|
|
|
2012-03-15 07:25:26 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
|
|
|
clutter_actor_set_easing_duration (actor, 500);
|
|
|
|
clutter_actor_set_easing_mode (actor, CLUTTER_LINEAR);
|
|
|
|
clutter_actor_set_background_color (actor, end_color);
|
|
|
|
clutter_actor_restore_easing_state (actor);
|
2012-02-02 09:07:38 -05:00
|
|
|
|
|
|
|
toggled = !toggled;
|
|
|
|
|
|
|
|
return CLUTTER_EVENT_STOP;
|
|
|
|
}
|
|
|
|
|
2012-02-14 11:50:52 -05:00
|
|
|
static gboolean
|
|
|
|
on_crossing (ClutterActor *actor,
|
2012-07-29 08:51:23 -04:00
|
|
|
ClutterEvent *event)
|
2012-02-14 11:50:52 -05:00
|
|
|
{
|
2012-07-29 08:51:23 -04:00
|
|
|
gboolean is_enter = clutter_event_type (event) == CLUTTER_ENTER;
|
2012-07-05 13:57:38 -04:00
|
|
|
float zpos;
|
2012-02-14 11:50:52 -05:00
|
|
|
|
|
|
|
if (is_enter)
|
2012-07-05 13:57:38 -04:00
|
|
|
zpos = -250.0;
|
2012-02-14 11:50:52 -05:00
|
|
|
else
|
2012-07-05 13:57:38 -04:00
|
|
|
zpos = 0.0;
|
2012-02-14 11:50:52 -05:00
|
|
|
|
2012-03-15 07:25:26 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
|
|
|
clutter_actor_set_easing_duration (actor, 500);
|
|
|
|
clutter_actor_set_easing_mode (actor, CLUTTER_EASE_OUT_BOUNCE);
|
2012-07-05 13:57:38 -04:00
|
|
|
clutter_actor_set_z_position (actor, zpos);
|
2012-03-15 07:25:26 -04:00
|
|
|
clutter_actor_restore_easing_state (actor);
|
2012-02-14 11:50:52 -05:00
|
|
|
|
|
|
|
return CLUTTER_EVENT_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-21 12:49:53 -04:00
|
|
|
on_transition_stopped (ClutterActor *actor,
|
|
|
|
const gchar *transition_name,
|
|
|
|
gboolean is_finished)
|
2012-02-14 11:50:52 -05:00
|
|
|
{
|
2012-03-15 07:25:26 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
2012-07-06 06:46:25 -04:00
|
|
|
clutter_actor_set_rotation_angle (actor, CLUTTER_Y_AXIS, 0.0f);
|
2012-03-15 07:25:26 -04:00
|
|
|
clutter_actor_restore_easing_state (actor);
|
2012-07-21 12:49:53 -04:00
|
|
|
|
|
|
|
/* disconnect so we don't get multiple notifications */
|
|
|
|
g_signal_handlers_disconnect_by_func (actor,
|
|
|
|
on_transition_stopped,
|
|
|
|
NULL);
|
2012-02-14 11:50:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
animate_rotation (ClutterActor *actor,
|
|
|
|
ClutterEvent *event)
|
|
|
|
{
|
2012-03-15 07:25:26 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
|
|
|
clutter_actor_set_easing_duration (actor, 1000);
|
|
|
|
|
2012-07-06 06:46:25 -04:00
|
|
|
clutter_actor_set_rotation_angle (actor, CLUTTER_Y_AXIS, 360.0);
|
2012-03-15 07:25:26 -04:00
|
|
|
|
|
|
|
clutter_actor_restore_easing_state (actor);
|
2012-02-14 11:50:52 -05:00
|
|
|
|
2012-07-21 12:49:53 -04:00
|
|
|
/* get a notification when the rotation-angle-y transition ends */
|
|
|
|
g_signal_connect (actor,
|
|
|
|
"transition-stopped::rotation-angle-y",
|
|
|
|
G_CALLBACK (on_transition_stopped),
|
|
|
|
NULL);
|
|
|
|
|
2012-02-14 11:50:52 -05:00
|
|
|
return CLUTTER_EVENT_STOP;
|
|
|
|
}
|
|
|
|
|
2012-05-01 13:30:10 -04:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2011-12-20 09:47:35 -05:00
|
|
|
{
|
|
|
|
ClutterActor *stage, *vase;
|
|
|
|
ClutterActor *flowers[3];
|
|
|
|
|
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
stage = clutter_stage_new ();
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Three Flowers in a Vase");
|
|
|
|
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
|
|
|
|
|
|
|
|
/* there are three flowers in a vase */
|
|
|
|
vase = clutter_actor_new ();
|
|
|
|
clutter_actor_set_name (vase, "vase");
|
2012-02-14 10:48:15 -05:00
|
|
|
clutter_actor_set_layout_manager (vase, clutter_box_layout_new ());
|
2012-02-29 10:02:59 -05:00
|
|
|
clutter_actor_set_background_color (vase, CLUTTER_COLOR_LightSkyBlue);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_add_constraint (vase, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
|
|
|
|
clutter_actor_add_child (stage, vase);
|
|
|
|
|
|
|
|
flowers[0] = clutter_actor_new ();
|
|
|
|
clutter_actor_set_name (flowers[0], "flower.1");
|
|
|
|
clutter_actor_set_size (flowers[0], SIZE, SIZE);
|
2012-02-29 10:02:59 -05:00
|
|
|
clutter_actor_set_margin_left (flowers[0], 12);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_set_background_color (flowers[0], CLUTTER_COLOR_Red);
|
2012-02-02 09:07:38 -05:00
|
|
|
clutter_actor_set_reactive (flowers[0], TRUE);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_add_child (vase, flowers[0]);
|
2012-02-14 11:50:52 -05:00
|
|
|
g_signal_connect (flowers[0], "button-press-event",
|
|
|
|
G_CALLBACK (animate_color),
|
|
|
|
NULL);
|
2011-12-20 09:47:35 -05:00
|
|
|
|
|
|
|
flowers[1] = clutter_actor_new ();
|
|
|
|
clutter_actor_set_name (flowers[1], "flower.2");
|
|
|
|
clutter_actor_set_size (flowers[1], SIZE, SIZE);
|
2012-02-29 10:02:59 -05:00
|
|
|
clutter_actor_set_margin_top (flowers[1], 12);
|
|
|
|
clutter_actor_set_margin_left (flowers[1], 6);
|
|
|
|
clutter_actor_set_margin_right (flowers[1], 6);
|
|
|
|
clutter_actor_set_margin_bottom (flowers[1], 12);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_set_background_color (flowers[1], CLUTTER_COLOR_Yellow);
|
2012-02-14 11:50:52 -05:00
|
|
|
clutter_actor_set_reactive (flowers[1], TRUE);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_add_child (vase, flowers[1]);
|
2012-02-14 11:50:52 -05:00
|
|
|
g_signal_connect (flowers[1], "enter-event",
|
|
|
|
G_CALLBACK (on_crossing),
|
2012-07-29 08:51:23 -04:00
|
|
|
NULL);
|
2012-02-14 11:50:52 -05:00
|
|
|
g_signal_connect (flowers[1], "leave-event",
|
|
|
|
G_CALLBACK (on_crossing),
|
2012-07-29 08:51:23 -04:00
|
|
|
NULL);
|
2011-12-20 09:47:35 -05:00
|
|
|
|
|
|
|
/* the third one is green */
|
|
|
|
flowers[2] = clutter_actor_new ();
|
|
|
|
clutter_actor_set_name (flowers[2], "flower.3");
|
|
|
|
clutter_actor_set_size (flowers[2], SIZE, SIZE);
|
2012-02-29 10:02:59 -05:00
|
|
|
clutter_actor_set_margin_right (flowers[2], 12);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_set_background_color (flowers[2], CLUTTER_COLOR_Green);
|
2012-07-06 13:06:33 -04:00
|
|
|
clutter_actor_set_pivot_point (flowers[2], 0.5f, 0.0f);
|
2012-02-14 11:50:52 -05:00
|
|
|
clutter_actor_set_reactive (flowers[2], TRUE);
|
2011-12-20 09:47:35 -05:00
|
|
|
clutter_actor_add_child (vase, flowers[2]);
|
2012-02-14 11:50:52 -05:00
|
|
|
g_signal_connect (flowers[2], "button-press-event",
|
|
|
|
G_CALLBACK (animate_rotation),
|
|
|
|
NULL);
|
2011-12-20 09:47:35 -05:00
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|