Debian Codegraph @

tests/interactive/test-animation.c

raw
1 #include <stdlib.h>
2 #include <gmodule.h>
3 #include <clutter/clutter.h>
4
5 static gboolean is_expanded = FALSE;
6
7 static void
8 on_rect_transitions_completed (ClutterActor *actor)
9 {
10 is_expanded = !is_expanded;
11
12 g_print ("Animation complete\n");
13
14 clutter_actor_set_reactive (actor, TRUE);
15 }
16
17 static void
18 on_clicked (ClutterClickAction *action,
19 ClutterActor *actor,
20 gpointer dummy G_GNUC_UNUSED)
21 {
22 ClutterAnimation *animation;
23 gfloat old_x, old_y, new_x, new_y;
24 gfloat old_width, old_height, new_width, new_height;
25 gdouble new_angle;
26 const ClutterColor *new_color;
27 guint8 new_opacity;
28
29 clutter_actor_get_position (actor, &old_x, &old_y);
30 clutter_actor_get_size (actor, &old_width, &old_height);
31
32 /* determine the final state of the animation depending on
33 * the state of the actor
34 */
35 if (!is_expanded)
36 {
37 new_x = old_x - 100;
38 new_y = old_y - 100;
39 new_width = old_width + 200;
40 new_height = old_height + 200;
41 new_angle = 360.0;
42
43 new_color = CLUTTER_COLOR_DarkScarletRed;
44
45 new_opacity = 255;
46 }
47 else
48 {
49 new_x = old_x + 100;
50 new_y = old_y + 100;
51 new_width = old_width - 200;
52 new_height = old_height - 200;
53 new_angle = 0.0;
54
55 new_color = CLUTTER_COLOR_LightOrange;
56
57 new_opacity = 128;
58 }
59
60 clutter_actor_save_easing_state (actor);
61 clutter_actor_set_easing_mode (actor, CLUTTER_EASE_IN_EXPO);
62 clutter_actor_set_easing_duration (actor, 2000);
63
64 clutter_actor_set_position (actor, new_x, new_y);
65 clutter_actor_set_size (actor, new_width, new_height);
66 clutter_actor_set_background_color (actor, new_color);
67 clutter_actor_set_rotation_angle (actor, CLUTTER_Z_AXIS, new_angle);
68 clutter_actor_set_reactive (actor, FALSE);
69
70 /* animate the opacity halfway through, with a different pacing */
71 clutter_actor_save_easing_state (actor);
72 clutter_actor_set_easing_mode (actor, CLUTTER_LINEAR);
73 clutter_actor_set_easing_delay (actor, 1000);
74 clutter_actor_set_easing_duration (actor, 1000);
75 clutter_actor_set_opacity (actor, new_opacity);
76 clutter_actor_restore_easing_state (actor);
77
78 clutter_actor_restore_easing_state (actor);
79 }
80
81 G_MODULE_EXPORT int
82 test_animation_main (int argc, char *argv[])
83 {
84 ClutterActor *stage, *rect;
85 ClutterColor rect_color = { 0x44, 0xdd, 0x44, 0xff };
86 ClutterAction *action;
87
88 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
89 return 1;
90
91 stage = clutter_stage_new ();
92 clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue);
93 clutter_stage_set_title (CLUTTER_STAGE (stage), "Animation");
94 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
95
96 rect = clutter_actor_new ();
97 clutter_actor_set_background_color (rect, CLUTTER_COLOR_LightOrange);
98 clutter_actor_add_child (stage, rect);
99 clutter_actor_set_size (rect, 50, 50);
100 clutter_actor_set_pivot_point (rect, .5f, .5f);
101 clutter_actor_set_translation (rect, -25, -25, 0);
102 clutter_actor_set_position (rect,
103 clutter_actor_get_width (stage) / 2,
104 clutter_actor_get_height (stage) / 2);
105 clutter_actor_set_opacity (rect, 128);
106 clutter_actor_set_reactive (rect, TRUE);
107 g_signal_connect (rect, "transitions-completed",
108 G_CALLBACK (on_rect_transitions_completed),
109 NULL);
110
111 action = clutter_click_action_new ();
112 g_signal_connect (action, "clicked", G_CALLBACK (on_clicked), NULL);
113 clutter_actor_add_action_with_name (rect, "click", action);
114
115 clutter_actor_show (stage);
116
117 clutter_main ();
118
119 return EXIT_SUCCESS;
120 }
121
122 G_MODULE_EXPORT const char *
123 test_animation_describe (void)
124 {
125 return "Simple animation demo";
126 }