Debian Codegraph @

tests/interactive/test-multistage.c

raw
1 #include <gmodule.h>
2 #include <clutter/clutter.h>
3
4 static GList *stages = NULL;
5 static gint n_stages = 1;
6
7 static gboolean
8 tex_button_cb (ClutterActor *actor,
9 ClutterEvent *event,
10 gpointer data)
11 {
12 clutter_actor_hide (actor);
13
14 return TRUE;
15 }
16
17 static void
18 on_destroy (ClutterActor *actor)
19 {
20 stages = g_list_remove (stages, actor);
21 }
22
23 static gboolean
24 on_button_press (ClutterActor *actor,
25 ClutterEvent *event,
26 gpointer data)
27 {
28 ClutterActor *new_stage;
29 ClutterActor *label, *tex;
30 gint width, height;
31 gchar *stage_label, *stage_name;
32 ClutterTimeline *timeline;
33 ClutterAlpha *alpha;
34 ClutterBehaviour *r_behave;
35
36 new_stage = clutter_stage_new ();
37 if (new_stage == NULL)
38 return FALSE;
39
40 stage_name = g_strdup_printf ("Stage [%d]", ++n_stages);
41
42 clutter_stage_set_title (CLUTTER_STAGE (new_stage), stage_name);
43 clutter_actor_set_background_color (new_stage,
44 CLUTTER_COLOR_DarkScarletRed);
45 clutter_actor_set_size (new_stage, 320, 240);
46 clutter_actor_set_name (new_stage, stage_name);
47
48 g_signal_connect (new_stage, "destroy", G_CALLBACK (on_destroy), NULL);
49
50 tex = clutter_texture_new_from_file (TESTS_DATADIR
51 G_DIR_SEPARATOR_S
52 "redhand.png",
53 NULL);
54
55 if (!tex)
56 g_error ("pixbuf load failed");
57
58 clutter_actor_set_reactive (tex, TRUE);
59 g_signal_connect (tex, "button-press-event",
60 G_CALLBACK (tex_button_cb), NULL);
61
62 clutter_container_add_actor (CLUTTER_CONTAINER (new_stage), tex);
63
64 stage_label = g_strconcat ("<b>", stage_name, "</b>", NULL);
65 label = clutter_text_new_with_text ("Mono 12", stage_label);
66
67 clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White);
68 clutter_text_set_use_markup (CLUTTER_TEXT (label), TRUE);
69 width = (clutter_actor_get_width (new_stage)
70 - clutter_actor_get_width (label)) / 2;
71 height = (clutter_actor_get_height (new_stage)
72 - clutter_actor_get_height (label)) / 2;
73 clutter_actor_set_position (label, width, height);
74 clutter_container_add_actor (CLUTTER_CONTAINER (new_stage), label);
75 clutter_actor_show (label);
76 g_free (stage_label);
77
78 /*
79 g_signal_connect (new_stage, "button-press-event",
80 G_CALLBACK (clutter_actor_destroy),
81 NULL);
82 */
83
84 timeline = clutter_timeline_new (2000);
85 clutter_timeline_set_repeat_count (timeline, -1);
86
87 alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
88 r_behave = clutter_behaviour_rotate_new (alpha,
89 CLUTTER_Y_AXIS,
90 CLUTTER_ROTATE_CW,
91 0.0, 360.0);
92
93 clutter_behaviour_rotate_set_center (CLUTTER_BEHAVIOUR_ROTATE (r_behave),
94 clutter_actor_get_width (label)/2,
95 0,
96 0);
97
98 clutter_behaviour_apply (r_behave, label);
99 clutter_timeline_start (timeline);
100
101 clutter_actor_show_all (new_stage);
102
103 stages = g_list_prepend (stages, new_stage);
104
105 g_free (stage_name);
106
107 return TRUE;
108 }
109
110 G_MODULE_EXPORT int
111 test_multistage_main (int argc, char *argv[])
112 {
113 ClutterActor *stage_default;
114 ClutterActor *label;
115 gint width, height;
116
117 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
118 return 1;
119
120 stage_default = clutter_stage_new ();
121 clutter_stage_set_title (CLUTTER_STAGE (stage_default), "Default Stage");
122 clutter_actor_set_name (stage_default, "Default Stage");
123 g_signal_connect (stage_default, "destroy",
124 G_CALLBACK (clutter_main_quit),
125 NULL);
126 g_signal_connect (stage_default, "button-press-event",
127 G_CALLBACK (on_button_press),
128 NULL);
129
130 label = clutter_text_new_with_text ("Mono 16", "Default stage");
131 width = (clutter_actor_get_width (stage_default)
132 - clutter_actor_get_width (label))
133 / 2;
134 height = (clutter_actor_get_height (stage_default)
135 - clutter_actor_get_height (label))
136 / 2;
137 clutter_actor_set_position (label, width, height);
138 clutter_container_add_actor (CLUTTER_CONTAINER (stage_default), label);
139 clutter_actor_show (label);
140
141 clutter_actor_show (stage_default);
142
143 clutter_main ();
144
145 g_list_foreach (stages, (GFunc) clutter_actor_destroy, NULL);
146 g_list_free (stages);
147
148 return 0;
149 }