1
0
Fork 0
mutter-performance-source/tests/test-pick.c
Neil Roberts 8d429e8abc Bug 1034 - Picking doesn't work on Eee PC
* clutter/clutter-main.c (_clutter_id_to_color): When choosing a
	pick color, set all but the most significant of the unused
	bits. This should make make it more likely that the GL
	implementation will round down to the right value.

	* tests/test-pick.c: Test case for picking. It creates 192 actors
	at known positions and stores their gids. It then calls
	clutter_stage_get_actor_at_pos with each position to check that
	the right gid is returned.

	* tests/Makefile.am (noinst_PROGRAMS): Add test-pick
2008-09-12 12:43:25 +00:00

99 lines
2.1 KiB
C

#include <clutter/clutter.h>
#define STAGE_WIDTH 320
#define STAGE_HEIGHT 200
#define ACTORS_X 12
#define ACTORS_Y 16
typedef struct _Data Data;
struct _Data
{
ClutterActor *stage;
int y, x;
guint32 gids[ACTORS_X * ACTORS_Y];
guint actor_width, actor_height;
int ret;
};
static gboolean
on_timeout (Data *data)
{
int y, x;
for (y = 0; y < ACTORS_Y; y++)
for (x = 0; x < ACTORS_X; x++)
{
gboolean pass = FALSE;
guint32 gid;
ClutterActor *actor
= clutter_stage_get_actor_at_pos (CLUTTER_STAGE (data->stage),
x * data->actor_width
+ data->actor_width / 2,
y * data->actor_height
+ data->actor_height / 2);
printf ("actor %u -> ", data->gids[y * ACTORS_X + x]);
if (actor == NULL)
printf ("NULL: FAIL\n");
else
{
gid = clutter_actor_get_gid (actor);
if (gid == data->gids[y * ACTORS_X + x])
pass = TRUE;
printf ("% 8i: %s\n", gid, pass ? "pass" : "FAIL");
}
if (!pass)
data->ret = 1;
}
clutter_main_quit ();
return FALSE;
}
int
main (int argc, char **argv)
{
int y, x;
Data data;
data.ret = 0;
clutter_init (&argc, &argv);
data.stage = clutter_stage_get_default ();
clutter_actor_set_size (data.stage, STAGE_WIDTH, STAGE_HEIGHT);
data.actor_width = STAGE_WIDTH / ACTORS_X;
data.actor_height = STAGE_HEIGHT / ACTORS_Y;
for (y = 0; y < ACTORS_Y; y++)
for (x = 0; x < ACTORS_X; x++)
{
ClutterColor color = { x * 255 / (ACTORS_X - 1),
y * 255 / (ACTORS_Y - 1),
128, 255 };
ClutterGeometry geom = { x * data.actor_width, y * data.actor_height,
data.actor_width, data.actor_height };
ClutterActor *rect = clutter_rectangle_new_with_color (&color);
clutter_actor_set_geometry (rect, &geom);
clutter_container_add (CLUTTER_CONTAINER (data.stage), rect, NULL);
data.gids[y * ACTORS_X + x] = clutter_actor_get_gid (rect);
}
clutter_actor_show (data.stage);
g_timeout_add (250, (GSourceFunc) on_timeout, &data);
clutter_main ();
printf ("end result: %s\n", data.ret ? "FAIL" : "pass");
return data.ret;
}