[gtk+/touch-for-3.4: 20/65] scrolledwindow: Improve initial velocity calculation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touch-for-3.4: 20/65] scrolledwindow: Improve initial velocity calculation
- Date: Fri, 24 Feb 2012 15:26:31 +0000 (UTC)
commit bc5eacb1850c360e97e71d390a7ac59de616d5c2
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Dec 23 17:10:56 2011 +0100
scrolledwindow: Improve initial velocity calculation
Velocity calculation has been refactored out of the captured motion
events handler, and also has more tolerance defore determining that
a drag is actually still.
gtk/gtkscrolledwindow.c | 50 +++++++++++++++++++++++++++++++++++-----------
1 files changed, 38 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 27a22ca..baa652c 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2450,6 +2450,41 @@ gtk_scrolled_window_release_captured_event (GtkScrolledWindow *scrolled_window)
}
static gboolean
+gtk_scrolled_window_calculate_velocity (GtkScrolledWindow *scrolled_window,
+ GdkEvent *event)
+{
+ GtkScrolledWindowPrivate *priv;
+ gdouble x_root, y_root;
+ guint32 _time;
+
+#define STILL_THRESHOLD 40
+
+ if (!gdk_event_get_root_coords (event, &x_root, &y_root))
+ return FALSE;
+
+ priv = scrolled_window->priv;
+ _time = gdk_event_get_time (event);
+
+ if (priv->last_motion_event_x_root != x_root ||
+ priv->last_motion_event_y_root != y_root ||
+ ABS (_time - priv->last_motion_event_time) > STILL_THRESHOLD)
+ {
+ priv->x_velocity = (priv->last_motion_event_x_root - x_root) /
+ (gdouble) (_time - priv->last_motion_event_time);
+ priv->y_velocity = (priv->last_motion_event_y_root - y_root) /
+ (gdouble) (_time - priv->last_motion_event_time);
+ }
+
+ priv->last_motion_event_x_root = x_root;
+ priv->last_motion_event_y_root = y_root;
+ priv->last_motion_event_time = _time;
+
+#undef STILL_THRESHOLD
+
+ return TRUE;
+}
+
+static gboolean
gtk_scrolled_window_captured_button_release (GtkWidget *widget,
GdkEvent *_event)
{
@@ -2495,6 +2530,8 @@ gtk_scrolled_window_captured_button_release (GtkWidget *widget,
priv->button_press_event = NULL;
}
+ gtk_scrolled_window_calculate_velocity (scrolled_window, _event);
+
/* Zero out vector components without a visible scrollbar */
if (!priv->hscrollbar_visible)
priv->x_velocity = 0;
@@ -2618,18 +2655,7 @@ gtk_scrolled_window_captured_motion_notify (GtkWidget *widget,
_gtk_scrolled_window_allocate_overshoot_window (scrolled_window);
}
- /* Find out X/Y components of the velocity vector, in pixels/ms */
- if (event->time != priv->last_motion_event_time)
- {
- priv->x_velocity = (priv->last_motion_event_x_root - event->x_root) /
- (gdouble) (event->time - priv->last_motion_event_time);
- priv->y_velocity = (priv->last_motion_event_y_root - event->y_root) /
- (gdouble) (event->time - priv->last_motion_event_time);
-
- priv->last_motion_event_x_root = event->x_root;
- priv->last_motion_event_y_root = event->y_root;
- priv->last_motion_event_time = event->time;
- }
+ gtk_scrolled_window_calculate_velocity (scrolled_window, _event);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]