| 1 |
#include <stdlib.h> |
| 2 |
#include <math.h> |
| 3 |
#include <gmodule.h> |
| 4 |
#include <clutter/clutter.h> |
| 5 |
|
| 6 |
static ClutterState *state; |
| 7 |
static ClutterAnimator *animator; |
| 8 |
|
| 9 |
static gboolean press_event (ClutterActor *actor, |
| 10 |
ClutterEvent *event, |
| 11 |
gpointer user_data) |
| 12 |
{ |
| 13 |
clutter_grab_pointer (actor); |
| 14 |
clutter_state_set_state (state, "end"); |
| 15 |
return TRUE; |
| 16 |
} |
| 17 |
|
| 18 |
static gboolean release_event (ClutterActor *actor, |
| 19 |
ClutterEvent *event, |
| 20 |
gpointer user_data) |
| 21 |
{ |
| 22 |
clutter_state_set_state (state, "start"); |
| 23 |
clutter_ungrab_pointer (); |
| 24 |
return TRUE; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
static ClutterActor *new_rect (gint r, |
| 29 |
gint g, |
| 30 |
gint b, |
| 31 |
gint a) |
| 32 |
{ |
| 33 |
GError *error = NULL; |
| 34 |
ClutterColor *color = clutter_color_new (r, g, b, a); |
| 35 |
ClutterActor *rectangle; |
| 36 |
|
| 37 |
gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); |
| 38 |
rectangle = clutter_texture_new_from_file (file, &error); |
| 39 |
if (rectangle == NULL) |
| 40 |
g_error ("image load failed: %s", error->message); |
| 41 |
g_free (file); |
| 42 |
|
| 43 |
clutter_actor_set_size (rectangle, 128, 128); |
| 44 |
clutter_color_free (color); |
| 45 |
return rectangle; |
| 46 |
} |
| 47 |
|
| 48 |
G_MODULE_EXPORT gint |
| 49 |
test_state_animator_main (gint argc, |
| 50 |
gchar **argv) |
| 51 |
{ |
| 52 |
ClutterActor *stage; |
| 53 |
ClutterActor *rects[40]; |
| 54 |
gint i; |
| 55 |
|
| 56 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 57 |
return 1; |
| 58 |
|
| 59 |
stage = clutter_stage_new (); |
| 60 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "State and Animator"); |
| 61 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 62 |
|
| 63 |
for (i = 0; i < 2; i++) |
| 64 |
{ |
| 65 |
rects[i] = new_rect (255 * (i * 1.0 / 40), 50, 160, 255); |
| 66 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]); |
| 67 |
clutter_actor_set_anchor_point (rects[i], 64, 64); |
| 68 |
clutter_actor_set_position (rects[i], 320.0, 240.0); |
| 69 |
clutter_actor_set_opacity (rects[i], 0x70); |
| 70 |
|
| 71 |
clutter_actor_set_reactive (rects[i], TRUE); |
| 72 |
g_signal_connect (rects[i], "button-press-event", G_CALLBACK (press_event), NULL); |
| 73 |
g_signal_connect (rects[i], "button-release-event", G_CALLBACK (release_event), NULL); |
| 74 |
} |
| 75 |
|
| 76 |
state = clutter_state_new (); |
| 77 |
clutter_state_set (state, NULL, "start", |
| 78 |
rects[0], "depth", CLUTTER_LINEAR, 0.0, |
| 79 |
rects[0], "x", CLUTTER_LINEAR, 100.0, |
| 80 |
rects[0], "y", CLUTTER_LINEAR, 300.0, |
| 81 |
rects[1], "opacity", CLUTTER_LINEAR, 0x20, |
| 82 |
rects[1], "scale-x", CLUTTER_LINEAR, 1.0, |
| 83 |
rects[1], "scale-y", CLUTTER_LINEAR, 1.0, |
| 84 |
NULL); |
| 85 |
clutter_state_set (state, NULL, "end", |
| 86 |
rects[0], "depth", CLUTTER_LINEAR, 200.0, |
| 87 |
rects[0], "x", CLUTTER_LINEAR, 320.0, |
| 88 |
rects[0], "y", CLUTTER_LINEAR, 240.0, |
| 89 |
rects[1], "opacity", CLUTTER_LINEAR, 0xff, |
| 90 |
rects[1], "scale-x", CLUTTER_LINEAR, 2.0, |
| 91 |
rects[1], "scale-y", CLUTTER_LINEAR, 2.0, |
| 92 |
NULL); |
| 93 |
|
| 94 |
animator = clutter_animator_new (); |
| 95 |
clutter_animator_set (animator, |
| 96 |
rects[0], "depth", -1, 0.0, 0.0, |
| 97 |
rects[0], "depth", CLUTTER_LINEAR, 1.0, 275.0, |
| 98 |
rects[0], "x", -1, 0.0, 0.0, |
| 99 |
rects[0], "x", CLUTTER_LINEAR, 0.5, 200.0, |
| 100 |
rects[0], "x", CLUTTER_LINEAR, 1.0, 320.0, |
| 101 |
|
| 102 |
rects[0], "y", -1, 0.0, 0.0, |
| 103 |
rects[0], "y", CLUTTER_LINEAR, 0.3, 100.0, |
| 104 |
rects[0], "y", CLUTTER_LINEAR, 1.0, 240.0, |
| 105 |
|
| 106 |
rects[1], "opacity", -1, 0.0, 0x20, |
| 107 |
rects[1], "opacity", CLUTTER_LINEAR, 1.0, 0xff, |
| 108 |
rects[1], "scale-x", -1, 0.0, 1.0, |
| 109 |
rects[1], "scale-x", CLUTTER_LINEAR, 0.5, 2.0, |
| 110 |
rects[1], "scale-x", CLUTTER_LINEAR, 1.0, 2.0, |
| 111 |
rects[1], "scale-y", -1, 0.0, 1.0, |
| 112 |
rects[1], "scale-y", CLUTTER_LINEAR, 0.5, 2.0, |
| 113 |
rects[1], "scale-y", CLUTTER_LINEAR, 1.0, 2.0, |
| 114 |
NULL); |
| 115 |
|
| 116 |
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "depth", TRUE); |
| 117 |
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "x", TRUE); |
| 118 |
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "y", TRUE); |
| 119 |
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[1]), "opacity", TRUE); |
| 120 |
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[1]), "scale-x", TRUE); |
| 121 |
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[1]), "scale-y", TRUE); |
| 122 |
|
| 123 |
clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]), "x", |
| 124 |
CLUTTER_INTERPOLATION_CUBIC); |
| 125 |
clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]), "y", |
| 126 |
CLUTTER_INTERPOLATION_CUBIC); |
| 127 |
|
| 128 |
clutter_state_set_animator (state, "start", "end", animator); |
| 129 |
g_object_unref (animator); |
| 130 |
|
| 131 |
clutter_actor_show (stage); |
| 132 |
clutter_state_set_state (state, "start"); |
| 133 |
|
| 134 |
clutter_main (); |
| 135 |
g_object_unref (state); |
| 136 |
|
| 137 |
return EXIT_SUCCESS; |
| 138 |
} |
| 139 |
|
| 140 |
G_MODULE_EXPORT const char * |
| 141 |
test_state_animator_describe (void) |
| 142 |
{ |
| 143 |
return "Animate using the State and Animator classes."; |
| 144 |
} |