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.
This commit is contained in:
Carlos Garnacho
2014-04-08 21:19:46 +02:00
parent bd722499dc
commit 2166be96d2
2 changed files with 37 additions and 5 deletions

View File

@@ -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;
if (gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_DENIED)
seq = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
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;
}

View File

@@ -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__ */