X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fanimation%2Fscene-graph-animator.h;h=391bacfb1feb090a480393393e5966b5325395d7;hb=1fdfbc2906bc1dcae714eedfbe6c7f94cd6f9364;hp=1cc6ab6a26be1e1e33831bef32a7ec16478904e2;hpb=80a17733af457e9c4609b2b86f6fa0ec90d53151;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/animation/scene-graph-animator.h b/dali/internal/update/animation/scene-graph-animator.h index 1cc6ab6..391bacf 100644 --- a/dali/internal/update/animation/scene-graph-animator.h +++ b/dali/internal/update/animation/scene-graph-animator.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -20,8 +20,14 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES +#include +#include +#include +#include +#include #include #include #include @@ -29,79 +35,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include namespace Dali { - namespace Internal { - using Interpolation = Dali::Animation::Interpolation; -/** - * AnimatorFunction base class. - * Needs to be declared first so AnimatorBase knows about it's destructor - * 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 bool operator()(float progress, const bool& property) - { - return property; - } - - virtual float operator()(float progress, const int32_t& property) - { - return static_cast( property ); - } - - virtual float operator()(float progress, const float& property) - { - return property; - } - - virtual Vector2 operator()(float progress, const Vector2& property) - { - return property; - } - - virtual Vector3 operator()(float progress, const Vector3& property) - { - return property; - } - - virtual Vector4 operator()(float progress, const Vector4& property) - { - return property; - } - - virtual Quaternion operator()(float progress, const Quaternion& property) - { - return property; - } -}; - namespace SceneGraph { - /** * An abstract base class for Animators, which can be added to scene graph animations. * Each animator changes a single property of an object in the scene graph. @@ -109,7 +51,6 @@ namespace SceneGraph class AnimatorBase : public PropertyOwner::Observer { public: - using AlphaFunc = float (*)(float progress); ///< Definition of an alpha function /** @@ -130,28 +71,24 @@ public: virtual ~LifecycleObserver() = default; }; - /** * Constructor. */ - AnimatorBase( PropertyOwner* propertyOwner, - AnimatorFunctionBase* animatorFunction, - AlphaFunction alphaFunction, - const TimePeriod& timePeriod ) - : mLifecycleObserver( nullptr ), - mPropertyOwner( propertyOwner ), - mAnimatorFunction( animatorFunction ), - mDurationSeconds( timePeriod.durationSeconds ), - mIntervalDelaySeconds( timePeriod.delaySeconds ), - mSpeedFactor( 1.0f ), - mCurrentProgress( 0.f ), - mLoopCount( 1 ), - mAlphaFunction( alphaFunction ), - mDisconnectAction( Dali::Animation::BAKE_FINAL ), - mAnimationPlaying( false ), - mEnabled( true ), - mConnectedToSceneGraph( false ), - mAutoReverseEnabled( false ) + AnimatorBase(PropertyOwner* propertyOwner, + AlphaFunction alphaFunction, + const TimePeriod& timePeriod) + : mLifecycleObserver(nullptr), + mPropertyOwner(propertyOwner), + mDurationSeconds(timePeriod.durationSeconds), + mIntervalDelaySeconds(timePeriod.delaySeconds), + mSpeedFactor(1.0f), + mCurrentProgress(0.f), + mAlphaFunction(alphaFunction), + mDisconnectAction(Dali::Animation::BAKE_FINAL), + mAnimationPlaying(false), + mEnabled(true), + mConnectedToSceneGraph(false), + mAutoReverseEnabled(false) { } @@ -160,33 +97,31 @@ public: */ ~AnimatorBase() override { - delete mAnimatorFunction; - if (mPropertyOwner && mConnectedToSceneGraph) + if(mPropertyOwner && mConnectedToSceneGraph) { mPropertyOwner->RemoveObserver(*this); } - if( mLifecycleObserver != nullptr ) + if(mLifecycleObserver != nullptr) { mLifecycleObserver->ObjectDestroyed(); } } - void AddLifecycleObserver( LifecycleObserver& observer ) + void AddLifecycleObserver(LifecycleObserver& observer) { mLifecycleObserver = &observer; } - void RemoveLifecycleObserver( LifecycleObserver& observer ) + void RemoveLifecycleObserver(LifecycleObserver& observer) { mLifecycleObserver = nullptr; } private: // From PropertyOwner::Observer - /** * @copydoc PropertyOwner::Observer::PropertyOwnerConnected( PropertyOwner& owner ) */ - void PropertyOwnerConnected( PropertyOwner& owner ) final + void PropertyOwnerConnected(PropertyOwner& owner) final { mEnabled = true; } @@ -194,13 +129,13 @@ private: // From PropertyOwner::Observer /** * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) */ - void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) final + void PropertyOwnerDisconnected(BufferIndex bufferIndex, PropertyOwner& owner) final { // If we are active, then bake the value if required - if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::DISCARD ) + if(mAnimationPlaying && mDisconnectAction != Dali::Animation::DISCARD) { // Bake to target-value if BakeFinal, otherwise bake current value - Update( bufferIndex, ( mDisconnectAction == Dali::Animation::BAKE ? mCurrentProgress : 1.0f ), true ); + Update(bufferIndex, (mDisconnectAction == Dali::Animation::BAKE ? mCurrentProgress : 1.0f), true); } mEnabled = false; @@ -209,7 +144,7 @@ private: // From PropertyOwner::Observer /** * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed( PropertyOwner& owner ) */ - void PropertyOwnerDestroyed( PropertyOwner& owner ) final + void PropertyOwnerDestroyed(PropertyOwner& owner) final { mPropertyOwner = nullptr; } @@ -222,6 +157,9 @@ public: { mConnectedToSceneGraph = true; mPropertyOwner->AddObserver(*this); + + // Enable if the target object is valid and connected to the scene graph. + mEnabled = mPropertyOwner->IsAnimationPossible(); } /** @@ -245,7 +183,7 @@ public: return mDurationSeconds; } - void SetSpeedFactor( float factor ) + void SetSpeedFactor(float factor) { mSpeedFactor = factor; } @@ -255,20 +193,20 @@ public: mLoopCount = loopCount; } - float SetProgress( float progress ) + float SetProgress(float progress) { float value = 0.0f; - if( mAutoReverseEnabled ) + if(mAutoReverseEnabled) { - if( mSpeedFactor > 0.0f ) + if(mSpeedFactor > 0.0f) { - value = 1.0f - 2.0f * std::abs( progress - 0.5f ); + value = 1.0f - 2.0f * std::abs(progress - 0.5f); } // Reverse mode - else if( mSpeedFactor < 0.0f ) + else if(mSpeedFactor < 0.0f) { - value = 2.0f * std::abs( progress - 0.5f ); + value = 2.0f * std::abs(progress - 0.5f); } } else @@ -321,12 +259,12 @@ public: * @param[in] Current progress * @return The progress after the alpha function has been aplied */ - float ApplyAlphaFunction( float progress ) const + float ApplyAlphaFunction(float progress) const { float result = progress; - AlphaFunction::Mode alphaFunctionMode( mAlphaFunction.GetMode() ); - if( alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION ) + AlphaFunction::Mode alphaFunctionMode(mAlphaFunction.GetMode()); + if(alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION) { switch(mAlphaFunction.GetBuiltinFunction()) { @@ -337,7 +275,7 @@ public: } case AlphaFunction::REVERSE: { - result = 1.0f-progress; + result = 1.0f - progress; break; } case AlphaFunction::EASE_IN_SQUARE: @@ -347,7 +285,7 @@ public: } case AlphaFunction::EASE_OUT_SQUARE: { - result = 1.0f - (1.0f-progress) * (1.0f-progress); + result = 1.0f - (1.0f - progress) * (1.0f - progress); break; } case AlphaFunction::EASE_IN: @@ -357,12 +295,12 @@ public: } case AlphaFunction::EASE_OUT: { - result = (progress-1.0f) * (progress-1.0f) * (progress-1.0f) + 1.0f; + result = (progress - 1.0f) * (progress - 1.0f) * (progress - 1.0f) + 1.0f; break; } case AlphaFunction::EASE_IN_OUT: { - result = progress*progress*(3.0f-2.0f*progress); + result = progress * progress * (3.0f - 2.0f * progress); break; } case AlphaFunction::EASE_IN_SINE: @@ -394,7 +332,7 @@ public: { const float sqrt2 = 1.70158f; progress -= 1.0f; - result = 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 ); + result = 1.0f + progress * progress * ((sqrt2 + 1.0f) * progress + sqrt2); break; } case AlphaFunction::COUNT: @@ -403,10 +341,10 @@ public: } } } - else if( alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION ) + else if(alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION) { AlphaFunctionPrototype customFunction = mAlphaFunction.GetCustomFunction(); - if( customFunction ) + if(customFunction) { result = customFunction(progress); } @@ -415,20 +353,20 @@ public: { //If progress is very close to 0 or very close to 1 we don't need to evaluate the curve as the result will //be almost 0 or almost 1 respectively - if( ( progress > Math::MACHINE_EPSILON_1 ) && ((1.0f - progress) > Math::MACHINE_EPSILON_1) ) + if((progress > Math::MACHINE_EPSILON_1) && ((1.0f - progress) > Math::MACHINE_EPSILON_1)) { Dali::Vector4 controlPoints = mAlphaFunction.GetBezierControlPoints(); - static const float tolerance = 0.001f; //10 iteration max + static const float tolerance = 0.001f; //10 iteration max //Perform a binary search on the curve float lowerBound(0.0f); float upperBound(1.0f); float currentT(0.5f); - float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT); - while( fabsf( progress - currentX ) > tolerance ) + float currentX = EvaluateCubicBezier(controlPoints.x, controlPoints.z, currentT); + while(fabsf(progress - currentX) > tolerance) { - if( progress > currentX ) + if(progress > currentX) { lowerBound = currentT; } @@ -436,10 +374,10 @@ public: { upperBound = currentT; } - currentT = (upperBound+lowerBound)*0.5f; - currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT); + currentT = (upperBound + lowerBound) * 0.5f; + currentX = EvaluateCubicBezier(controlPoints.x, controlPoints.z, currentT); } - result = EvaluateCubicBezier( controlPoints.y, controlPoints.w, currentT); + result = EvaluateCubicBezier(controlPoints.y, controlPoints.w, currentT); } } @@ -451,7 +389,7 @@ public: * Property is only baked if the animator is active. * @param [in] action The disconnect action. */ - void SetDisconnectAction( Dali::Animation::EndAction action ) + void SetDisconnectAction(Dali::Animation::EndAction action) { mDisconnectAction = action; } @@ -471,7 +409,7 @@ public: * @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. */ - void SetActive( bool active ) + void SetActive(bool active) { mAnimationPlaying = active; } @@ -489,7 +427,7 @@ public: * @brief Sets the looping mode. * @param[in] loopingMode True when the looping mode is AUTO_REVERSE */ - void SetLoopingMode( bool loopingMode ) + void SetLoopingMode(bool loopingMode) { mAutoReverseEnabled = loopingMode; } @@ -511,23 +449,23 @@ public: * @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. */ - void Update( BufferIndex bufferIndex, float progress, bool bake ) + void Update(BufferIndex bufferIndex, float progress, bool bake) { - if( mLoopCount >= 0 ) + if(mLoopCount >= 0) { // Update the progress value - progress = SetProgress( progress ); + progress = SetProgress(progress); } - if( mPropertyOwner ) + if(mPropertyOwner) { - mPropertyOwner->SetUpdated( true ); + mPropertyOwner->SetUpdated(true); } - float alpha = ApplyAlphaFunction( progress ); + float alpha = ApplyAlphaFunction(progress); // PropertyType specific part - DoUpdate( bufferIndex, bake, alpha ); + DoUpdate(bufferIndex, bake, alpha); mCurrentProgress = progress; } @@ -538,10 +476,9 @@ public: * @param bake whether to bake or not * @param alpha value from alpha based on progress */ - virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) = 0; + virtual void DoUpdate(BufferIndex bufferIndex, bool bake, float alpha) = 0; protected: - /** * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0 * @param[in] p0 First control point of the bezier curve @@ -549,39 +486,41 @@ protected: * @param[in] t A floating point value between 0.0 and 1.0 * @return Value of the curve at progress t */ - inline float EvaluateCubicBezier( float p0, float p1, float t ) const + inline float EvaluateCubicBezier(float p0, float p1, float t) const { - float tSquare = t*t; - return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t; + float tSquare = t * t; + return 3.0f * (1.0f - t) * (1.0f - t) * t * p0 + 3.0f * (1.0f - t) * tSquare * p1 + tSquare * t; } LifecycleObserver* mLifecycleObserver; - PropertyOwner* mPropertyOwner; - AnimatorFunctionBase* mAnimatorFunction; + PropertyOwner* mPropertyOwner; + float mDurationSeconds; float mIntervalDelaySeconds; float mSpeedFactor; float mCurrentProgress; - int32_t mLoopCount; - AlphaFunction mAlphaFunction; - Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage. - bool mAnimationPlaying:1; ///< whether disconnect has been applied 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; + int32_t mLoopCount{1}; + Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage. + bool mAnimationPlaying : 1; ///< whether disconnect has been applied 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; }; /** * An animator for a specific property type PropertyType. */ -template < typename PropertyType, typename PropertyAccessorType > -class Animator : public AnimatorBase +template +class Animator final : public AnimatorBase { -public: + using AnimatorFunction = std::function; + + AnimatorFunction mAnimatorFunction; +public: /** * Construct a new property animator. * @param[in] property The animatable property; only valid while the Animator is attached. @@ -590,86 +529,78 @@ public: * @param[in] timePeriod The time period of this animation. * @return A newly allocated animator. */ - static AnimatorBase* New( const PropertyOwner& propertyOwner, - const PropertyBase& property, - AnimatorFunctionBase* animatorFunction, - AlphaFunction alphaFunction, - const TimePeriod& timePeriod ) + static AnimatorBase* New(const PropertyOwner& propertyOwner, + const PropertyBase& property, + AnimatorFunction animatorFunction, + AlphaFunction alphaFunction, + const TimePeriod& timePeriod) { // The property was const in the actor-thread, but animators are used in the scene-graph thread. - return new Animator( const_cast( &propertyOwner ), - const_cast( &property ), - animatorFunction, - alphaFunction, - timePeriod ); - } - - /** - * Virtual destructor. - */ - ~Animator() override - { + return new Animator(const_cast(&propertyOwner), + const_cast(&property), + std::move(animatorFunction), + alphaFunction, + timePeriod); } /** * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) */ - void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final + void DoUpdate(BufferIndex bufferIndex, bool bake, float alpha) final { - const PropertyType& current = mPropertyAccessor.Get( bufferIndex ); + const PropertyType& current = mPropertyAccessor.Get(bufferIndex); // need to cast the return value in case property is integer - const PropertyType result = static_cast( (*mAnimatorFunction)( alpha, current ) ); + const PropertyType result = static_cast(mAnimatorFunction(alpha, current)); - if ( bake ) + if(bake) { - mPropertyAccessor.Bake( bufferIndex, result ); + mPropertyAccessor.Bake(bufferIndex, result); } else { - mPropertyAccessor.Set( bufferIndex, result ); + mPropertyAccessor.Set(bufferIndex, result); } } private: - /** * Private constructor; see also Animator::New(). */ - Animator( PropertyOwner* propertyOwner, - PropertyBase* property, - AnimatorFunctionBase* animatorFunction, - AlphaFunction alphaFunction, - const TimePeriod& timePeriod ) - : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ), - mPropertyAccessor( property ) + Animator(PropertyOwner* propertyOwner, + PropertyBase* property, + AnimatorFunction animatorFunction, + AlphaFunction alphaFunction, + const TimePeriod& timePeriod) + : AnimatorBase(propertyOwner, alphaFunction, timePeriod), + mAnimatorFunction(std::move(animatorFunction)), + mPropertyAccessor(property) { // WARNING - this object is created in the event-thread // The scene-graph mPropertyOwner object cannot be observed here } // Undefined - Animator( const Animator& ); + Animator(const Animator&); // Undefined - Animator& operator=( const Animator& ); + Animator& operator=(const Animator&); protected: - PropertyAccessorType mPropertyAccessor; - }; - - /** * An animator for a specific property type PropertyType. */ -template -class AnimatorTransformProperty : public AnimatorBase +template +class AnimatorTransformProperty final : public AnimatorBase { -public: + using AnimatorFunction = std::function; + + AnimatorFunction mAnimatorFunction; +public: /** * Construct a new property animator. * @param[in] property The animatable property; only valid while the Animator is attached. @@ -678,123 +609,110 @@ public: * @param[in] timePeriod The time period of this animation. * @return A newly allocated animator. */ - static AnimatorBase* New( const PropertyOwner& propertyOwner, - const PropertyBase& property, - AnimatorFunctionBase* animatorFunction, - AlphaFunction alphaFunction, - const TimePeriod& timePeriod ) + static AnimatorBase* New(const PropertyOwner& propertyOwner, + const PropertyBase& property, + AnimatorFunction animatorFunction, + AlphaFunction alphaFunction, + const TimePeriod& timePeriod) { - // The property was const in the actor-thread, but animators are used in the scene-graph thread. - return new AnimatorTransformProperty( const_cast( &propertyOwner ), - const_cast( &property ), - animatorFunction, - alphaFunction, - timePeriod ); - } - - /** - * Virtual destructor. - */ - ~AnimatorTransformProperty() override - { + return new AnimatorTransformProperty(const_cast(&propertyOwner), + const_cast(&property), + std::move(animatorFunction), + alphaFunction, + timePeriod); } /** * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) */ - void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final + void DoUpdate(BufferIndex bufferIndex, bool bake, float alpha) final { - const PropertyType& current = mPropertyAccessor.Get( bufferIndex ); + const PropertyType& current = mPropertyAccessor.Get(bufferIndex); // need to cast the return value in case property is integer - const PropertyType result = static_cast( (*mAnimatorFunction)( alpha, current ) ); + const PropertyType result = static_cast(mAnimatorFunction(alpha, current)); - if ( bake ) + if(bake) { - mPropertyAccessor.Bake( bufferIndex, result ); + mPropertyAccessor.Bake(bufferIndex, result); } else { - mPropertyAccessor.Set( bufferIndex, result ); + mPropertyAccessor.Set(bufferIndex, result); } } private: - /** * Private constructor; see also Animator::New(). */ - AnimatorTransformProperty( PropertyOwner* propertyOwner, - PropertyBase* property, - AnimatorFunctionBase* animatorFunction, - AlphaFunction alphaFunction, - const TimePeriod& timePeriod ) - : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ), - mPropertyAccessor( property ) + AnimatorTransformProperty(PropertyOwner* propertyOwner, + PropertyBase* property, + AnimatorFunction animatorFunction, + AlphaFunction alphaFunction, + const TimePeriod& timePeriod) + : AnimatorBase(propertyOwner, alphaFunction, timePeriod), + mAnimatorFunction(std::move(animatorFunction)), + mPropertyAccessor(property) { // WARNING - this object is created in the event-thread // The scene-graph mPropertyOwner object cannot be observed here } // Undefined - AnimatorTransformProperty() = delete; - AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete; - AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete; + AnimatorTransformProperty() = delete; + AnimatorTransformProperty(const AnimatorTransformProperty&) = delete; + AnimatorTransformProperty& operator=(const AnimatorTransformProperty&) = delete; protected: - PropertyAccessorType mPropertyAccessor; - }; } // namespace SceneGraph // Update functions -struct AnimateByInteger : public AnimatorFunctionBase +struct AnimateByInteger { AnimateByInteger(const int& relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - float operator()(float alpha, const int32_t& property) override + float operator()(float alpha, const int32_t& property) { // integers need to be correctly rounded - return roundf(static_cast( property ) + static_cast( mRelative ) * alpha ); + return roundf(static_cast(property) + static_cast(mRelative) * alpha); } int32_t mRelative; }; -struct AnimateToInteger : public AnimatorFunctionBase +struct AnimateToInteger { AnimateToInteger(const int& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - float operator()(float alpha, const int32_t& property) override + float operator()(float alpha, const int32_t& property) { // integers need to be correctly rounded - return roundf(static_cast( property ) + (static_cast(mTarget - property) * alpha) ); + return roundf(static_cast(property) + (static_cast(mTarget - property) * alpha)); } int32_t mTarget; }; -struct AnimateByFloat : public AnimatorFunctionBase +struct AnimateByFloat { AnimateByFloat(const float& relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - float operator()(float alpha, const float& property) override + float operator()(float alpha, const float& property) { return float(property + mRelative * alpha); } @@ -802,15 +720,14 @@ struct AnimateByFloat : public AnimatorFunctionBase float mRelative; }; -struct AnimateToFloat : public AnimatorFunctionBase +struct AnimateToFloat { AnimateToFloat(const float& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - float operator()(float alpha, const float& property) override + float operator()(float alpha, const float& property) { return float(property + ((mTarget - property) * alpha)); } @@ -818,15 +735,14 @@ struct AnimateToFloat : public AnimatorFunctionBase float mTarget; }; -struct AnimateByVector2 : public AnimatorFunctionBase +struct AnimateByVector2 { AnimateByVector2(const Vector2& relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - Vector2 operator()(float alpha, const Vector2& property) override + Vector2 operator()(float alpha, const Vector2& property) { return Vector2(property + mRelative * alpha); } @@ -834,15 +750,14 @@ struct AnimateByVector2 : public AnimatorFunctionBase Vector2 mRelative; }; -struct AnimateToVector2 : public AnimatorFunctionBase +struct AnimateToVector2 { AnimateToVector2(const Vector2& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - Vector2 operator()(float alpha, const Vector2& property) override + Vector2 operator()(float alpha, const Vector2& property) { return Vector2(property + ((mTarget - property) * alpha)); } @@ -850,15 +765,14 @@ struct AnimateToVector2 : public AnimatorFunctionBase Vector2 mTarget; }; -struct AnimateByVector3 : public AnimatorFunctionBase +struct AnimateByVector3 { AnimateByVector3(const Vector3& relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - Vector3 operator()(float alpha, const Vector3& property) override + Vector3 operator()(float alpha, const Vector3& property) { return Vector3(property + mRelative * alpha); } @@ -866,15 +780,14 @@ struct AnimateByVector3 : public AnimatorFunctionBase Vector3 mRelative; }; -struct AnimateToVector3 : public AnimatorFunctionBase +struct AnimateToVector3 { AnimateToVector3(const Vector3& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - Vector3 operator()(float alpha, const Vector3& property) override + Vector3 operator()(float alpha, const Vector3& property) { return Vector3(property + ((mTarget - property) * alpha)); } @@ -882,15 +795,14 @@ struct AnimateToVector3 : public AnimatorFunctionBase Vector3 mTarget; }; -struct AnimateByVector4 : public AnimatorFunctionBase +struct AnimateByVector4 { AnimateByVector4(const Vector4& relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - Vector4 operator()(float alpha, const Vector4& property) override + Vector4 operator()(float alpha, const Vector4& property) { return Vector4(property + mRelative * alpha); } @@ -898,15 +810,14 @@ struct AnimateByVector4 : public AnimatorFunctionBase Vector4 mRelative; }; -struct AnimateToVector4 : public AnimatorFunctionBase +struct AnimateToVector4 { AnimateToVector4(const Vector4& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - Vector4 operator()(float alpha, const Vector4& property) override + Vector4 operator()(float alpha, const Vector4& property) { return Vector4(property + ((mTarget - property) * alpha)); } @@ -914,15 +825,14 @@ struct AnimateToVector4 : public AnimatorFunctionBase Vector4 mTarget; }; -struct AnimateByOpacity : public AnimatorFunctionBase +struct AnimateByOpacity { AnimateByOpacity(const float& relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - Vector4 operator()(float alpha, const Vector4& property) override + Vector4 operator()(float alpha, const Vector4& property) { Vector4 result(property); result.a += mRelative * alpha; @@ -933,15 +843,14 @@ struct AnimateByOpacity : public AnimatorFunctionBase float mRelative; }; -struct AnimateToOpacity : public AnimatorFunctionBase +struct AnimateToOpacity { AnimateToOpacity(const float& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - Vector4 operator()(float alpha, const Vector4& property) override + Vector4 operator()(float alpha, const Vector4& property) { Vector4 result(property); result.a = property.a + ((mTarget - property.a) * alpha); @@ -952,15 +861,14 @@ struct AnimateToOpacity : public AnimatorFunctionBase float mTarget; }; -struct AnimateByBoolean : public AnimatorFunctionBase +struct AnimateByBoolean { AnimateByBoolean(bool relativeValue) : mRelative(relativeValue) { } - using AnimatorFunctionBase::operator(); - bool operator()(float alpha, const bool& property) override + bool operator()(float alpha, const bool& property) { // Alpha is not useful here, just keeping to the same template as other update functors return bool(alpha >= 1.0f ? (property || mRelative) : property); @@ -969,15 +877,14 @@ struct AnimateByBoolean : public AnimatorFunctionBase bool mRelative; }; -struct AnimateToBoolean : public AnimatorFunctionBase +struct AnimateToBoolean { AnimateToBoolean(bool targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - bool operator()(float alpha, const bool& property) override + bool operator()(float alpha, const bool& property) { // Alpha is not useful here, just keeping to the same template as other update functors return bool(alpha >= 1.0f ? mTarget : property); @@ -986,18 +893,17 @@ struct AnimateToBoolean : public AnimatorFunctionBase bool mTarget; }; -struct RotateByAngleAxis : public AnimatorFunctionBase +struct RotateByAngleAxis { RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis) - : mAngleRadians( angleRadians ), + : mAngleRadians(angleRadians), mAxis(axis.x, axis.y, axis.z) { } - using AnimatorFunctionBase::operator(); - Quaternion operator()(float alpha, const Quaternion& rotation) override + Quaternion operator()(float alpha, const Quaternion& rotation) { - if (alpha > 0.0f) + if(alpha > 0.0f) { return rotation * Quaternion(mAngleRadians * alpha, mAxis); } @@ -1005,19 +911,18 @@ struct RotateByAngleAxis : public AnimatorFunctionBase return rotation; } - Radian mAngleRadians; + Radian mAngleRadians; Vector3 mAxis; }; -struct RotateToQuaternion : public AnimatorFunctionBase +struct RotateToQuaternion { RotateToQuaternion(const Quaternion& targetValue) : mTarget(targetValue) { } - using AnimatorFunctionBase::operator(); - Quaternion operator()(float alpha, const Quaternion& rotation) override + Quaternion operator()(float alpha, const Quaternion& rotation) { return Quaternion::Slerp(rotation, mTarget, alpha); } @@ -1025,187 +930,181 @@ struct RotateToQuaternion : public AnimatorFunctionBase Quaternion mTarget; }; - -struct KeyFrameBooleanFunctor : public AnimatorFunctionBase +struct KeyFrameBooleanFunctor { - KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames) - : mKeyFrames(keyFrames) + KeyFrameBooleanFunctor(KeyFrameBoolean keyFrames) + : mKeyFrames(std::move(keyFrames)) { } - using AnimatorFunctionBase::operator(); - bool operator()(float progress, const bool& property) override + bool operator()(float progress, const bool& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR); + return mKeyFrames.GetValue(progress, Dali::Animation::LINEAR); } return property; } - KeyFrameBooleanPtr mKeyFrames; + KeyFrameBoolean mKeyFrames; }; -struct KeyFrameIntegerFunctor : public AnimatorFunctionBase +struct KeyFrameIntegerFunctor { - KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation) - : mKeyFrames(keyFrames),mInterpolation(interpolation) + KeyFrameIntegerFunctor(KeyFrameInteger keyFrames, Interpolation interpolation) + : mKeyFrames(std::move(keyFrames)), + mInterpolation(interpolation) { } - using AnimatorFunctionBase::operator(); - float operator()(float progress, const int32_t& property) override + float operator()(float progress, const int32_t& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return static_cast( mKeyFrames->GetValue(progress, mInterpolation) ); + return static_cast(mKeyFrames.GetValue(progress, mInterpolation)); } - return static_cast( property ); + return static_cast(property); } - KeyFrameIntegerPtr mKeyFrames; - Interpolation mInterpolation; + KeyFrameInteger mKeyFrames; + Interpolation mInterpolation; }; -struct KeyFrameNumberFunctor : public AnimatorFunctionBase +struct KeyFrameNumberFunctor { - KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation) - : mKeyFrames(keyFrames),mInterpolation(interpolation) + KeyFrameNumberFunctor(KeyFrameNumber keyFrames, Interpolation interpolation) + : mKeyFrames(std::move(keyFrames)), + mInterpolation(interpolation) { } - using AnimatorFunctionBase::operator(); - float operator()(float progress, const float& property) override + float operator()(float progress, const float& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return mKeyFrames->GetValue(progress, mInterpolation); + return mKeyFrames.GetValue(progress, mInterpolation); } return property; } - KeyFrameNumberPtr mKeyFrames; - Interpolation mInterpolation; + KeyFrameNumber mKeyFrames; + Interpolation mInterpolation; }; -struct KeyFrameVector2Functor : public AnimatorFunctionBase +struct KeyFrameVector2Functor { - KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation) - : mKeyFrames(keyFrames),mInterpolation(interpolation) + KeyFrameVector2Functor(KeyFrameVector2 keyFrames, Interpolation interpolation) + : mKeyFrames(std::move(keyFrames)), + mInterpolation(interpolation) { } - using AnimatorFunctionBase::operator(); - Vector2 operator()(float progress, const Vector2& property) override + Vector2 operator()(float progress, const Vector2& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return mKeyFrames->GetValue(progress, mInterpolation); + return mKeyFrames.GetValue(progress, mInterpolation); } return property; } - KeyFrameVector2Ptr mKeyFrames; - Interpolation mInterpolation; + KeyFrameVector2 mKeyFrames; + Interpolation mInterpolation; }; - -struct KeyFrameVector3Functor : public AnimatorFunctionBase +struct KeyFrameVector3Functor { - KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation) - : mKeyFrames(keyFrames),mInterpolation(interpolation) + KeyFrameVector3Functor(KeyFrameVector3 keyFrames, Interpolation interpolation) + : mKeyFrames(std::move(keyFrames)), + mInterpolation(interpolation) { } - using AnimatorFunctionBase::operator(); - Vector3 operator()(float progress, const Vector3& property) override + Vector3 operator()(float progress, const Vector3& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return mKeyFrames->GetValue(progress, mInterpolation); + return mKeyFrames.GetValue(progress, mInterpolation); } return property; } - KeyFrameVector3Ptr mKeyFrames; - Interpolation mInterpolation; + KeyFrameVector3 mKeyFrames; + Interpolation mInterpolation; }; -struct KeyFrameVector4Functor : public AnimatorFunctionBase +struct KeyFrameVector4Functor { - KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation) - : mKeyFrames(keyFrames),mInterpolation(interpolation) + KeyFrameVector4Functor(KeyFrameVector4 keyFrames, Interpolation interpolation) + : mKeyFrames(std::move(keyFrames)), + mInterpolation(interpolation) { } - using AnimatorFunctionBase::operator(); - Vector4 operator()(float progress, const Vector4& property) override + Vector4 operator()(float progress, const Vector4& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return mKeyFrames->GetValue(progress, mInterpolation); + return mKeyFrames.GetValue(progress, mInterpolation); } return property; } - KeyFrameVector4Ptr mKeyFrames; - Interpolation mInterpolation; + KeyFrameVector4 mKeyFrames; + Interpolation mInterpolation; }; -struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase +struct KeyFrameQuaternionFunctor { - KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames) - : mKeyFrames(keyFrames) + KeyFrameQuaternionFunctor(KeyFrameQuaternion keyFrames) + : mKeyFrames(std::move(keyFrames)) { } - using AnimatorFunctionBase::operator(); - Quaternion operator()(float progress, const Quaternion& property) override + Quaternion operator()(float progress, const Quaternion& property) { - if(mKeyFrames->IsActive(progress)) + if(mKeyFrames.IsActive(progress)) { - return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR); + return mKeyFrames.GetValue(progress, Dali::Animation::LINEAR); } return property; } - KeyFrameQuaternionPtr mKeyFrames; + KeyFrameQuaternion mKeyFrames; }; -struct PathPositionFunctor : public AnimatorFunctionBase +struct PathPositionFunctor { - PathPositionFunctor( PathPtr path ) + PathPositionFunctor(PathPtr path) : mPath(path) { } - using AnimatorFunctionBase::operator(); - Vector3 operator()(float progress, const Vector3& property) override + Vector3 operator()(float progress, const Vector3& property) { Vector3 position(property); - static_cast( mPath->SamplePosition(progress, position) ); + static_cast(mPath->SamplePosition(progress, position)); return position; } PathPtr mPath; }; -struct PathRotationFunctor : public AnimatorFunctionBase +struct PathRotationFunctor { - PathRotationFunctor( PathPtr path, const Vector3& forward ) + PathRotationFunctor(PathPtr path, const Vector3& forward) : mPath(path), - mForward( forward ) + mForward(forward) { mForward.Normalize(); } - using AnimatorFunctionBase::operator(); - Quaternion operator()(float progress, const Quaternion& property) override + Quaternion operator()(float progress, const Quaternion& property) { Vector3 tangent; - if( mPath->SampleTangent(progress, tangent) ) + if(mPath->SampleTangent(progress, tangent)) { - return Quaternion( mForward, tangent ); + return Quaternion(mForward, tangent); } else {