| 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 |
GError *error = NULL; |
| 40 |
ClutterColor *color = clutter_color_new (r, g, b, a); |
| 41 |
ClutterActor *group = clutter_group_new (); |
| 42 |
ClutterActor *rectangle = clutter_rectangle_new_with_color (color); |
| 43 |
ClutterActor *hand = NULL; |
| 44 |
|
| 45 |
gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL); |
| 46 |
|
| 47 |
hand = clutter_texture_new_from_file (file, &error); |
| 48 |
if (rectangle == NULL) |
| 49 |
g_error ("image load failed: %s", error->message); |
| 50 |
g_free (file); |
| 51 |
clutter_actor_set_size (hand, ACTOR_WIDTH,ACTOR_HEIGHT); |
| 52 |
|
| 53 |
clutter_actor_set_size (rectangle, ACTOR_WIDTH,ACTOR_HEIGHT); |
| 54 |
clutter_color_free (color); |
| 55 |
clutter_container_add (CLUTTER_CONTAINER (group), rectangle, hand, NULL); |
| 56 |
return group; |
| 57 |
} |
| 58 |
|
| 59 |
gint |
| 60 |
main (gint argc, |
| 61 |
gchar **argv) |
| 62 |
{ |
| 63 |
ClutterActor *stage; |
| 64 |
ClutterState *layout_state; |
| 65 |
gint i; |
| 66 |
|
| 67 |
clutter_perf_fps_init (); |
| 68 |
if (CLUTTER_INIT_SUCCESS != clutter_init (&argc, &argv)) |
| 69 |
g_error ("Failed to initialize Clutter"); |
| 70 |
|
| 71 |
stage = clutter_stage_new (); |
| 72 |
layout_state = clutter_state_new (); |
| 73 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "State Performance [mini]"); |
| 74 |
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black); |
| 75 |
clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); |
| 76 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 77 |
|
| 78 |
for (i=0; i<TOTAL; i++) |
| 79 |
{ |
| 80 |
ClutterActor *actor; |
| 81 |
ClutterState *a_state; |
| 82 |
|
| 83 |
int row = i/COLS; |
| 84 |
int col = i%COLS; |
| 85 |
|
| 86 |
actor = new_rect (255 * ( 1.0*col/COLS), 50, |
| 87 |
255 * ( 1.0*row/ROWS), 255); |
| 88 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); |
| 89 |
clutter_actor_set_position (actor, 320.0, 240.0); |
| 90 |
clutter_actor_set_reactive (actor, TRUE); |
| 91 |
|
| 92 |
|
| 93 |
clutter_state_set (layout_state, NULL, "active", |
| 94 |
actor, "delayed::x", CLUTTER_LINEAR, |
| 95 |
ACTOR_WIDTH * 1.0 * ((TOTAL-1-i) % COLS), |
| 96 |
((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2, |
| 97 |
actor, "delayed::y", CLUTTER_LINEAR, |
| 98 |
ACTOR_HEIGHT * 1.0 * ((TOTAL-1-i) / COLS), |
| 99 |
((row*1.0/ROWS))/2, 0.0, |
| 100 |
actor, "rotation-angle-x", CLUTTER_LINEAR, 0.0, |
| 101 |
actor, "rotation-angle-y", CLUTTER_LINEAR, 0.0, |
| 102 |
NULL); |
| 103 |
|
| 104 |
clutter_state_set (layout_state, NULL, "right", |
| 105 |
actor, "delayed::x", CLUTTER_LINEAR, STAGE_WIDTH * 1.0, |
| 106 |
((row*1.0/ROWS))/2, |
| 107 |
(1.0-(row*1.0/ROWS))/2, |
| 108 |
actor, "delayed::y", CLUTTER_LINEAR, STAGE_HEIGHT * 1.0, |
| 109 |
((row*1.0/ROWS))/2, |
| 110 |
0.0, |
| 111 |
NULL); |
| 112 |
|
| 113 |
clutter_state_set (layout_state, NULL, "left", |
| 114 |
actor, "rotation-angle-x", CLUTTER_LINEAR, 45.0, |
| 115 |
actor, "rotation-angle-y", CLUTTER_LINEAR, 5.0, |
| 116 |
actor, "x", CLUTTER_LINEAR, 0-64.0, |
| 117 |
actor, "y", CLUTTER_LINEAR, 0-64.0, |
| 118 |
NULL); |
| 119 |
|
| 120 |
a_state = clutter_state_new (); |
| 121 |
g_object_set_data_full (G_OBJECT (actor), "hover-state-machine", |
| 122 |
a_state, g_object_unref); |
| 123 |
|
| 124 |
clutter_state_set (a_state, NULL, "normal", |
| 125 |
actor, "opacity", CLUTTER_LINEAR, 0x77, |
| 126 |
actor, "rotation-angle-z", CLUTTER_LINEAR, 0.0, |
| 127 |
NULL); |
| 128 |
clutter_state_set (a_state, NULL, "hover", |
| 129 |
actor, "opacity", CLUTTER_LINEAR, 0xff, |
| 130 |
actor, "rotation-angle-z", CLUTTER_LINEAR, 10.0, |
| 131 |
NULL); |
| 132 |
clutter_actor_set_opacity (actor, 0x77); |
| 133 |
|
| 134 |
clutter_state_set_duration (a_state, NULL, NULL, 500); |
| 135 |
} |
| 136 |
|
| 137 |
clutter_state_set_duration (layout_state, NULL, NULL, 1000); |
| 138 |
clutter_state_set_duration (layout_state, "active", "left", 1400); |
| 139 |
|
| 140 |
g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL); |
| 141 |
|
| 142 |
clutter_actor_show (stage); |
| 143 |
|
| 144 |
clutter_state_warp_to_state (layout_state, "left"); |
| 145 |
clutter_state_set_state (layout_state, "active"); |
| 146 |
|
| 147 |
clutter_perf_fps_start (CLUTTER_STAGE (stage)); |
| 148 |
clutter_main (); |
| 149 |
clutter_perf_fps_report ("test-state-mini"); |
| 150 |
g_object_unref (layout_state); |
| 151 |
|
| 152 |
return EXIT_SUCCESS; |
| 153 |
} |