2007-05-09 19:31:08 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2007-08-13 16:48:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
key_focus_in_cb (ClutterActor *actor,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ClutterActor *focus_box = CLUTTER_ACTOR(data);
|
|
|
|
|
|
|
|
if (actor == clutter_stage_get_default ())
|
|
|
|
{
|
|
|
|
clutter_actor_hide (focus_box);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clutter_actor_show (focus_box);
|
|
|
|
clutter_actor_set_position (focus_box,
|
|
|
|
clutter_actor_get_x (actor) - 5,
|
|
|
|
clutter_actor_get_y (actor) - 5);
|
|
|
|
|
|
|
|
clutter_actor_set_size (focus_box,
|
|
|
|
clutter_actor_get_width (actor) + 10,
|
|
|
|
clutter_actor_get_height (actor) + 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-09 19:31:08 -04:00
|
|
|
static void
|
2007-08-13 16:48:01 -04:00
|
|
|
input_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer data)
|
2007-05-09 19:31:08 -04:00
|
|
|
{
|
2007-08-13 16:48:01 -04:00
|
|
|
|
|
|
|
gchar keybuf[9], *source = (gchar*)data;
|
2007-06-18 05:15:00 -04:00
|
|
|
int len = 0;
|
|
|
|
|
2007-05-09 19:31:08 -04:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_KEY_PRESS:
|
2007-06-18 05:15:00 -04:00
|
|
|
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval),
|
|
|
|
keybuf);
|
|
|
|
keybuf[len] = '\0';
|
2007-08-13 16:48:01 -04:00
|
|
|
printf ("[%s] KEY PRESS '%s'", source, keybuf);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_KEY_RELEASE:
|
2007-06-18 05:15:00 -04:00
|
|
|
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval),
|
|
|
|
keybuf);
|
|
|
|
keybuf[len] = '\0';
|
2007-08-13 16:48:01 -04:00
|
|
|
printf ("[%s] KEY RELEASE '%s'", source, keybuf);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_MOTION:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] MOTION", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] BUTTON PRESS", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_2BUTTON_PRESS:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] BUTTON 2 PRESS", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_3BUTTON_PRESS:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] BUTTON 3 PRESS", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] BUTTON RELEASE", source);
|
|
|
|
if (clutter_event_get_source (event) == actor)
|
|
|
|
clutter_stage_set_key_focus
|
|
|
|
(CLUTTER_STAGE(clutter_stage_get_default ()), actor);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_SCROLL:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] BUTTON SCROLL", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_STAGE_STATE:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] STAGE STATE", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_DESTROY_NOTIFY:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] DESTROY NOTIFY", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_CLIENT_MESSAGE:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] CLIENT MESSAGE\n", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_DELETE:
|
2007-08-13 16:48:01 -04:00
|
|
|
printf("[%s] DELETE", source);
|
2007-05-09 19:31:08 -04:00
|
|
|
break;
|
2007-07-26 07:04:04 -04:00
|
|
|
case CLUTTER_NOTHING:
|
2007-08-13 16:48:01 -04:00
|
|
|
return;
|
2007-05-09 19:31:08 -04:00
|
|
|
}
|
2007-08-13 16:48:01 -04:00
|
|
|
|
|
|
|
if (clutter_event_get_source (event) == actor)
|
|
|
|
printf(" *source*");
|
|
|
|
printf("\n");
|
|
|
|
|
2007-05-09 19:31:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2007-08-13 16:48:01 -04:00
|
|
|
ClutterActor *stage, *actor, *focus_box;
|
|
|
|
ClutterColor rcol = { 0xff, 0, 0, 0xff},
|
|
|
|
bcol = { 0, 0, 0xff, 0xff },
|
|
|
|
gcol = { 0, 0xff, 0, 0xff },
|
|
|
|
ncol = { 0, 0, 0, 0xff };
|
2007-05-09 19:31:08 -04:00
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
2007-08-13 16:48:01 -04:00
|
|
|
g_signal_connect (stage, "event", G_CALLBACK (input_cb), "stage");
|
|
|
|
|
|
|
|
focus_box = clutter_rectangle_new_with_color (&ncol);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), focus_box, NULL);
|
|
|
|
|
|
|
|
actor = clutter_rectangle_new_with_color (&rcol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_position (actor, 100, 100);
|
|
|
|
|
|
|
|
clutter_actor_set_reactive (actor);
|
|
|
|
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "red box");
|
|
|
|
g_signal_connect (actor, "focus-in", G_CALLBACK (key_focus_in_cb),
|
|
|
|
focus_box);
|
|
|
|
|
|
|
|
clutter_stage_set_key_focus (stage, actor);
|
|
|
|
|
|
|
|
actor = clutter_rectangle_new_with_color (&gcol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_position (actor, 250, 100);
|
|
|
|
|
|
|
|
clutter_actor_set_reactive (actor);
|
|
|
|
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "green box");
|
|
|
|
g_signal_connect (actor, "focus-in", G_CALLBACK (key_focus_in_cb),
|
|
|
|
focus_box);
|
|
|
|
|
|
|
|
actor = clutter_rectangle_new_with_color (&bcol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_position (actor, 400, 100);
|
|
|
|
|
|
|
|
clutter_actor_set_reactive (actor);
|
|
|
|
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box");
|
|
|
|
g_signal_connect (actor, "focus-in", G_CALLBACK (key_focus_in_cb),
|
|
|
|
focus_box);
|
|
|
|
|
|
|
|
actor = clutter_rectangle_new_with_color (&ncol);
|
|
|
|
clutter_actor_set_size (actor, 400, 50);
|
|
|
|
clutter_actor_set_position (actor, 100, 250);
|
|
|
|
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box");
|
|
|
|
g_signal_connect (actor, "focus-in", G_CALLBACK (key_focus_in_cb),
|
|
|
|
focus_box);
|
|
|
|
|
|
|
|
g_signal_connect (stage, "focus-in", G_CALLBACK (key_focus_in_cb),
|
|
|
|
focus_box);
|
|
|
|
|
|
|
|
|
2007-05-09 19:31:08 -04:00
|
|
|
clutter_actor_show_all (CLUTTER_ACTOR (stage));
|
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|