]> Pileus Git - ~andy/gtk/commitdiff
GtkTimeline: Wrap around the progress correctly when looping
authorOwen W. Taylor <otaylor@fishsoup.net>
Fri, 28 Sep 2012 16:38:14 +0000 (12:38 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Thu, 14 Feb 2013 22:19:49 +0000 (17:19 -0500)
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

index 55df628be0c5f87e9f384bdd21533cafc3eebf3a..ad2e7dfcd4c8bf28357a17052c52fe0054c6ca6b 100644 (file)
@@ -357,7 +357,7 @@ gtk_timeline_on_update (GdkFrameClock *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 (GdkFrameClock *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 (GdkFrameClock *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);