[clutter/wip/touch-events] tests: Test touch event delivery to actors



commit 7d4d98b2814bded0396b87a21e501b16922d7e57
Author: Tomeu Vizoso <tomeu vizoso collabora com>
Date:   Mon Jun 4 11:46:43 2012 +0200

    tests: Test touch event delivery to actors

 tests/interactive/test-touch-events.c |   37 ++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/tests/interactive/test-touch-events.c b/tests/interactive/test-touch-events.c
index c5ea60e..142f0a1 100644
--- a/tests/interactive/test-touch-events.c
+++ b/tests/interactive/test-touch-events.c
@@ -22,7 +22,10 @@
 #include <glib.h>
 #include <clutter/clutter.h>
 
+#define STAGE_WIDTH 800
+#define STAGE_HEIGHT 550
 #define NUM_COLORS 10
+#define NUM_ACTORS 10
 
 static GSList *events = NULL;
 static const ClutterColor const static_colors[] = {
@@ -79,10 +82,27 @@ event_cb (ClutterActor *actor, ClutterEvent *event, ClutterActor *canvas)
   return TRUE;
 }
 
+static gboolean
+rect_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer data)
+{
+  gulong sequence;
+  ClutterColor color;
+
+  if (event->type != CLUTTER_TOUCH_BEGIN)
+    return FALSE;
+
+  sequence = (gulong) clutter_event_get_event_sequence (event);
+  color = static_colors[sequence % NUM_COLORS];
+  clutter_rectangle_set_color (CLUTTER_RECTANGLE (actor), &color);
+
+  return TRUE;
+}
+
 G_MODULE_EXPORT int
 test_touch_events_main (int argc, char *argv[])
 {
   ClutterActor *stage, *canvas;
+  int i;
 
   clutter_x11_enable_xinput ();
 
@@ -95,7 +115,7 @@ test_touch_events_main (int argc, char *argv[])
   g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
   clutter_stage_set_title (CLUTTER_STAGE (stage), "Touch events");
   clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
-  clutter_actor_set_size (stage, 1600, 800);
+  clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
   clutter_actor_set_reactive (stage, TRUE);
   clutter_actor_show (stage);
 
@@ -112,6 +132,21 @@ test_touch_events_main (int argc, char *argv[])
 
   g_signal_connect (stage, "event", G_CALLBACK (event_cb), canvas);
 
+  for (i = 0; i < NUM_ACTORS; i++)
+    {
+      gfloat size = STAGE_HEIGHT / NUM_ACTORS;
+      ClutterColor color = static_colors[i % NUM_COLORS];
+      ClutterActor *rectangle = clutter_rectangle_new_with_color (&color);
+
+      /* Test that event delivery to actors work */
+      g_signal_connect (rectangle, "event", G_CALLBACK (rect_event_cb), NULL);
+      
+      clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle);
+      clutter_actor_set_size (rectangle, size, size);
+      clutter_actor_set_position (rectangle, 0, i * size);
+      clutter_actor_set_reactive (rectangle, TRUE);
+    }
+
   clutter_main ();
 
   g_slist_free_full (events, (GDestroyNotify) clutter_event_free);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]