Add BakeFinal to Animation::EndAction
authorJavon Prince <javon.prince@samsung.com>
Tue, 29 Apr 2014 18:16:09 +0000 (19:16 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Sat, 3 May 2014 09:45:50 +0000 (10:45 +0100)
When an animation is stopped, it will save the property
values as if it's duration had normally elapsed.

Signed-off-by: Javon Prince <javon.prince@samsung.com>
automated-tests/src/dali/utc-Dali-Animation.cpp
capi/dali/public-api/animation/animation.h
dali/internal/update/animation/scene-graph-animation.cpp

index ec260cf..1b1add4 100644 (file)
@@ -447,7 +447,30 @@ int UtcDaliAnimationSetEndAction(void)
   application.Render(0);
   DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentPosition(), TEST_LOCATION );
 
-  // Animate again, but don't bake this time
+  // Test BakeFinal, animate again, for half the duration
+  finishCheck.Reset();
+  animation.SetEndAction(Animation::BakeFinal);
+  DALI_TEST_CHECK(animation.GetEndAction() == Animation::BakeFinal);
+  animation.Play();
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds*1000.0f*0.5f) /*half of the animation duration*/);
+
+  // Stop the animation early
+  animation.Stop();
+
+  // We did NOT expect the animation to finish
+  application.SendNotification();
+  finishCheck.CheckSignalNotReceived();
+  DALI_TEST_EQUALS( targetPosition * 0.5f, actor.GetCurrentPosition(), VECTOR4_EPSILON, TEST_LOCATION );
+
+  // Go back to the start
+  actor.SetPosition(Vector3::ZERO);
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentPosition(), TEST_LOCATION );
+
+  // Test EndAction::Discard, animate again, but don't bake this time
   finishCheck.Reset();
   animation.SetEndAction(Animation::Discard);
   DALI_TEST_CHECK(animation.GetEndAction() == Animation::Discard);
@@ -482,6 +505,10 @@ int UtcDaliAnimationGetEndAction(void)
 
   animation.SetEndAction(Animation::Discard);
   DALI_TEST_CHECK(animation.GetEndAction() == Animation::Discard);
+
+  animation.SetEndAction(Animation::BakeFinal);
+  DALI_TEST_CHECK(animation.GetEndAction() == Animation::BakeFinal);
+
   END_TEST;
 }
 
@@ -494,6 +521,9 @@ int UtcDaliAnimationGetDestroyAction(void)
   animation.SetDestroyAction(Animation::Discard);
   DALI_TEST_CHECK(animation.GetDestroyAction() == Animation::Discard);
 
+  animation.SetDestroyAction(Animation::BakeFinal);
+  DALI_TEST_CHECK(animation.GetDestroyAction() == Animation::BakeFinal);
+
   END_TEST;
 }
 
index 2549d58..76f7be7 100644 (file)
@@ -122,12 +122,13 @@ public:
   typedef boost::function<Quaternion (float alpha, const Quaternion& current)> QuaternionAnimatorFunc; ///< Interpolation function
 
   /**
-   * @brief What to do when the animation ends.
+   * @brief What to do when the animation ends, is stopped or is destroyed
    */
   enum EndAction
   {
-    Bake,   ///< When the animation ends, the animated property values are saved.
-    Discard ///< When the animation ends, the animated property values are forgotten.
+    Bake,     ///< When the animation ends, the animated property values are saved.
+    Discard,  ///< When the animation ends, the animated property values are forgotten.
+    BakeFinal ///< If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
   };
 
   //Signal Names
index 29093b9..69e457f 100644 (file)
@@ -97,8 +97,12 @@ bool Animation::Stop(BufferIndex bufferIndex)
   {
     animationFinished = true; // The actor-thread should be notified of this
 
-    if (mEndAction == Dali::Animation::Bake)
+    if( mEndAction != Dali::Animation::Discard )
     {
+      if( mEndAction == Dali::Animation::BakeFinal )
+      {
+        mElapsedSeconds = mDurationSeconds + Math::MACHINE_EPSILON_1; // Force animation to reach it's end
+      }
       UpdateAnimators(bufferIndex, true/*bake the final result*/);
     }
 
@@ -116,7 +120,7 @@ void Animation::OnDestroy(BufferIndex bufferIndex)
 {
   if (mState == Playing || mState == Paused)
   {
-    if (mDestroyAction == Dali::Animation::Bake)
+    if (mDestroyAction != Dali::Animation::Discard)
     {
       UpdateAnimators(bufferIndex, true/*bake the final result*/);
     }
@@ -156,7 +160,7 @@ bool Animation::Update(BufferIndex bufferIndex, float elapsedSeconds)
 
   const bool animationFinished(mState == Playing && mElapsedSeconds > mDurationSeconds);
 
-  UpdateAnimators(bufferIndex, animationFinished && (mEndAction == Dali::Animation::Bake));
+  UpdateAnimators(bufferIndex, animationFinished && (mEndAction != Dali::Animation::Discard));
 
   if (animationFinished)
   {