[libchamplain] Base viewport update on time as well



commit 56f2ba7b2858d14cf76437ad77b25021dcc04006
Author: JiÅ?í Techet <techet gmail com>
Date:   Mon Mar 15 02:06:28 2010 +0100

    Base viewport update on time as well
    
    Viewport is currently updated only based on the amount of scrolled pixels
    (100). However, when the viewport is slowing down in the kinetic mode,
    this can result in a blank space appearing in the top of the window for
    quite a long time because the movement is slow and doesn't reach the 100
    pixel margin needed for update. This patch adds one more criterion - time,
    which makes to perform the updates at least 4 times a second, no matter
    how many pixels were scrolled.
    
    Signed-off-by: JiÅ?í Techet <techet gmail com>

 champlain/champlain-view.c |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index d038405..5946acf 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -176,6 +176,7 @@ struct _ChamplainViewPrivate
   /* Lines and shapes */
   ClutterActor *polygon_layer;  /* Contains the polygons */
 
+  GTimeVal last_update_time;
 };
 
 G_DEFINE_TYPE (ChamplainView, champlain_view, CLUTTER_TYPE_GROUP);
@@ -1377,6 +1378,10 @@ champlain_view_init (ChamplainView *view)
   priv->scale_unit = CHAMPLAIN_UNIT_KM;
   priv->max_scale_width = 100;
 
+  /* make sure the last update time is in the past */
+  g_get_current_time (&priv->last_update_time);
+  g_time_val_add (&priv->last_update_time, -1000 * 1000);
+
   /* Setup map layer */
   priv->map_layer = g_object_ref (clutter_group_new ());
   clutter_actor_show (priv->map_layer);
@@ -1459,15 +1464,32 @@ viewport_pos_changed_cb (GObject *gobject,
   ChamplainViewPrivate *priv = GET_PRIVATE (view);
 
   gfloat x, y;
+  GTimeVal now, next_update_time;
+  gboolean skip_update;
 
   tidy_viewport_get_origin (TIDY_VIEWPORT (priv->viewport), &x, &y,
       NULL);
 
-  if (fabs (x - priv->viewport_size.x) < 100 &&
-      fabs (y - priv->viewport_size.y) < 100)
-      return;
+  skip_update = fabs (x - priv->viewport_size.x) < 100 &&
+                fabs (y - priv->viewport_size.y) < 100;
 
-  update_viewport (view, x, y);
+  if (skip_update)
+    {
+      g_get_current_time (&now);
+      next_update_time = priv->last_update_time;
+      g_time_val_add (&next_update_time, 250 * 1000); // Refresh at least 4-times a second
+
+      skip_update =  next_update_time.tv_sec > now.tv_sec ||
+                     (next_update_time.tv_sec == now.tv_sec &&
+                      next_update_time.tv_usec > now.tv_usec);
+    }
+
+  if (!skip_update)
+    {
+      g_get_current_time (&priv->last_update_time);
+
+      update_viewport (view, x, y);
+    }
 }
 
 /**



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