From: Owen W. Taylor Date: Fri, 28 Sep 2012 16:38:14 +0000 (-0400) Subject: GtkTimeline: Wrap around the progress correctly when looping X-Git-Url: http://pileus.org/git/?a=commitdiff_plain;h=672100b82263d47e5b4a91143202bb67fcc2407f;p=~andy%2Fgtk 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 --- diff --git a/gtk/gtktimeline.c b/gtk/gtktimeline.c index 55df628be..ad2e7dfcd 100644 --- a/gtk/gtktimeline.c +++ b/gtk/gtktimeline.c @@ -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);