| 1 |
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS |
| 2 |
#include <clutter/clutter.h> |
| 3 |
#include <string.h> |
| 4 |
|
| 5 |
static CoglHandle |
| 6 |
make_texture (void) |
| 7 |
{ |
| 8 |
guint32 *data = g_malloc (100 * 100 * 4); |
| 9 |
int x; |
| 10 |
int y; |
| 11 |
|
| 12 |
for (y = 0; y < 100; y ++) |
| 13 |
for (x = 0; x < 100; x++) |
| 14 |
{ |
| 15 |
if (x < 50 && y < 50) |
| 16 |
data[y * 100 + x] = 0xff00ff00; |
| 17 |
else |
| 18 |
data[y * 100 + x] = 0xff00ffff; |
| 19 |
} |
| 20 |
return cogl_texture_new_from_data (100, |
| 21 |
100, |
| 22 |
COGL_TEXTURE_NONE, |
| 23 |
COGL_PIXEL_FORMAT_ARGB_8888, |
| 24 |
COGL_PIXEL_FORMAT_ARGB_8888, |
| 25 |
400, |
| 26 |
(guchar *)data); |
| 27 |
} |
| 28 |
|
| 29 |
static void |
| 30 |
texture_pick_with_alpha (void) |
| 31 |
{ |
| 32 |
ClutterTexture *tex = CLUTTER_TEXTURE (clutter_texture_new ()); |
| 33 |
ClutterStage *stage = CLUTTER_STAGE (clutter_test_get_stage ()); |
| 34 |
ClutterActor *actor; |
| 35 |
|
| 36 |
clutter_texture_set_cogl_texture (tex, make_texture ()); |
| 37 |
|
| 38 |
clutter_actor_add_child (CLUTTER_ACTOR (stage), CLUTTER_ACTOR (tex)); |
| 39 |
|
| 40 |
clutter_actor_show (CLUTTER_ACTOR (stage)); |
| 41 |
|
| 42 |
if (g_test_verbose ()) |
| 43 |
{ |
| 44 |
g_print ("\nstage = %p\n", stage); |
| 45 |
g_print ("texture = %p\n\n", tex); |
| 46 |
} |
| 47 |
|
| 48 |
clutter_texture_set_pick_with_alpha (tex, TRUE); |
| 49 |
if (g_test_verbose ()) |
| 50 |
g_print ("Testing with pick-with-alpha enabled:\n"); |
| 51 |
|
| 52 |
/* This should fall through and hit the stage: */ |
| 53 |
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 10); |
| 54 |
if (g_test_verbose ()) |
| 55 |
g_print ("actor @ (10, 10) = %p\n", actor); |
| 56 |
g_assert (actor == CLUTTER_ACTOR (stage)); |
| 57 |
|
| 58 |
/* The rest should hit the texture */ |
| 59 |
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 90, 10); |
| 60 |
if (g_test_verbose ()) |
| 61 |
g_print ("actor @ (90, 10) = %p\n", actor); |
| 62 |
g_assert (actor == CLUTTER_ACTOR (tex)); |
| 63 |
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 90, 90); |
| 64 |
if (g_test_verbose ()) |
| 65 |
g_print ("actor @ (90, 90) = %p\n", actor); |
| 66 |
g_assert (actor == CLUTTER_ACTOR (tex)); |
| 67 |
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 90); |
| 68 |
if (g_test_verbose ()) |
| 69 |
g_print ("actor @ (10, 90) = %p\n", actor); |
| 70 |
g_assert (actor == CLUTTER_ACTOR (tex)); |
| 71 |
|
| 72 |
clutter_texture_set_pick_with_alpha (tex, FALSE); |
| 73 |
if (g_test_verbose ()) |
| 74 |
g_print ("Testing with pick-with-alpha disabled:\n"); |
| 75 |
|
| 76 |
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 10); |
| 77 |
if (g_test_verbose ()) |
| 78 |
g_print ("actor @ (10, 10) = %p\n", actor); |
| 79 |
g_assert (actor == CLUTTER_ACTOR (tex)); |
| 80 |
} |
| 81 |
|
| 82 |
CLUTTER_TEST_SUITE ( |
| 83 |
CLUTTER_TEST_UNIT ("/texture/pick-with-alpha", texture_pick_with_alpha) |
| 84 |
) |