#define __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#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
{
typedef float (*AlphaFunc)(float progress); ///< Definition of an alpha function
/**
+ * Observer to determine when the animator is no longer present
+ */
+ class LifecycleObserver
+ {
+ public:
+ /**
+ * Called shortly before the animator is destroyed.
+ */
+ virtual void ObjectDestroyed() = 0;
+
+ protected:
+ /**
+ * Virtual destructor, no deletion through this interface
+ */
+ virtual ~LifecycleObserver() = default;
+ };
+
+
+ /**
* Constructor.
*/
AnimatorBase()
- : mDurationSeconds(1.0f),
- mInitialDelaySeconds(0.0f),
+ : mLifecycleObserver(nullptr),
+ 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 )
{
}
*/
virtual ~AnimatorBase()
{
+ if( mLifecycleObserver != nullptr )
+ {
+ mLifecycleObserver->ObjectDestroyed();
+ }
+ }
+
+ void AddLifecycleObserver( LifecycleObserver& observer )
+ {
+ mLifecycleObserver = &observer;
+ }
+
+ void RemoveLifecycleObserver( LifecycleObserver& observer )
+ {
+ mLifecycleObserver = nullptr;
}
/**
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 );
+ }
+ }
+ else
+ {
+ value = progress;
+ }
+
+ return value;
+ }
+
/**
* Set the delay before the animator should take effect.
* The default is zero i.e. no delay.
* @param [in] seconds The delay in seconds.
*/
- void SetInitialDelay(float seconds)
+ void SetIntervalDelay(float seconds)
{
- mInitialDelaySeconds = seconds;
+ mIntervalDelaySeconds = seconds;
}
/**
- * Retrieve the initial delay of the animator.
+ * Retrieve the delay before the animator should take effect.
* @return The delay in seconds.
*/
- float GetInitialDelay() const
+ float GetIntervalDelay() const
{
- return mInitialDelaySeconds;
+ return mIntervalDelaySeconds;
}
/**
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.
return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
}
+ LifecycleObserver* mLifecycleObserver;
float mDurationSeconds;
- float mInitialDelaySeconds;
+ 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;
};
/**
animatorFunction );
animator->SetAlphaFunction( alphaFunction );
- animator->SetInitialDelay( timePeriod.delaySeconds );
+ animator->SetIntervalDelay( timePeriod.delaySeconds );
animator->SetDuration( timePeriod.durationSeconds );
return animator;
*/
virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
{
- float alpha = ApplyAlphaFunction(progress);
+ if( mLoopCount >= 0 )
+ {
+ // Update the progress value
+ progress = SetProgress( progress );
+ }
+
+ float alpha = ApplyAlphaFunction( progress );
const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
animatorFunction );
animator->SetAlphaFunction( alphaFunction );
- animator->SetInitialDelay( timePeriod.delaySeconds );
+ animator->SetIntervalDelay( timePeriod.delaySeconds );
animator->SetDuration( timePeriod.durationSeconds );
return animator;
*/
virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
{
- float alpha = ApplyAlphaFunction(progress);
+ if( mLoopCount >= 0 )
+ {
+ // Update the progress value
+ progress = SetProgress( progress );
+ }
+
+ float alpha = ApplyAlphaFunction( progress );
const T& current = mPropertyAccessor.Get( bufferIndex );
{
}
+ using AnimatorFunctionBase::operator();
float operator()(float alpha, const int& property)
{
return int(property + mRelative * alpha + 0.5f );
{
}
+ using AnimatorFunctionBase::operator();
float operator()(float alpha, const int& property)
{
return int(property + ((mTarget - property) * alpha) + 0.5f);
{
}
+ using AnimatorFunctionBase::operator();
float operator()(float alpha, const float& property)
{
return float(property + mRelative * alpha);
{
}
+ using AnimatorFunctionBase::operator();
float operator()(float alpha, const float& property)
{
return float(property + ((mTarget - property) * alpha));
{
}
+ using AnimatorFunctionBase::operator();
Vector2 operator()(float alpha, const Vector2& property)
{
return Vector2(property + mRelative * alpha);
{
}
+ using AnimatorFunctionBase::operator();
Vector2 operator()(float alpha, const Vector2& property)
{
return Vector2(property + ((mTarget - property) * alpha));
{
}
+ using AnimatorFunctionBase::operator();
Vector3 operator()(float alpha, const Vector3& property)
{
return Vector3(property + mRelative * alpha);
{
}
+ using AnimatorFunctionBase::operator();
Vector3 operator()(float alpha, const Vector3& property)
{
return Vector3(property + ((mTarget - property) * alpha));
{
}
+ using AnimatorFunctionBase::operator();
Vector4 operator()(float alpha, const Vector4& property)
{
return Vector4(property + mRelative * alpha);
{
}
+ using AnimatorFunctionBase::operator();
Vector4 operator()(float alpha, const Vector4& property)
{
return Vector4(property + ((mTarget - property) * alpha));
{
}
+ using AnimatorFunctionBase::operator();
Vector4 operator()(float alpha, const Vector4& property)
{
Vector4 result(property);
{
}
+ using AnimatorFunctionBase::operator();
Vector4 operator()(float alpha, const Vector4& property)
{
Vector4 result(property);
{
}
+ using AnimatorFunctionBase::operator();
bool operator()(float alpha, const bool& property)
{
// Alpha is not useful here, just keeping to the same template as other update functors
{
}
+ using AnimatorFunctionBase::operator();
bool operator()(float alpha, const bool& property)
{
// Alpha is not useful here, just keeping to the same template as other update functors
{
}
+ using AnimatorFunctionBase::operator();
Quaternion operator()(float alpha, const Quaternion& rotation)
{
if (alpha > 0.0f)
{
}
+ using AnimatorFunctionBase::operator();
Quaternion operator()(float alpha, const Quaternion& rotation)
{
return Quaternion::Slerp(rotation, mTarget, alpha);
{
}
+ using AnimatorFunctionBase::operator();
bool operator()(float progress, const bool& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
float operator()(float progress, const int& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
float operator()(float progress, const float& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
Vector2 operator()(float progress, const Vector2& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
Vector3 operator()(float progress, const Vector3& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
Vector4 operator()(float progress, const Vector4& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
Quaternion operator()(float progress, const Quaternion& property)
{
if(mKeyFrames->IsActive(progress))
{
}
+ using AnimatorFunctionBase::operator();
Vector3 operator()(float progress, const Vector3& property)
{
Vector3 position(property);
mForward.Normalize();
}
+ using AnimatorFunctionBase::operator();
Quaternion operator()(float progress, const Quaternion& property)
{
Vector3 tangent;