[gtk+/wip/frame-synchronization: 16/33] GtkTimeline: Wrap around the progress correctly when looping



commit 025a93d2914e6c61785cc2c05176bafc1d5edd0f
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Fri Sep 28 12:38:14 2012 -0400

    GtkTimeline: Wrap around the progress correctly when looping
    
    When we have a looping animation for something like an angle,
    we need to make sure that the distance we go past 1.0 becomes
    the starting distance for the next frame. This prevents a
    stutter at the loop position.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685460

 gtk/gtktimeline.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktimeline.c b/gtk/gtktimeline.c
index a25c980..b0fe635 100644
--- a/gtk/gtktimeline.c
+++ b/gtk/gtktimeline.c
@@ -357,7 +357,7 @@ gtk_timeline_on_update (GdkPaintClock *clock,
                         GtkTimeline   *timeline)
 {
   GtkTimelinePriv *priv;
-  gdouble delta_progress, progress;
+  gdouble delta_progress, progress, adjust;
   guint64 now;
 
   /* the user may unref us during the signals, so save ourselves */
@@ -381,6 +381,21 @@ gtk_timeline_on_update (GdkPaintClock *clock,
 
       priv->last_progress = progress;
 
+      /* When looping, if we go past the end, start that much into the
+       * next cycle */
+      if (progress < 0.0)
+        {
+          adjust = progress - ceil(progress);
+          progress = 0.0;
+        }
+      else if (progress > 1.0)
+        {
+          adjust = progress - floor(progress);
+          progress = 1.0;
+        }
+      else
+        adjust = 0.0;
+
       progress = CLAMP (progress, 0., 1.);
     }
   else
@@ -398,7 +413,10 @@ gtk_timeline_on_update (GdkPaintClock *clock,
       loop = priv->loop && priv->animations_enabled;
 
       if (loop)
-        gtk_timeline_rewind (timeline);
+        {
+          gtk_timeline_rewind (timeline);
+          priv->progress += adjust;
+        }
       else
         {
           gtk_timeline_stop_running (timeline);



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