Added Animation GetState() 27/58527/9
authorLee Morgan <Lee.morgan@partner.samsung.com>
Mon, 1 Feb 2016 15:51:33 +0000 (15:51 +0000)
committerLee Morgan <Lee.morgan@partner.samsung.com>
Fri, 5 Feb 2016 16:21:31 +0000 (16:21 +0000)
Change-Id: I3c8103c4752f65840ed16f8b3406279049a57912

automated-tests/src/dali/utc-Dali-Animation.cpp
dali/internal/event/animation/animation-impl.cpp
dali/internal/event/animation/animation-impl.h
dali/public-api/animation/animation.cpp
dali/public-api/animation/animation.h

index fec88e8..5a288f4 100644 (file)
@@ -2015,7 +2015,101 @@ int UtcDaliAnimationPauseP(void)
   END_TEST;
 }
 
-int UtcDaliAnimationStoP(void)
+
+int UtcDaliAnimationGetStateP(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  Stage::GetCurrent().Add(actor);
+
+  // Build the animation
+  float durationSeconds(1.0f);
+  Animation animation = Animation::New(durationSeconds);
+  Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+  animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
+  DALI_TEST_EQUALS( animation.GetState(), Animation::STOPPED, TEST_LOCATION );
+
+  Vector3 fiftyPercentProgress(targetPosition * 0.5f);
+
+  // Start the animation
+  animation.Play();
+
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+
+  bool signalReceived(false);
+  AnimationFinishCheck finishCheck(signalReceived);
+  animation.FinishedSignal().Connect(&application, finishCheck);
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* 50% progress */);
+
+  // We didn't expect the animation to finish yet
+  application.SendNotification();
+  finishCheck.CheckSignalNotReceived();
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+  DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress, TEST_LOCATION );
+
+  // Pause the animation
+  animation.Pause();
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PAUSED, TEST_LOCATION );
+  application.SendNotification();
+  application.Render(0.f);
+
+  // Loop 5 times
+  for (int i=0; i<5; ++i)
+  {
+    application.Render(static_cast<unsigned int>(durationSeconds*500.0f));
+
+    // We didn't expect the animation to finish yet
+    application.SendNotification();
+    finishCheck.CheckSignalNotReceived();
+    DALI_TEST_EQUALS( actor.GetCurrentPosition(), fiftyPercentProgress/* Still 50% progress when paused */, TEST_LOCATION );
+    DALI_TEST_EQUALS( animation.GetState(), Animation::PAUSED, TEST_LOCATION );
+  }
+
+  // Keep going
+  finishCheck.Reset();
+  animation.Play();
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds*490.0f)/*slightly less than the animation duration*/);
+  // We didn't expect the animation to finish yet
+  application.SendNotification();
+  finishCheck.CheckSignalNotReceived();
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds*10.0f) + 1u/*just beyond the animation duration*/);
+
+  // We did expect the animation to finish
+  application.SendNotification();
+  finishCheck.CheckSignalReceived();
+  DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( animation.GetState(), Animation::STOPPED, TEST_LOCATION );
+
+  // Check that nothing has changed after a couple of buffer swaps
+  application.Render(0);
+  DALI_TEST_EQUALS( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION );
+  application.Render(0);
+  DALI_TEST_EQUALS( targetPosition, actor.GetCurrentPosition(), TEST_LOCATION );
+  DALI_TEST_EQUALS( animation.GetState(), Animation::STOPPED, TEST_LOCATION );
+
+  // re-play
+  finishCheck.Reset();
+  animation.Play();
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>(durationSeconds*490.0f)/*slightly less than the animation duration*/);
+  application.SendNotification();
+  finishCheck.CheckSignalNotReceived();
+  DALI_TEST_EQUALS( animation.GetState(), Animation::PLAYING, TEST_LOCATION );
+
+
+  END_TEST;
+}
+
+int UtcDaliAnimationStopP(void)
 {
   TestApplication application;
 
index 04ca30b..ec49265 100644 (file)
@@ -127,7 +127,8 @@ Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylis
   mPlayRange( Vector2(0.0f,1.0f)),
   mEndAction( endAction ),
   mDisconnectAction( disconnectAction ),
-  mDefaultAlpha( defaultAlpha )
+  mDefaultAlpha( defaultAlpha ),
+  mState(Dali::Animation::STOPPED)
 {
 }
 
@@ -264,6 +265,8 @@ void Animation::Play()
   // Update the current playlist
   mPlaylist.OnPlay( *this );
 
+  mState = Dali::Animation::PLAYING;
+
   // mAnimation is being used in a separate thread; queue a Play message
   PlayAnimationMessage( mEventThreadServices, *mAnimation );
 }
@@ -275,6 +278,8 @@ void Animation::PlayFrom( float progress )
     // Update the current playlist
     mPlaylist.OnPlay( *this );
 
+    mState = Dali::Animation::PLAYING;
+
     // mAnimation is being used in a separate thread; queue a Play message
     PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
   }
@@ -282,12 +287,21 @@ void Animation::PlayFrom( float progress )
 
 void Animation::Pause()
 {
+  mState = Dali::Animation::PAUSED;
+
   // mAnimation is being used in a separate thread; queue a Pause message
   PauseAnimationMessage( mEventThreadServices, *mAnimation );
 }
 
+Dali::Animation::State Animation::GetState() const
+{
+  return mState;
+}
+
 void Animation::Stop()
 {
+  mState = Dali::Animation::STOPPED;
+
   // mAnimation is being used in a separate thread; queue a Stop message
   StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
 }
@@ -747,6 +761,8 @@ bool Animation::HasFinished()
     mNotificationCount = playedCount;
 
     hasFinished = true;
+
+    mState = Dali::Animation::STOPPED;
   }
 
   return hasFinished;
index f3ade18..8eb5257 100644 (file)
@@ -159,6 +159,11 @@ public:
   void Pause();
 
   /**
+   * @copydoc Dali::Animation::GetState()
+   */
+  Dali::Animation::State GetState() const;
+
+  /**
    * @copydoc Dali::Animation::Stop()
    */
   void Stop();
@@ -467,6 +472,7 @@ private:
   EndAction mEndAction;
   EndAction mDisconnectAction;
   AlphaFunction mDefaultAlpha;
+  Dali::Animation::State mState;
 
 };
 
index 686d81b..4663f95 100644 (file)
@@ -145,6 +145,11 @@ void Animation::Pause()
   GetImplementation(*this).Pause();
 }
 
+Dali::Animation::State Animation::GetState() const
+{
+  return GetImplementation(*this).GetState();
+}
+
 void Animation::Stop()
 {
   GetImplementation(*this).Stop();
index d562c63..ad2f816 100644 (file)
@@ -140,6 +140,20 @@ public:
   };
 
   /**
+   * @brief What state the animation is in
+   *
+   * Note: Calling Reset() on this class will NOT reset the animation. It will call BaseHandle::Reset() which drops the object handle.
+   *
+   * @SINCE_1_1.21
+   */
+  enum State
+  {
+    STOPPED,   ///< Animation has stopped @SINCE_1_1.21
+    PLAYING,   ///< The animation is playing @SINCE_1_1.21
+    PAUSED     ///< The animation is paused @SINCE_1_1.21
+  };
+
+  /**
    * @brief Create an uninitialized Animation; this can be initialized with Animation::New().
    *
    * Calling member functions with an uninitialized Dali::Object is not allowed.
@@ -403,6 +417,13 @@ public:
   void Pause();
 
   /**
+   * @brief Query the state of the animation.
+   * @SINCE_1_1.21
+   * @return The Animation::State
+   */
+  State GetState() const;
+
+  /**
    * @brief Stop the animation.
    * @SINCE_1_0.0
    */