[gtk+/touchscreens: 66/69] gtk, scrolledwindow: Improve initial velocity calculation
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touchscreens: 66/69] gtk, scrolledwindow: Improve initial velocity calculation
- Date: Thu, 5 Jan 2012 11:45:23 +0000 (UTC)
commit 18e451da6eae0c2fc39161ed93724e5d98de433d
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Dec 23 17:10:56 2011 +0100
gtk,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 c128d0f..8378e2d 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2410,6 +2410,41 @@ gtk_scrolled_window_release_captured_events (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)
{
@@ -2453,6 +2488,8 @@ gtk_scrolled_window_captured_button_release (GtkWidget *widget,
}
priv->in_drag = FALSE;
+ gtk_scrolled_window_calculate_velocity (scrolled_window, _event);
+
/* Zero out vector components without a visible scrollbar */
if (!priv->hscrollbar_visible)
priv->x_velocity = 0;
@@ -2574,18 +2611,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 GTK_CAPTURED_EVENT_HANDLED;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]