*
*/
-// EXTERNAL INCLUDES
-#include <boost/function.hpp>
-
// INTERNAL INCLUDES
#include <dali/internal/common/owner-container.h>
#include <dali/internal/event/animation/key-frames-impl.h>
+#include <dali/internal/event/animation/path-impl.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/common/property-base.h>
-#include <dali/internal/common/observer-pointer.h>
#include <dali/public-api/animation/alpha-functions.h>
#include <dali/public-api/animation/animation.h>
#include <dali/public-api/animation/time-period.h>
namespace Internal
{
+typedef Dali::Animation::Interpolation Interpolation;
+
+struct AnimatorFunctionBase;
+
namespace SceneGraph
{
mInitialDelaySeconds(0.0f),
mAlphaFunc(AlphaFunctions::Linear),
mDisconnectAction(Dali::Animation::BakeFinal),
- mActive(false)
+ mActive(false),
+ mEnabled(true)
{
}
/**
* Whether the animator is active or not.
- * @param [in] action The disconnect action.
+ * @param [in] active The new active state.
* @post When the animator becomes active, it applies the disconnect-action if the property owner is then disconnected.
* @note When the property owner is disconnected, the active state is set to false.
*/
return mActive;
}
+ /*
+ * Retrive wheter the animator's target object is valid and on the stage.
+ * @return The enabled state.
+ */
+ bool IsEnabled() const
+ {
+ return mEnabled;
+ }
/**
- * This must be called when the animator is attached to the scene-graph.
- * @pre The animatable scene object must also be attached to the scene-graph.
- * @param[in] propertyOwner The scene-object that owns the animatable property.
+ * Returns wheter the target object of the animator is still valid
+ * or has been destroyed.
+ * @return True if animator is orphan, false otherwise *
+ * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
*/
- virtual void Attach( PropertyOwner* propertyOwner ) = 0;
+ virtual bool Orphan() = 0;
/**
* Update the scene object attached to the animator.
* @param[in] bufferIndex The buffer to animate.
* @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
* @param[in] bake Bake.
- * @return True if the update was applied, false if the animator has been orphaned.
*/
- virtual bool Update(BufferIndex bufferIndex, float progress, bool bake) = 0;
-
- /**
- * Query whether the animator is still attached to a scene object.
- * The attachment will be automatically severed, when the object is destroyed.
- * @return True if the animator is attached.
- */
- virtual bool IsAttached() const = 0;
+ virtual void Update(BufferIndex bufferIndex, float progress, bool bake) = 0;
protected:
AlphaFunc mAlphaFunc;
- Dali::Animation::EndAction mDisconnectAction;
- bool mActive:1;
+ Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
+ 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.
};
/**
{
public:
- typedef boost::function< PropertyType (float, const PropertyType&) > AnimatorFunction;
-
/**
* Construct a new property animator.
* @param[in] property The animatable property; only valid while the Animator is attached.
* @param[in] timePeriod The time period of this animation.
* @return A newly allocated animator.
*/
- static AnimatorBase* New( const PropertyBase& property,
- AnimatorFunction animatorFunction,
+ static AnimatorBase* New( const PropertyOwner& propertyOwner,
+ const PropertyBase& property,
+ AnimatorFunctionBase* animatorFunction,
AlphaFunction alphaFunction,
const TimePeriod& timePeriod )
{
typedef Animator< PropertyType, PropertyAccessorType > AnimatorType;
// The property was const in the actor-thread, but animators are used in the scene-graph thread.
- AnimatorType* animator = new AnimatorType( const_cast<PropertyBase*>( &property ),
+ AnimatorType* animator = new AnimatorType( const_cast<PropertyOwner*>( &propertyOwner ),
+ const_cast<PropertyBase*>( &property ),
animatorFunction );
animator->SetAlphaFunc( alphaFunction );
{
mPropertyOwner->RemoveObserver(*this);
}
- }
-
- /**
- * From AnimatorBase.
- * @param[in] propertyOwner The scene-object that owns the animatable property.
- */
- virtual void Attach( PropertyOwner* propertyOwner )
- {
- mPropertyOwner = propertyOwner;
-
- if (mPropertyOwner)
- {
- mPropertyOwner->AddObserver(*this);
- }
- }
- /**
- * From AnimatorBase.
- */
- virtual bool Update( BufferIndex bufferIndex, float progress, bool bake )
- {
- // If the object dies, the animator has no effect
- if ( mPropertyOwner )
+ if( mAnimatorFunction )
{
- float alpha = mAlphaFunc( progress );
-
- const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
-
- const PropertyType result = mAnimatorFunction( alpha, current );
-
- if ( bake )
- {
- mPropertyAccessor.Bake( bufferIndex, result );
- }
- else
- {
- mPropertyAccessor.Set( bufferIndex, result );
- }
-
- mCurrentProgress = progress;
+ delete mAnimatorFunction;
}
-
- return IsAttached(); // return false if orphaned
}
/**
- * From AnimatorBase.
+ * Called when mPropertyOwner is connected to the scene graph.
*/
- virtual bool IsAttached() const
+ virtual void PropertyOwnerConnected( PropertyOwner& owner )
{
- return NULL != mPropertyOwner;
+ mEnabled = true;
}
/**
}
mActive = false;
- mPropertyOwner = NULL;
- mPropertyAccessor.Reset();
+ mEnabled = false;
}
/**
- * Called shortly before mPropertyOwner is destroyed, along with its property.
+ * Called shortly before mPropertyOwner is destroyed
*/
virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
{
mPropertyOwner = NULL;
mPropertyAccessor.Reset();
+ mEnabled = false;
+ }
+
+ /**
+ * From AnimatorBase.
+ */
+ virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
+ {
+ float alpha = mAlphaFunc( progress );
+ const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
+
+ const PropertyType result = (*mAnimatorFunction)( alpha, current );
+ if ( bake )
+ {
+ mPropertyAccessor.Bake( bufferIndex, result );
+ }
+ else
+ {
+ mPropertyAccessor.Set( bufferIndex, result );
+ }
+
+ mCurrentProgress = progress;
+ }
+
+ /**
+ * From AnimatorBase.
+ */
+ virtual bool Orphan()
+ {
+ return (mPropertyOwner == NULL);
}
private:
/**
* Private constructor; see also Animator::New().
*/
- Animator( PropertyBase* property,
- AnimatorFunction animatorFunction )
- : mPropertyOwner( NULL ),
+ Animator( PropertyOwner* propertyOwner,
+ PropertyBase* property,
+ AnimatorFunctionBase* animatorFunction )
+ : mPropertyOwner( propertyOwner ),
mPropertyAccessor( property ),
mAnimatorFunction( animatorFunction ),
mCurrentProgress( 0.0f )
{
+ mPropertyOwner->AddObserver(*this);
}
// Undefined
PropertyOwner* mPropertyOwner;
PropertyAccessorType mPropertyAccessor;
- AnimatorFunction mAnimatorFunction;
+ AnimatorFunctionBase* mAnimatorFunction;
float mCurrentProgress;
};
} // namespace SceneGraph
+/*
+ * AnimatorFunction base class.
+ * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
+ */
+struct AnimatorFunctionBase
+{
+ /**
+ * Constructor
+ */
+ AnimatorFunctionBase(){}
+
+ /*
+ * Virtual destructor (Intended as base class)
+ */
+ virtual ~AnimatorFunctionBase(){}
+
+ ///Stub "()" operators.
+ virtual float operator()(float progress, const int& property)
+ {
+ return property;
+ }
+
+ virtual float operator()(float progress, const float& property)
+ {
+ return property;
+ }
+
+ virtual bool operator()(float progress, const bool& property)
+ {
+ return property;
+ }
+
+ virtual Vector2 operator()(float progress, const Vector2& property)
+ {
+ return property;
+ }
+
+ virtual Vector3 operator()(float progress, const Vector3& property)
+ {
+ return property;
+ }
-// Common Update functions
+ virtual Vector4 operator()(float progress, const Vector4& property)
+ {
+ return property;
+ }
-struct AnimateByFloat
+ virtual Quaternion operator()(float progress, const Quaternion& property)
+ {
+ return property;
+ }
+};
+
+// Update functions
+
+struct AnimateByFloat : public AnimatorFunctionBase
{
AnimateByFloat(const float& relativeValue)
: mRelative(relativeValue)
float mRelative;
};
-struct AnimateToFloat
+struct AnimateToFloat : public AnimatorFunctionBase
{
AnimateToFloat(const float& targetValue)
: mTarget(targetValue)
float mTarget;
};
-struct AnimateByInteger
+struct AnimateByInteger : public AnimatorFunctionBase
{
AnimateByInteger(const int& relativeValue)
: mRelative(relativeValue)
int mRelative;
};
-struct AnimateToInteger
+struct AnimateToInteger : public AnimatorFunctionBase
{
AnimateToInteger(const int& targetValue)
: mTarget(targetValue)
int mTarget;
};
-struct AnimateByVector2
+struct AnimateByVector2 : public AnimatorFunctionBase
{
AnimateByVector2(const Vector2& relativeValue)
: mRelative(relativeValue)
Vector2 mRelative;
};
-struct AnimateToVector2
+struct AnimateToVector2 : public AnimatorFunctionBase
{
AnimateToVector2(const Vector2& targetValue)
: mTarget(targetValue)
Vector2 mTarget;
};
-struct AnimateByVector3
+struct AnimateByVector3 : public AnimatorFunctionBase
{
AnimateByVector3(const Vector3& relativeValue)
: mRelative(relativeValue)
Vector3 mRelative;
};
-struct AnimateToVector3
+struct AnimateToVector3 : public AnimatorFunctionBase
{
AnimateToVector3(const Vector3& targetValue)
: mTarget(targetValue)
Vector3 mTarget;
};
-struct AnimateByVector4
+struct AnimateByVector4 : public AnimatorFunctionBase
{
AnimateByVector4(const Vector4& relativeValue)
: mRelative(relativeValue)
Vector4 mRelative;
};
-struct AnimateToVector4
+struct AnimateToVector4 : public AnimatorFunctionBase
{
AnimateToVector4(const Vector4& targetValue)
: mTarget(targetValue)
Vector4 mTarget;
};
-struct AnimateByOpacity
+struct AnimateByOpacity : public AnimatorFunctionBase
{
AnimateByOpacity(const float& relativeValue)
: mRelative(relativeValue)
float mRelative;
};
-struct AnimateToOpacity
+struct AnimateToOpacity : public AnimatorFunctionBase
{
AnimateToOpacity(const float& targetValue)
: mTarget(targetValue)
float mTarget;
};
-struct AnimateByBoolean
+struct AnimateByBoolean : public AnimatorFunctionBase
{
AnimateByBoolean(bool relativeValue)
: mRelative(relativeValue)
bool mRelative;
};
-struct AnimateToBoolean
+struct AnimateToBoolean : public AnimatorFunctionBase
{
AnimateToBoolean(bool targetValue)
: mTarget(targetValue)
bool mTarget;
};
-struct RotateByAngleAxis
+struct RotateByAngleAxis : public AnimatorFunctionBase
{
RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
: mAngleRadians(angleRadians),
Vector4 mAxis;
};
-struct RotateToQuaternion
+struct RotateToQuaternion : public AnimatorFunctionBase
{
RotateToQuaternion(const Quaternion& targetValue)
: mTarget(targetValue)
};
-struct KeyFrameBooleanFunctor
+struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
{
KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
: mKeyFrames(keyFrames)
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
}
return property;
}
KeyFrameBooleanPtr mKeyFrames;
};
-struct KeyFrameNumberFunctor
+struct KeyFrameNumberFunctor : public AnimatorFunctionBase
{
- KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames)
- : mKeyFrames(keyFrames)
+ KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
+ : mKeyFrames(keyFrames),mInterpolation(interpolation)
{
}
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, mInterpolation);
}
return property;
}
KeyFrameNumberPtr mKeyFrames;
+ Interpolation mInterpolation;
};
-struct KeyFrameIntegerFunctor
+struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
{
- KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames)
- : mKeyFrames(keyFrames)
+ KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
+ : mKeyFrames(keyFrames),mInterpolation(interpolation)
{
}
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, mInterpolation);
}
return property;
}
KeyFrameIntegerPtr mKeyFrames;
+ Interpolation mInterpolation;
};
-struct KeyFrameVector2Functor
+struct KeyFrameVector2Functor : public AnimatorFunctionBase
{
- KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames)
- : mKeyFrames(keyFrames)
+ KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
+ : mKeyFrames(keyFrames),mInterpolation(interpolation)
{
}
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, mInterpolation);
}
return property;
}
KeyFrameVector2Ptr mKeyFrames;
+ Interpolation mInterpolation;
};
-struct KeyFrameVector3Functor
+struct KeyFrameVector3Functor : public AnimatorFunctionBase
{
- KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames)
- : mKeyFrames(keyFrames)
+ KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
+ : mKeyFrames(keyFrames),mInterpolation(interpolation)
{
}
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, mInterpolation);
}
return property;
}
KeyFrameVector3Ptr mKeyFrames;
+ Interpolation mInterpolation;
};
-struct KeyFrameVector4Functor
+struct KeyFrameVector4Functor : public AnimatorFunctionBase
{
- KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames)
- : mKeyFrames(keyFrames)
+ KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
+ : mKeyFrames(keyFrames),mInterpolation(interpolation)
{
}
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, mInterpolation);
}
return property;
}
KeyFrameVector4Ptr mKeyFrames;
+ Interpolation mInterpolation;
};
-struct KeyFrameQuaternionFunctor
+struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
{
KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
: mKeyFrames(keyFrames)
{
if(mKeyFrames->IsActive(progress))
{
- return mKeyFrames->GetValue(progress);
+ return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
}
return property;
}
KeyFrameQuaternionPtr mKeyFrames;
};
+struct PathPositionFunctor : public AnimatorFunctionBase
+{
+ PathPositionFunctor( PathPtr path )
+ : mPath(path)
+ {
+ }
+ Vector3 operator()(float progress, const Vector3& property)
+ {
+ return mPath->SamplePosition(progress );
+ }
+
+ PathPtr mPath;
+};
+
+struct PathRotationFunctor : public AnimatorFunctionBase
+{
+ PathRotationFunctor( PathPtr path, const Vector3& forward )
+ : mPath(path),
+ mForward( forward )
+ {
+ mForward.Normalize();
+ }
+
+ Quaternion operator()(float progress, const Quaternion& property)
+ {
+ Vector3 tangent( mPath->SampleTangent(progress) );
+ return Quaternion( mForward, tangent );
+ }
+
+ PathPtr mPath;
+ Vector3 mForward;
+};
} // namespace Internal