From c1e2658104046d8895134df5b7519db26a491892 Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Thu, 19 Aug 2010 17:17:58 +0100 Subject: [PATCH] cookbook: Added simple pointer motion example Added a simple pointer motion example which just reports on the stage and actor-relative coordinates of the pointer as it moves. --- doc/cookbook/examples/Makefile.am | 6 +- doc/cookbook/examples/events-pointer-motion.c | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 doc/cookbook/examples/events-pointer-motion.c diff --git a/doc/cookbook/examples/Makefile.am b/doc/cookbook/examples/Makefile.am index 624ddad94..370b61b5f 100644 --- a/doc/cookbook/examples/Makefile.am +++ b/doc/cookbook/examples/Makefile.am @@ -11,8 +11,9 @@ noinst_PROGRAMS = \ layouts-stacking \ layouts-stacking-diff-sized-actors \ events-mouse-scroll \ - events-pointer-motion-crossing \ - events-pointer-motion-scribbler \ + events-pointer-motion \ + events-pointer-motion-crossing \ + events-pointer-motion-scribbler \ $(NULL) INCLUDES = \ @@ -42,6 +43,7 @@ textures_sub_texture_SOURCES = textures-sub-texture.c layouts_stacking_SOURCES = layouts-stacking.c layouts_stacking_diff_sized_actors_SOURCES = layouts-stacking-diff-sized-actors.c events_mouse_scroll_SOURCES = events-mouse-scroll.c +events_pointer_motion_SOURCES = events-pointer-motion.c events_pointer_motion_crossing_SOURCES = events-pointer-motion-crossing.c events_pointer_motion_scribbler_SOURCES = events-pointer-motion-scribbler.c diff --git a/doc/cookbook/examples/events-pointer-motion.c b/doc/cookbook/examples/events-pointer-motion.c new file mode 100644 index 000000000..02293dcf0 --- /dev/null +++ b/doc/cookbook/examples/events-pointer-motion.c @@ -0,0 +1,56 @@ +#include + +static const ClutterColor stage_color = { 0x33, 0x33, 0x55, 0xff }; +static const ClutterColor rectangle_color = { 0xaa, 0x99, 0x00, 0xff }; + +static gboolean +_pointer_moved_cb (ClutterActor *actor, + ClutterEvent *event, + gpointer user_data) +{ + ClutterMotionEvent *motion_event = (ClutterMotionEvent *)event; + + gfloat stage_x = motion_event->x; + gfloat stage_y = motion_event->y; + + gfloat actor_x, actor_y; + clutter_actor_transform_stage_point (actor, + stage_x, stage_y, + &actor_x, &actor_y); + + g_debug ("pointer @ stage x %.0f, y %.0f; actor x %.0f, y %.0f", + stage_x, stage_y, + actor_x, actor_y); + return TRUE; +} + +int +main (int argc, char *argv[]) +{ + ClutterActor *stage; + ClutterActor *rectangle; + + clutter_init (&argc, &argv); + + stage = clutter_stage_get_default (); + clutter_actor_set_size (stage, 400, 400); + clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); + + rectangle = clutter_rectangle_new_with_color (&rectangle_color); + clutter_actor_set_size (rectangle, 300, 300); + clutter_actor_set_position (rectangle, 50, 50); + clutter_actor_set_reactive (rectangle, TRUE); + + clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle); + + g_signal_connect (rectangle, + "motion-event", + G_CALLBACK (_pointer_moved_cb), + NULL); + + clutter_actor_show (stage); + + clutter_main (); + + return 0; +}