Debian Codegraph @

tests/interactive/test-animator.c

raw
1 #include <stdlib.h>
2 #include <math.h>
3 #include <gmodule.h>
4 #include <clutter/clutter.h>
5
6 static ClutterAnimator *animator;
7
8 static ClutterActor *new_rect (gint r,
9 gint g,
10 gint b,
11 gint a)
12 {
13 GError *error = NULL;
14 ClutterColor *color = clutter_color_new (r, g, b, a);
15 ClutterActor *rectangle;
16
17 gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
18 rectangle = clutter_texture_new_from_file (file, &error);
19 if (rectangle == NULL)
20 g_error ("image load failed: %s", error->message);
21 g_free (file);
22
23 clutter_actor_set_size (rectangle, 128, 128);
24 clutter_color_free (color);
25 return rectangle;
26 }
27
28 static gboolean nuke_one (gpointer actor)
29 {
30 clutter_actor_destroy (actor);
31 return FALSE;
32 }
33
34 #define COUNT 4
35
36 static void reverse_timeline (ClutterTimeline *timeline,
37 gpointer data)
38 {
39 ClutterTimelineDirection direction = clutter_timeline_get_direction (timeline);
40 if (direction == CLUTTER_TIMELINE_FORWARD)
41 clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_BACKWARD);
42 else
43 clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_FORWARD);
44 clutter_timeline_start (timeline);
45 }
46
47
48 G_MODULE_EXPORT gint
49 test_animator_main (gint argc,
50 gchar **argv)
51 {
52 ClutterActor *stage;
53 ClutterActor *rects[COUNT];
54 gint i;
55 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
56 return 1;
57
58 stage = clutter_stage_new ();
59 clutter_stage_set_title (CLUTTER_STAGE (stage), "Animator");
60 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
61
62 for (i = 0; i < COUNT; i++)
63 {
64 rects[i] = new_rect (255 * (i * 1.0 / COUNT), 50, 160, 255);
65 clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]);
66 clutter_actor_set_anchor_point (rects[i], 64, 64);
67 clutter_actor_set_position (rects[i], 320.0, 240.0);
68 clutter_actor_set_opacity (rects[i], 0x70);
69 }
70
71 clutter_threads_add_timeout (10000, nuke_one, rects[2]);
72
73 animator = clutter_animator_new ();
74
75 /* Note: when both animations are active for the same actor at the same
76 * time there is a race, such races should be handled by avoiding
77 * controlling the same properties from multiple animations. This is
78 * an intentional design flaw of this test for testing the corner case.
79 */
80
81 clutter_animator_set (animator,
82 rects[0], "x", 1, 0.0, 180.0,
83 rects[0], "x", CLUTTER_LINEAR, 0.25, 450.0,
84 rects[0], "x", CLUTTER_LINEAR, 0.5, 450.0,
85 rects[0], "x", CLUTTER_LINEAR, 0.75, 180.0,
86 rects[0], "x", CLUTTER_LINEAR, 1.0, 180.0,
87
88 rects[0], "y", -1, 0.0, 100.0,
89 rects[0], "y", CLUTTER_LINEAR, 0.25, 100.0,
90 rects[0], "y", CLUTTER_LINEAR, 0.5, 380.0,
91 rects[0], "y", CLUTTER_LINEAR, 0.75, 380.0,
92 rects[0], "y", CLUTTER_LINEAR, 1.0, 100.0,
93
94 rects[3], "x", 0, 0.0, 180.0,
95 rects[3], "x", CLUTTER_LINEAR, 0.25, 180.0,
96 rects[3], "x", CLUTTER_LINEAR, 0.5, 450.0,
97 rects[3], "x", CLUTTER_LINEAR, 0.75, 450.0,
98 rects[3], "x", CLUTTER_LINEAR, 1.0, 180.0,
99
100 rects[3], "y", 0, 0.0, 100.0,
101 rects[3], "y", CLUTTER_LINEAR, 0.25, 380.0,
102 rects[3], "y", CLUTTER_LINEAR, 0.5, 380.0,
103 rects[3], "y", CLUTTER_LINEAR, 0.75, 100.0,
104 rects[3], "y", CLUTTER_LINEAR, 1.0, 100.0,
105
106
107 rects[2], "rotation-angle-y", 0, 0.0, 0.0,
108 rects[2], "rotation-angle-y", CLUTTER_LINEAR, 1.0, 360.0,
109
110 rects[1], "scale-x", 0, 0.0, 1.0,
111 rects[1], "scale-x", CLUTTER_LINEAR, 1.0, 2.0,
112 rects[1], "scale-y", 0, 0.0, 1.0,
113 rects[1], "scale-y", CLUTTER_LINEAR, 1.0, 2.0,
114 NULL);
115
116
117 clutter_actor_set_scale (rects[0], 1.4, 1.4);
118 clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "x",
119 TRUE);
120 clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "y",
121 TRUE);
122 clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]),
123 "x", CLUTTER_INTERPOLATION_CUBIC);
124 clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]),
125 "y", CLUTTER_INTERPOLATION_CUBIC);
126
127 clutter_stage_hide_cursor(CLUTTER_STAGE (stage));
128 clutter_actor_show (stage);
129 clutter_animator_set_duration (animator, 5000);
130
131 g_signal_connect (clutter_animator_start (animator),
132 "completed", G_CALLBACK (reverse_timeline), NULL);
133 clutter_main ();
134
135 g_object_unref (animator);
136
137 return EXIT_SUCCESS;
138 }