| 1 |
#include <stdlib.h> |
| 2 |
#include <gmodule.h> |
| 3 |
#include <clutter/clutter.h> |
| 4 |
|
| 5 |
static const ClutterColor colors[] = { |
| 6 |
{ 255, 0, 0, 255 }, |
| 7 |
{ 0, 255, 0, 255 }, |
| 8 |
{ 0, 0, 255, 255 }, |
| 9 |
}; |
| 10 |
|
| 11 |
#define PADDING (64.0f) |
| 12 |
#define SIZE (64.0f) |
| 13 |
|
| 14 |
static void |
| 15 |
on_transition_stopped (ClutterActor *actor, |
| 16 |
const gchar *transition_name, |
| 17 |
gboolean is_finished) |
| 18 |
{ |
| 19 |
g_print ("%s: transition stopped: %s (finished: %s)\n", |
| 20 |
clutter_actor_get_name (actor), |
| 21 |
transition_name, |
| 22 |
is_finished ? "yes" : "no"); |
| 23 |
} |
| 24 |
|
| 25 |
G_MODULE_EXPORT const char * |
| 26 |
test_keyframe_transition_describe (void) |
| 27 |
{ |
| 28 |
return "Demonstrate the keyframe transition."; |
| 29 |
} |
| 30 |
|
| 31 |
G_MODULE_EXPORT int |
| 32 |
test_keyframe_transition_main (int argc, char *argv[]) |
| 33 |
{ |
| 34 |
ClutterActor *stage; |
| 35 |
int i; |
| 36 |
|
| 37 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 38 |
return EXIT_FAILURE; |
| 39 |
|
| 40 |
stage = clutter_stage_new (); |
| 41 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Keyframe Transitions"); |
| 42 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 43 |
|
| 44 |
for (i = 0; i < 3; i++) |
| 45 |
{ |
| 46 |
ClutterTransition *transition, *group; |
| 47 |
ClutterActor *rect; |
| 48 |
float cur_x, cur_y; |
| 49 |
float new_x, new_y; |
| 50 |
gchar *name; |
| 51 |
|
| 52 |
cur_x = PADDING; |
| 53 |
cur_y = PADDING + ((SIZE + PADDING) * i); |
| 54 |
|
| 55 |
new_x = clutter_actor_get_width (stage) - PADDING - SIZE; |
| 56 |
new_y = g_random_double_range (PADDING, clutter_actor_get_height (stage) - PADDING - SIZE); |
| 57 |
|
| 58 |
name = g_strdup_printf ("rect%02d", i); |
| 59 |
|
| 60 |
rect = clutter_actor_new (); |
| 61 |
|
| 62 |
clutter_actor_set_name (rect, name); |
| 63 |
clutter_actor_set_background_color (rect, &colors[i]); |
| 64 |
clutter_actor_set_size (rect, SIZE, SIZE); |
| 65 |
clutter_actor_set_position (rect, PADDING, cur_y); |
| 66 |
clutter_actor_add_child (stage, rect); |
| 67 |
|
| 68 |
group = clutter_transition_group_new (); |
| 69 |
clutter_timeline_set_duration (CLUTTER_TIMELINE (group), 2000); |
| 70 |
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (group), 1); |
| 71 |
clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (group), TRUE); |
| 72 |
|
| 73 |
transition = clutter_keyframe_transition_new ("x"); |
| 74 |
clutter_transition_set_from (transition, G_TYPE_FLOAT, cur_x); |
| 75 |
clutter_transition_set_to (transition, G_TYPE_FLOAT, new_x); |
| 76 |
|
| 77 |
clutter_keyframe_transition_set (CLUTTER_KEYFRAME_TRANSITION (transition), |
| 78 |
G_TYPE_FLOAT, 1, |
| 79 |
0.5, new_x / 2.0f, CLUTTER_EASE_OUT_EXPO); |
| 80 |
clutter_transition_group_add_transition (CLUTTER_TRANSITION_GROUP (group), transition); |
| 81 |
g_object_unref (transition); |
| 82 |
|
| 83 |
transition = clutter_keyframe_transition_new ("y"); |
| 84 |
clutter_transition_set_from (transition, G_TYPE_FLOAT, cur_y); |
| 85 |
clutter_transition_set_to (transition, G_TYPE_FLOAT, cur_y); |
| 86 |
|
| 87 |
clutter_keyframe_transition_set (CLUTTER_KEYFRAME_TRANSITION (transition), |
| 88 |
G_TYPE_FLOAT, 1, |
| 89 |
0.5, new_y, CLUTTER_EASE_OUT_EXPO); |
| 90 |
clutter_transition_group_add_transition (CLUTTER_TRANSITION_GROUP (group), transition); |
| 91 |
g_object_unref (transition); |
| 92 |
|
| 93 |
clutter_actor_add_transition (rect, "rectAnimation", group); |
| 94 |
|
| 95 |
g_signal_connect (rect, "transition-stopped", |
| 96 |
G_CALLBACK (on_transition_stopped), |
| 97 |
NULL); |
| 98 |
g_object_unref (group); |
| 99 |
|
| 100 |
g_free (name); |
| 101 |
} |
| 102 |
|
| 103 |
clutter_actor_show (stage); |
| 104 |
|
| 105 |
clutter_main (); |
| 106 |
|
| 107 |
return EXIT_SUCCESS; |
| 108 |
} |