END_TEST;
}
+int UtcDaliAnimationSetLoopingModeP(void)
+{
+ // Test Loop forever and Loop mode being set
+ TestApplication application;
+ Stage stage( Stage::GetCurrent() );
+
+ // Default: LoopingMode::RESTART
+ {
+ Actor actor = Actor::New();
+ stage.Add( actor );
+
+ float durationSeconds( 1.0f );
+ Animation animation = Animation::New( durationSeconds );
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::RESTART );
+
+ Vector3 targetPosition(10.0f, 10.0f, 10.0f);
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition );
+
+ // Start the animation
+ animation.Play();
+ application.SendNotification();
+ application.Render(static_cast<unsigned int>(durationSeconds*0.5f*1000.0f)/*Only half the animation*/);
+
+ actor.Unparent();
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+ }
+
+ // LoopingMode::AUTO_REVERSE
+ {
+ Actor actor = Actor::New();
+ stage.Add( actor );
+
+ float durationSeconds( 1.0f );
+ Animation animation = Animation::New( durationSeconds );
+ animation.SetLooping( true );
+
+ bool signalReceived( false );
+ AnimationFinishCheck finishCheck( signalReceived );
+ animation.FinishedSignal().Connect( &application, finishCheck );
+ application.SendNotification();
+
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition );
+
+ DevelAnimation::SetLoopingMode( animation, DevelAnimation::LoopingMode::AUTO_REVERSE );
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::AUTO_REVERSE );
+
+ // Start the animation
+ animation.Play();
+ application.SendNotification();
+ application.Render(0);
+
+ for( int iterations = 0; iterations < 3; ++iterations )
+ {
+ application.Render( static_cast< unsigned int >( durationSeconds * 500.0f )/* 50% time progress */ );
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+
+ // AUTO_REVERSE mode means, for Animation duration time, the actor starts from the beginning, passes the targetPosition,
+ // and arrives at the beginning.
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render( static_cast< unsigned int >( durationSeconds * 500.0f )/* 100% time progress */ );
+
+ // We did expect the animation to finish
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3( 0.0f, 0.0f, 0.0f ), TEST_LOCATION );
+ }
+
+ animation.SetLooping( false );
+ application.SendNotification();
+ application.Render(static_cast< unsigned int >( durationSeconds * 1000.0f ) + 1u /*just beyond the animation duration*/);
+
+ application.SendNotification();
+ finishCheck.CheckSignalReceived();
+
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3( 0.0f, 0.0f, 0.0f ), TEST_LOCATION );
+ }
+
+ // LoopingMode::AUTO_REVERSE in Reverse mode, which begin from the end
+ {
+ Actor actor = Actor::New();
+ stage.Add( actor );
+
+ float durationSeconds( 1.0f );
+ Animation animation = Animation::New( durationSeconds );
+ animation.SetLooping( true );
+
+ bool signalReceived( false );
+ AnimationFinishCheck finishCheck( signalReceived );
+ animation.FinishedSignal().Connect( &application, finishCheck );
+ application.SendNotification();
+
+ // Specify a negative multiplier to play the animation in reverse
+ animation.SetSpeedFactor( -1.0f );
+
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition );
+
+ DevelAnimation::SetLoopingMode( animation, DevelAnimation::LoopingMode::AUTO_REVERSE );
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::AUTO_REVERSE );
+
+ // Start the animation
+ animation.Play();
+ application.SendNotification();
+ application.Render(0);
+
+ for( int iterations = 0; iterations < 3; ++iterations )
+ {
+ application.Render( static_cast< unsigned int >( durationSeconds * 500.0f )/* 50% time progress */ );
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+
+ // Setting a negative speed factor is to play the animation in reverse.
+ // So, when LoopingMode::AUTO_REVERSE and SetSpeedFactor( -1.0f ) is, for Animation duration time,
+ // the actor starts from the targetPosition, passes the beginning, and arrives at the targetPosition.
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3( 0.0f, 0.0f, 0.0f ), TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render( static_cast< unsigned int >( durationSeconds * 500.0f )/* 100% time progress */ );
+
+ // We did expect the animation to finish
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+ }
+
+ animation.SetLooping( false );
+ application.SendNotification();
+ application.Render(static_cast< unsigned int >( durationSeconds * 1000.0f ) + 1u /*just beyond the animation duration*/);
+
+ application.SendNotification();
+ finishCheck.CheckSignalReceived();
+
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
+int UtcDaliAnimationSetLoopingModeP2(void)
+{
+ // Test Loop Count and Loop mode being set
+ TestApplication application;
+ Stage stage( Stage::GetCurrent() );
+
+ // LoopingMode::AUTO_REVERSE
+ {
+ Actor actor = Actor::New();
+ stage.Add( actor );
+
+ float durationSeconds( 1.0f );
+ Animation animation = Animation::New( durationSeconds );
+ animation.SetLoopCount(3);
+ DALI_TEST_CHECK(animation.IsLooping());
+
+ bool signalReceived( false );
+ AnimationFinishCheck finishCheck( signalReceived );
+ animation.FinishedSignal().Connect( &application, finishCheck );
+ application.SendNotification();
+
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition );
+
+ DevelAnimation::SetLoopingMode( animation, DevelAnimation::LoopingMode::AUTO_REVERSE );
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::AUTO_REVERSE );
+
+ // Start the animation
+ animation.Play();
+
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+
+ // Loop
+ float intervalSeconds = 3.0f;
+
+ application.Render(static_cast<unsigned int>(durationSeconds*intervalSeconds*1000.0f));
+ // AUTO_REVERSE mode means, for Animation duration time, the actor starts from the beginning, passes the targetPosition,
+ // and arrives at the beginning.
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3( 0.0f, 0.0f, 0.0f ), TEST_LOCATION );
+
+ application.Render(static_cast<unsigned int>(durationSeconds*intervalSeconds*1000.0f));
+
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+
+ application.Render(static_cast<unsigned int>(durationSeconds*intervalSeconds*1000.0f));
+
+ application.SendNotification();
+ finishCheck.CheckSignalReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), Vector3( 0.0f, 0.0f, 0.0f ), TEST_LOCATION );
+
+ finishCheck.Reset();
+ }
+
+ // LoopingMode::AUTO_REVERSE in Reverse mode, which begin from the end
+ {
+ Actor actor = Actor::New();
+ stage.Add( actor );
+
+ float durationSeconds( 1.0f );
+ Animation animation = Animation::New( durationSeconds );
+ animation.SetLoopCount(3);
+ DALI_TEST_CHECK(animation.IsLooping());
+
+ bool signalReceived( false );
+ AnimationFinishCheck finishCheck( signalReceived );
+ animation.FinishedSignal().Connect( &application, finishCheck );
+ application.SendNotification();
+
+ // Specify a negative multiplier to play the animation in reverse
+ animation.SetSpeedFactor( -1.0f );
+
+ Vector3 targetPosition(100.0f, 100.0f, 100.0f);
+ animation.AnimateTo( Property( actor, Actor::Property::POSITION ), targetPosition );
+
+ DevelAnimation::SetLoopingMode( animation, DevelAnimation::LoopingMode::AUTO_REVERSE );
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::AUTO_REVERSE );
+
+ // Start the animation
+ animation.Play();
+
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+
+ // Loop
+ float intervalSeconds = 3.0f;
+
+ application.Render(static_cast<unsigned int>(durationSeconds*intervalSeconds*1000.0f));
+ // Setting a negative speed factor is to play the animation in reverse.
+ // So, when LoopingMode::AUTO_REVERSE and SetSpeedFactor( -1.0f ) is, for Animation duration time,
+ // the actor starts from the targetPosition, passes the beginning, and arrives at the targetPosition.
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+
+ application.Render(static_cast<unsigned int>(durationSeconds*intervalSeconds*1000.0f));
+
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ application.Render(0);
+ application.SendNotification();
+ finishCheck.CheckSignalNotReceived();
+
+ application.Render(static_cast<unsigned int>(durationSeconds*intervalSeconds*1000.0f));
+
+ application.SendNotification();
+ finishCheck.CheckSignalReceived();
+ DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION );
+
+ finishCheck.Reset();
+ }
+
+ END_TEST;
+}
+
+int UtcDaliAnimationGetLoopingModeP(void)
+{
+ TestApplication application;
+
+ Animation animation = Animation::New(1.0f);
+
+ // default mode
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::RESTART );
+
+ DevelAnimation::SetLoopingMode( animation, DevelAnimation::LoopingMode::AUTO_REVERSE );
+ DALI_TEST_CHECK( DevelAnimation::GetLoopingMode( animation ) == DevelAnimation::AUTO_REVERSE );
+
+ END_TEST;
+}
+
int UtcDaliAnimationProgressSignalConnectionWithoutProgressMarkerP(void)
{
TestApplication application;
#include <dali/public-api/math/quaternion.h>
#include <dali/public-api/math/radian.h>
#include <dali/internal/update/animation/property-accessor.h>
-
+#include <dali/integration-api/debug.h>
namespace Dali
{
AnimatorBase()
: mDurationSeconds(1.0f),
mIntervalDelaySeconds(0.0f),
+ mSpeedFactor(1.0f),
+ mLoopCount(1),
mAlphaFunction(AlphaFunction::DEFAULT),
mDisconnectAction(Dali::Animation::BakeFinal),
mActive(false),
mEnabled(true),
- mConnectedToSceneGraph(false)
+ mConnectedToSceneGraph(false),
+ mAutoReverseEnabled( false )
{
}
return mDurationSeconds;
}
+ void SetSpeedFactor( float factor )
+ {
+ mSpeedFactor = factor;
+ }
+
+ void SetLoopCount(int loopCount)
+ {
+ mLoopCount = loopCount;
+ }
+
+ float SetProgress( float progress )
+ {
+ float value = 0.0f;
+
+ if( mAutoReverseEnabled )
+ {
+ if( mSpeedFactor > 0.0f )
+ {
+ value = 1.0f - 2.0f * std::abs( progress - 0.5f );
+ }
+ // Reverse mode
+ else if( mSpeedFactor < 0.0f )
+ {
+ value = 2.0f * std::abs( progress - 0.5f );
+ }
+ }
+
+ return value;
+ }
+
/**
* Set the delay before the animator should take effect.
* The default is zero i.e. no delay.
return mAlphaFunction;
}
- /*
+ /**
* Applies the alpha function to the specified progress
* @param[in] Current progress
* @return The progress after the alpha function has been aplied
return mActive;
}
- /*
+ /**
* Retrive wheter the animator's target object is valid and on the stage.
* @return The enabled state.
*/
{
return mEnabled;
}
+
+ /**
+ * @brief Sets the looping mode.
+ * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
+ */
+ void SetLoopingMode( bool loopingMode )
+ {
+ mAutoReverseEnabled = loopingMode;
+ }
+
/**
* Returns wheter the target object of the animator is still valid
* or has been destroyed.
float mDurationSeconds;
float mIntervalDelaySeconds;
+ float mSpeedFactor;
+
+ int mLoopCount;
AlphaFunction mAlphaFunction;
bool mActive:1; ///< Animator is "active" while it's running.
bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
+ bool mAutoReverseEnabled:1;
};
/**
*/
virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
{
- float alpha = ApplyAlphaFunction(progress);
+ if( mLoopCount != 1 ) // Looping mode
+ {
+ // Update the progress value
+ progress = SetProgress( progress );
+ }
+
+ float alpha = ApplyAlphaFunction( progress );
const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
*/
virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
{
- float alpha = ApplyAlphaFunction(progress);
+ if( mLoopCount != 1 ) // Looping mode
+ {
+ // Update the progress value
+ progress = SetProgress( progress );
+ }
+
+ float alpha = ApplyAlphaFunction( progress );
const T& current = mPropertyAccessor.Get( bufferIndex );