mirror of
https://github.com/brl/mutter.git
synced 2024-12-30 14:42:14 +00:00
589c8d9579
This adds a boolean "pick-with-alpha" property to ClutterTexture and when true, it will use the textures alpha channel to define the actors shape when picking. Users should be aware that it's a bit more expensive to pick textures like this (so probably best not to blindly enable it on *all* your textures) since it implies rasterizing the texture during picking whereas we would otherwise just send a solid filled quad to the GPU. It will also interrupt the internal batching of geometry for pick renders which can otherwise often be done in a single draw call.
90 lines
2.7 KiB
C
90 lines
2.7 KiB
C
#include <glib.h>
|
|
#include <clutter/clutter.h>
|
|
#include <string.h>
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
static CoglHandle
|
|
make_texture (void)
|
|
{
|
|
guint32 *data = g_malloc (100 * 100 * 4);
|
|
int x;
|
|
int y;
|
|
|
|
for (y = 0; y < 100; y ++)
|
|
for (x = 0; x < 100; x++)
|
|
{
|
|
if (x < 50 && y < 50)
|
|
data[y * 100 + x] = 0xff00ff00;
|
|
else
|
|
data[y * 100 + x] = 0xff00ffff;
|
|
}
|
|
return cogl_texture_new_from_data (100,
|
|
100,
|
|
COGL_TEXTURE_NONE,
|
|
COGL_PIXEL_FORMAT_ARGB_8888,
|
|
COGL_PIXEL_FORMAT_ARGB_8888,
|
|
400,
|
|
(guchar *)data);
|
|
}
|
|
|
|
void
|
|
test_texture_pick_with_alpha (TestConformSimpleFixture *fixture,
|
|
gconstpointer data)
|
|
{
|
|
ClutterTexture *tex = CLUTTER_TEXTURE (clutter_texture_new ());
|
|
ClutterStage *stage = CLUTTER_STAGE (clutter_stage_get_default ());
|
|
ClutterActor *actor;
|
|
|
|
clutter_texture_set_cogl_texture (tex, make_texture ());
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (tex));
|
|
|
|
clutter_actor_show (CLUTTER_ACTOR (stage));
|
|
|
|
if (g_test_verbose ())
|
|
{
|
|
g_print ("\nstage = %p\n", stage);
|
|
g_print ("texture = %p\n\n", tex);
|
|
}
|
|
|
|
clutter_texture_set_pick_with_alpha (tex, TRUE);
|
|
if (g_test_verbose ())
|
|
g_print ("Testing with pick-with-alpha enabled:\n");
|
|
|
|
/* This should fall through and hit the stage: */
|
|
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 10);
|
|
if (g_test_verbose ())
|
|
g_print ("actor @ (10, 10) = %p\n", actor);
|
|
g_assert (actor == CLUTTER_ACTOR (stage));
|
|
|
|
/* The rest should hit the texture */
|
|
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 90, 10);
|
|
if (g_test_verbose ())
|
|
g_print ("actor @ (90, 10) = %p\n", actor);
|
|
g_assert (actor == CLUTTER_ACTOR (tex));
|
|
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 90, 90);
|
|
if (g_test_verbose ())
|
|
g_print ("actor @ (90, 90) = %p\n", actor);
|
|
g_assert (actor == CLUTTER_ACTOR (tex));
|
|
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 90);
|
|
if (g_test_verbose ())
|
|
g_print ("actor @ (10, 90) = %p\n", actor);
|
|
g_assert (actor == CLUTTER_ACTOR (tex));
|
|
|
|
clutter_texture_set_pick_with_alpha (tex, FALSE);
|
|
if (g_test_verbose ())
|
|
g_print ("Testing with pick-with-alpha disabled:\n");
|
|
|
|
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, 10, 10);
|
|
if (g_test_verbose ())
|
|
g_print ("actor @ (10, 10) = %p\n", actor);
|
|
g_assert (actor == CLUTTER_ACTOR (tex));
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (tex));
|
|
|
|
if (g_test_verbose ())
|
|
g_print ("OK\n");
|
|
}
|
|
|