[libdazzle] animation: handle 0 length animations gracefully



commit a17c5e23bab82b99cff78747d0d4227b98affe42
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jul 18 23:34:46 2018 -0700

    animation: handle 0 length animations gracefully
    
    If end_time == begin_time, then we'd continually return 0.0 as our offset
    which means we never advance and spin the animation loop.
    
    Fixes #14 and #20

 src/animation/dzl-animation.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/src/animation/dzl-animation.c b/src/animation/dzl-animation.c
index 745aafd..9e0347e 100644
--- a/src/animation/dzl-animation.c
+++ b/src/animation/dzl-animation.c
@@ -326,10 +326,11 @@ dzl_animation_get_offset (DzlAnimation *animation,
 
   frame_time = CLAMP (frame_time, animation->begin_time, animation->end_time);
 
-  if (frame_time == animation->begin_time)
-    return 0.0;
-  else if (frame_time == animation->end_time)
+  /* Check end_time first in case end_time == begin_time */
+  if (frame_time == animation->end_time)
     return 1.0;
+  else if (frame_time == animation->begin_time)
+    return 0.0;
 
   return (frame_time - animation->begin_time) / (gdouble)(animation->duration_msec * 1000L);
 }


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