[gtk+/multitouch: 113/124] gtk, gestures: Add gtk_gestures_interpreter_get_n_active_strokes



commit fe3f36f6d40196cb924ff263e22003284b17c172
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 12 02:47:23 2012 +0100

    gtk,gestures: Add gtk_gestures_interpreter_get_n_active_strokes
    
    This call gets the number of currently active strokes, finished
    strokes (i.e. those that already had a GDK_BUTTON/TOUCH_RELEASE
    processed) don't count.

 docs/reference/gtk/gtk3-sections.txt |    1 +
 gtk/gtkgesturesinterpreter.c         |   41 ++++++++++++++++++++++++++++++++++
 gtk/gtkgesturesinterpreter.h         |    2 +
 3 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 9f89b9f..abc285d 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -1588,6 +1588,7 @@ gtk_gestures_interpreter_add_gesture
 gtk_gestures_interpreter_remove_gesture
 gtk_gestures_interpreter_feed_event
 gtk_gestures_interpreter_finish
+gtk_gestures_interpreter_get_n_active_strokes
 
 <SUBSECTION Gestures>
 GtkGestureStroke
diff --git a/gtk/gtkgesturesinterpreter.c b/gtk/gtkgesturesinterpreter.c
index 40c7b0d..3d0f285 100644
--- a/gtk/gtkgesturesinterpreter.c
+++ b/gtk/gtkgesturesinterpreter.c
@@ -97,6 +97,8 @@ struct _RecordedGesture
   gint max_x;
   gint min_y;
   gint max_y;
+
+  guint finished : 1;
 };
 
 enum {
@@ -907,6 +909,41 @@ gtk_gestures_interpreter_remove_gesture (GtkGesturesInterpreter *interpreter,
 }
 
 /**
+ * gtk_gestures_interpreter_get_n_active_strokes:
+ * @interpreter: a #GtkGesturesInterpreter
+ *
+ * Returns the number of devices/touch sequences currently interacting
+ * with @interpreter.
+ *
+ * Returns: the number of strokes being performed in the interpreter.
+ *
+ * Since: 3.4
+ **/
+guint
+gtk_gestures_interpreter_get_n_active_strokes (GtkGesturesInterpreter *interpreter)
+{
+  GtkGesturesInterpreterPrivate *priv;
+  GHashTableIter iter;
+  guint n_touches = 0;
+  gpointer data;
+
+  g_return_val_if_fail (GTK_IS_GESTURES_INTERPRETER (interpreter), 0);
+
+  priv = interpreter->priv;
+  g_hash_table_iter_init (&iter, priv->events);
+
+  while (g_hash_table_iter_next (&iter, NULL, &data))
+    {
+      RecordedGesture *recorded = data;
+
+      if (!recorded->finished)
+        n_touches++;
+    }
+
+  return n_touches;
+}
+
+/**
  * gtk_gestures_interpreter_feed_event:
  * @interpreter: a #GtkGesturesInterpreter
  * @event: a #GdkEvent containing coordinates
@@ -955,6 +992,10 @@ gtk_gestures_interpreter_feed_event (GtkGesturesInterpreter *interpreter,
 
   recorded_gesture_append_coordinate (recorded, x, y);
 
+  if (event->type == GDK_BUTTON_RELEASE ||
+      event->type == GDK_TOUCH_RELEASE)
+    recorded->finished = TRUE;
+
   return TRUE;
 }
 
diff --git a/gtk/gtkgesturesinterpreter.h b/gtk/gtkgesturesinterpreter.h
index 72a53c4..76c0f65 100644
--- a/gtk/gtkgesturesinterpreter.h
+++ b/gtk/gtkgesturesinterpreter.h
@@ -109,6 +109,8 @@ gboolean gtk_gestures_interpreter_add_gesture    (GtkGesturesInterpreter *interp
 void     gtk_gestures_interpreter_remove_gesture (GtkGesturesInterpreter *interpreter,
                                                   guint                   gesture_id);
 
+guint    gtk_gestures_interpreter_get_n_active_strokes (GtkGesturesInterpreter *interpreter);
+
 gboolean gtk_gestures_interpreter_feed_event (GtkGesturesInterpreter *interpreter,
 					      GdkEvent               *event);
 gboolean gtk_gestures_interpreter_finish     (GtkGesturesInterpreter *interpreter,



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