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