[gtk+/multitouch-for-3.4: 47/89] gtk, scrolledwindow: Improve initial velocity calculation



commit fa949146bf2c454f28407cd7df593772d66fd744
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 36288a5..c7d5e00 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2434,6 +2434,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)
 {
@@ -2479,6 +2514,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;
@@ -2601,18 +2638,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]