Debian Codegraph @

tests/performance/test-state-hidden.c

raw
1 #include <stdlib.h>
2 #include <math.h>
3 #include <gmodule.h>
4 #include <clutter/clutter.h>
5 #include "test-common.h"
6
7 #define STAGE_WIDTH 160
8 #define STAGE_HEIGHT 120
9
10 #define ACTOR_WIDTH 8
11 #define ACTOR_HEIGHT 8
12
13 #define COLS (STAGE_WIDTH/ACTOR_WIDTH)
14 #define ROWS (STAGE_HEIGHT/ACTOR_HEIGHT)
15 #define TOTAL (ROWS*COLS)
16
17
18 static void completed (ClutterState *state,
19 gpointer data)
20 {
21 if (g_str_equal (clutter_state_get_state (state), "right"))
22 {
23 /* skip straight to left state when reaching right */
24 clutter_state_warp_to_state (state, "left");
25 }
26 else if (g_str_equal (clutter_state_get_state (state), "active"))
27 clutter_state_set_state (state, "right");
28 else
29 {
30 clutter_state_set_state (state, "active");
31 }
32 }
33
34 static ClutterActor *new_rect (gint r,
35 gint g,
36 gint b,
37 gint a)
38 {
39 ClutterColor *color = clutter_color_new (r, g, b, a);
40 ClutterActor *group = clutter_group_new ();
41 ClutterActor *rectangle = clutter_rectangle_new_with_color (color);
42
43 gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL);
44
45 g_free (file);
46 clutter_actor_set_size (rectangle, ACTOR_WIDTH,ACTOR_HEIGHT);
47 clutter_color_free (color);
48 clutter_container_add (CLUTTER_CONTAINER (group), rectangle, NULL);
49 return group;
50 }
51
52 gint
53 main (gint argc,
54 gchar **argv)
55 {
56 ClutterActor *stage;
57 ClutterActor *group;
58 ClutterState *layout_state;
59 gint i;
60
61 clutter_perf_fps_init ();
62 if (CLUTTER_INIT_SUCCESS != clutter_init (&argc, &argv))
63 g_error ("Failed to initialize Clutter");
64
65 stage = clutter_stage_new ();
66 group = clutter_group_new ();
67 layout_state = clutter_state_new ();
68 clutter_stage_set_title (CLUTTER_STAGE (stage), "State Performance [hidden]");
69 clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black);
70 clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
71 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
72
73 for (i=0; i<TOTAL; i++)
74 {
75 ClutterActor *actor;
76 ClutterState *a_state;
77
78 int row = i/COLS;
79 int col = i%COLS;
80
81 actor = new_rect (255 * ( 1.0*col/COLS), 50,
82 255 * ( 1.0*row/ROWS), 255);
83 clutter_container_add_actor (CLUTTER_CONTAINER (group), actor);
84 clutter_actor_set_position (actor, 320.0, 240.0);
85 clutter_actor_set_reactive (actor, TRUE);
86
87
88 clutter_state_set (layout_state, NULL, "active",
89 actor, "delayed::x", CLUTTER_LINEAR,
90 ACTOR_WIDTH * 1.0 * ((TOTAL-1-i) % COLS),
91 ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2,
92 actor, "delayed::y", CLUTTER_LINEAR,
93 ACTOR_HEIGHT * 1.0 * ((TOTAL-1-i) / COLS),
94 ((row*1.0/ROWS))/2, 0.0,
95 actor, "rotation-angle-x", CLUTTER_LINEAR, 0.0,
96 actor, "rotation-angle-y", CLUTTER_LINEAR, 0.0,
97 NULL);
98
99 clutter_state_set (layout_state, NULL, "right",
100 actor, "delayed::x", CLUTTER_LINEAR, STAGE_WIDTH * 1.0,
101 ((row*1.0/ROWS))/2,
102 (1.0-(row*1.0/ROWS))/2,
103 actor, "delayed::y", CLUTTER_LINEAR, STAGE_HEIGHT * 1.0,
104 ((row*1.0/ROWS))/2,
105 0.0,
106 NULL);
107
108 clutter_state_set (layout_state, NULL, "left",
109 actor, "rotation-angle-x", CLUTTER_LINEAR, 45.0,
110 actor, "rotation-angle-y", CLUTTER_LINEAR, 5.0,
111 actor, "x", CLUTTER_LINEAR, 0-64.0,
112 actor, "y", CLUTTER_LINEAR, 0-64.0,
113 NULL);
114
115 a_state = clutter_state_new ();
116 g_object_set_data_full (G_OBJECT (actor), "hover-state-machine",
117 a_state, g_object_unref);
118
119 clutter_state_set (a_state, NULL, "normal",
120 actor, "opacity", CLUTTER_LINEAR, 0x77,
121 actor, "rotation-angle-z", CLUTTER_LINEAR, 0.0,
122 NULL);
123 clutter_state_set (a_state, NULL, "hover",
124 actor, "opacity", CLUTTER_LINEAR, 0xff,
125 actor, "rotation-angle-z", CLUTTER_LINEAR, 10.0,
126 NULL);
127 clutter_actor_set_opacity (actor, 0x77);
128
129 clutter_state_set_duration (a_state, NULL, NULL, 500);
130 }
131 clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
132 clutter_actor_set_opacity (group, 0);
133
134 clutter_state_set_duration (layout_state, NULL, NULL, 1000);
135 clutter_state_set_duration (layout_state, "active", "left", 1400);
136
137 g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL);
138
139 clutter_actor_show (stage);
140
141 clutter_state_warp_to_state (layout_state, "left");
142 clutter_state_set_state (layout_state, "active");
143
144 clutter_perf_fps_start (CLUTTER_STAGE (stage));
145 clutter_main ();
146 clutter_perf_fps_report ("test-state-hidden");
147 g_object_unref (layout_state);
148
149 return EXIT_SUCCESS;
150 }