extern int UtcDaliAnimationPlayOffStage(void);
extern int UtcDaliAnimationPlayDiscardHandle(void);
extern int UtcDaliAnimationPlayStopDiscardHandle(void);
+extern int UtcDaliAnimationPlayFrom(void);
+extern int UtcDaliAnimationSetCurrentProgress(void);
extern int UtcDaliAnimationPause(void);
extern int UtcDaliAnimationStop(void);
extern int UtcDaliAnimationStopSetPosition(void);
{"UtcDaliAnimationPlayOffStage", UtcDaliAnimationPlayOffStage, utc_dali_animation_startup, utc_dali_animation_cleanup},
{"UtcDaliAnimationPlayDiscardHandle", UtcDaliAnimationPlayDiscardHandle, utc_dali_animation_startup, utc_dali_animation_cleanup},
{"UtcDaliAnimationPlayStopDiscardHandle", UtcDaliAnimationPlayStopDiscardHandle, utc_dali_animation_startup, utc_dali_animation_cleanup},
+ {"UtcDaliAnimationPlayFrom", UtcDaliAnimationPlayFrom, utc_dali_animation_startup, utc_dali_animation_cleanup},
+ {"UtcDaliAnimationSetCurrentProgress", UtcDaliAnimationSetCurrentProgress, utc_dali_animation_startup, utc_dali_animation_cleanup},
{"UtcDaliAnimationPause", UtcDaliAnimationPause, utc_dali_animation_startup, utc_dali_animation_cleanup},
{"UtcDaliAnimationStop", UtcDaliAnimationStop, utc_dali_animation_startup, utc_dali_animation_cleanup},
{"UtcDaliAnimationStopSetPosition", UtcDaliAnimationStopSetPosition, utc_dali_animation_startup, utc_dali_animation_cleanup},
END_TEST;
}
+int UtcDaliAnimationPlayFrom(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.MoveTo(actor, targetPosition, AlphaFunctions::Linear);
+
+ //PlayFrom with an argument outside the range [0..1] will be ignored
+ animation.PlayFrom(-1.0f);
+ application.SendNotification();
+ DALI_TEST_EQUALS(0.0f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ animation.PlayFrom(100.0f);
+ application.SendNotification();
+ DALI_TEST_EQUALS(0.0f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ // Start the animation from 40% progress
+ animation.PlayFrom( 0.4f );
+
+ bool signalReceived(false);
+ AnimationFinishCheck finishCheck(signalReceived);
+ animation.FinishedSignal().Connect(&application, finishCheck);
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 60% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.6f), TEST_LOCATION );
+
+ animation.Play(); // Test that calling play has no effect, when animation is already playing
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 80% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION );
+
+ application.Render(static_cast<unsigned int>(durationSeconds*200.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 );
+
+ // 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 );
+ END_TEST;
+}
+
+int UtcDaliAnimationSetCurrentProgress(void)
+{
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ Stage::GetCurrent().Add(actor);
+
+ // Build the animation
+ Animation animation = Animation::New(0.0f);
+ animation.Play();
+
+ //Test GetCurrentProgress return 0.0 as the duration is 0.0
+ DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ animation.SetCurrentProgress( 0.5f );
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(100.0f));
+
+ //Progress should still be 0.0
+ DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ //Set duration
+ float durationSeconds(1.0f);
+ animation.SetDuration(durationSeconds);
+ application.SendNotification();
+
+ bool signalReceived(false);
+ AnimationFinishCheck finishCheck(signalReceived);
+ animation.FinishedSignal().Connect(&application, finishCheck);
+ application.SendNotification();
+
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear);
+
+ //Trying to set the current cursor outside the range [0..1] is ignored
+ animation.SetCurrentProgress( -1.0f);
+ application.SendNotification();
+ DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ animation.SetCurrentProgress( 100.0f);
+ application.SendNotification();
+ DALI_TEST_EQUALS( 0.0f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ // Start the animation from 40% progress
+ animation.SetCurrentProgress( 0.4f );
+ animation.Play();
+
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 60% progress */);
+
+ // We didn't expect the animation to finish yet
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.6f), TEST_LOCATION );
+ DALI_TEST_EQUALS( 0.6f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ animation.Play(); // Test that calling play has no effect, when animation is already playing
+ application.SendNotification();
+
+ //Set the progress to 70%
+ animation.SetCurrentProgress( 0.7f );
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*100.0f)/* 80% progress */);
+ DALI_TEST_EQUALS( 0.8f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), (targetPosition * 0.8f), TEST_LOCATION );
+ DALI_TEST_EQUALS( 0.8f, animation.GetCurrentProgress(), TEST_LOCATION );
+
+ //
+
+ application.Render(static_cast<unsigned int>(durationSeconds*200.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 );
+
+ // 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 );
+ END_TEST;
+}
+
+
int UtcDaliAnimationPause(void)
{
TestApplication application;
return mDurationSeconds;
}
+ /*
+ * Retrieve the current progress of the animation.
+ * @return The current progress as a normalized value between [0,1].
+ */
+ float GetCurrentProgress() const
+ {
+ if( mDurationSeconds > 0.0f )
+ {
+ return mElapsedSeconds / mDurationSeconds;
+ }
+
+ return 0.0f;
+ }
+
+ /*
+ * Sets the progress of the animation.
+ * @param[in] The new progress as a normalized value between [0,1]
+ */
+ void SetCurrentProgress( float progress )
+ {
+ mElapsedSeconds = mDurationSeconds * progress;
+ }
+
/**
* Set whether the animation will loop.
* @param[in] looping True if the animation will loop.
*/
void Play();
+ /*
+ * Play the animation from a given point
+ * @param[in] progress A value between [0,1] form where the animation should start playing
+ */
+ void PlayFrom( float progress );
+
/**
* Pause the animation.
*/
new (slot) LocalType( &animation, &Animation::SetDestroyAction, action );
}
+inline void SetCurrentProgressMessage( EventToUpdate& eventToUpdate, const Animation& animation, float progress )
+{
+ typedef MessageValue1< Animation, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &animation, &Animation::SetCurrentProgress, progress );
+}
+
inline void PlayAnimationMessage( EventToUpdate& eventToUpdate, const Animation& animation )
{
typedef Message< Animation > LocalType;
new (slot) LocalType( &animation, &Animation::Play );
}
+inline void PlayAnimationFromMessage( EventToUpdate& eventToUpdate, const Animation& animation, float progress )
+{
+ typedef MessageValue1< Animation,float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &animation, &Animation::PlayFrom, progress );
+}
+
inline void PauseAnimationMessage( EventToUpdate& eventToUpdate, const Animation& animation )
{
typedef Message< Animation > LocalType;