[gtk+/gestures: 86/202] swipe: Add function to retrieve the current velocity



commit 2166be96d2cc6dd133a13566ee85fa35fc04a4b2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Apr 8 21:19:46 2014 +0200

    swipe: Add function to retrieve the current velocity
    
    This can be used to fetch the current velocity on update(), as opposed
    to swipe() which happens after the sequence is finished.

 gtk/gtkgestureswipe.c |   37 ++++++++++++++++++++++++++++++++-----
 gtk/gtkgestureswipe.h |    5 +++++
 2 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkgestureswipe.c b/gtk/gtkgestureswipe.c
index d04504a..e4f6e29 100644
--- a/gtk/gtkgestureswipe.c
+++ b/gtk/gtkgestureswipe.c
@@ -109,13 +109,18 @@ _gtk_gesture_swipe_calculate_velocity (GtkGestureSwipe *gesture,
                                        gdouble         *velocity_y)
 {
   GtkGestureSwipePrivate *priv;
+  GdkEventSequence *sequence;
+  guint32 evtime, diff_time;
   EventData *start, *end;
   gdouble diff_x, diff_y;
-  guint32 diff_time;
 
   priv = gtk_gesture_swipe_get_instance_private (gesture);
   *velocity_x = *velocity_y = 0;
 
+  sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
+  gtk_gesture_get_last_update_time (GTK_GESTURE (gesture), sequence, &evtime);
+  _gtk_gesture_swipe_clear_backlog (gesture, evtime);
+
   if (priv->events->len == 0)
     return;
 
@@ -141,14 +146,14 @@ gtk_gesture_swipe_end (GtkGesture       *gesture,
   GtkGestureSwipe *swipe = GTK_GESTURE_SWIPE (gesture);
   GtkGestureSwipePrivate *priv;
   gdouble velocity_x, velocity_y;
-  guint32 evtime;
+  GdkEventSequence *seq;
+
+  seq = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
 
-  if (gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_DENIED)
+  if (gtk_gesture_get_sequence_state (gesture, seq) == GTK_EVENT_SEQUENCE_DENIED)
     return;
 
   priv = gtk_gesture_swipe_get_instance_private (swipe);
-  gtk_gesture_get_last_update_time (gesture, sequence, &evtime);
-  _gtk_gesture_swipe_clear_backlog (swipe, evtime);
   _gtk_gesture_swipe_calculate_velocity (swipe, &velocity_x, &velocity_y);
   g_signal_emit (gesture, signals[SWIPE], 0, velocity_x, velocity_y);
 
@@ -202,3 +207,25 @@ gtk_gesture_swipe_new (GtkWidget *widget)
                        "widget", widget,
                        NULL);
 }
+
+gboolean
+gtk_gesture_swipe_get_velocity (GtkGestureSwipe *gesture,
+                                gdouble         *velocity_x,
+                                gdouble         *velocity_y)
+{
+  gdouble vel_x, vel_y;
+
+  g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
+
+  if (!gtk_gesture_is_recognized (GTK_GESTURE (gesture)))
+    return FALSE;
+
+  _gtk_gesture_swipe_calculate_velocity (gesture, &vel_x, &vel_y);
+
+  if (velocity_x)
+    *velocity_x = vel_x;
+  if (velocity_y)
+    *velocity_y = vel_y;
+
+  return TRUE;
+}
diff --git a/gtk/gtkgestureswipe.h b/gtk/gtkgestureswipe.h
index b8564b0..fec6132 100644
--- a/gtk/gtkgestureswipe.h
+++ b/gtk/gtkgestureswipe.h
@@ -62,6 +62,11 @@ GType        gtk_gesture_swipe_get_type  (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_3_14
 GtkGesture * gtk_gesture_swipe_new       (GtkWidget *widget);
 
+GDK_AVAILABLE_IN_3_14
+gboolean     gtk_gesture_swipe_get_velocity (GtkGestureSwipe *gesture,
+                                             gdouble         *velocity_x,
+                                             gdouble         *velocity_y);
+
 G_END_DECLS
 
 #endif /* __GTK_GESTURE_SWIPE_H__ */


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