X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fanimation%2Fscene-graph-animation.h;h=a4e309f4de722d92b584868ab7e4b43064f9efb5;hb=35952536d36e03b9ddf5356a8844a959644bbf55;hp=4f2095eadbd40d5acfa5b18e30f1f9c34266de7c;hpb=68376524a0f3362fa7f0a52ffb005f611fdf3175;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/animation/scene-graph-animation.h b/dali/internal/update/animation/scene-graph-animation.h index 4f2095e..a4e309f 100644 --- a/dali/internal/update/animation/scene-graph-animation.h +++ b/dali/internal/update/animation/scene-graph-animation.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ -#define __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ +#ifndef DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H +#define DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -35,13 +35,6 @@ namespace Internal namespace SceneGraph { -class Animation; - -typedef OwnerContainer< Animation* > AnimationContainer; - -typedef AnimationContainer::Iterator AnimationIter; -typedef AnimationContainer::ConstIterator AnimationConstIter; - /** * Animations are used to change the properties of scene graph objects, as part of a scene * managers "update" phase. An animation is a container of Animator objects; the actual setting @@ -51,7 +44,7 @@ class Animation { public: - typedef Dali::Animation::EndAction EndAction; + using EndAction = Dali::Animation::EndAction; enum State { @@ -71,7 +64,7 @@ public: * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected. * @return A new Animation */ - static Animation* New( float durationSeconds, float speedFactor, const Vector2& playRange, int loopCount, EndAction endAction, EndAction disconnectAction ); + static Animation* New( float durationSeconds, float speedFactor, const Vector2& playRange, int32_t loopCount, EndAction endAction, EndAction disconnectAction ); /** * Virtual destructor @@ -106,7 +99,7 @@ public: return mDurationSeconds; } - /* + /** * Retrieve the current progress of the animation. * @return The current progress as a normalized value between [0,1]. */ @@ -120,7 +113,7 @@ public: return 0.0f; } - /* + /** * Sets the progress of the animation. * @param[in] The new progress as a normalized value between [0,1] */ @@ -129,6 +122,10 @@ public: mElapsedSeconds = mDurationSeconds * progress; } + /** + * Specifies a speed factor for the animation. + * @param[in] factor A value which will multiply the velocity + */ void SetSpeedFactor( float factor ) { mSpeedFactor = factor; @@ -139,7 +136,7 @@ public: * 0 is loop forever, N loop play N times * @param[in] loopCount The loop count */ - void SetLoopCount(int loopCount); + void SetLoopCount(int32_t loopCount); /** * Query whether the animation will loop. @@ -150,11 +147,11 @@ public: return mLoopCount != 1; } - /* + /** * Get the loop count * @return the loop count */ - int GetLoopCount() const + int32_t GetLoopCount() const { return mLoopCount; } @@ -204,13 +201,19 @@ public: */ 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 ); /** + * @brief Play the animation after a given delay time. + * @param[in] delaySeconds The delay time + */ + void PlayAfter( float delaySeconds ); + + /** * Pause the animation. */ void Pause(); @@ -242,7 +245,7 @@ public: * Retrive a count of the number of times the animation has been played to completion. * This can be used to emit "Finised" signals from the public-api */ - int GetPlayedCount() const + int32_t GetPlayedCount() const { return mPlayedCount; } @@ -250,12 +253,20 @@ public: /** * Get the current loop count from zero to GetLoopCount(). */ - int GetCurrentLoop() const + int32_t GetCurrentLoop() const { return mCurrentLoop; } /** + * @brief Sets the looping mode. + * + * Animation plays forwards and then restarts from the beginning or runs backwards again. + * @param[in] loopingMode True when the looping mode is AUTO_REVERSE + */ + void SetLoopingMode( bool loopingMode ); + + /** * Add a newly created animator. * Animators are automatically removed, when orphaned from an animatable scene object. * @param[in] animator The animator to add. @@ -265,15 +276,6 @@ public: void AddAnimator( OwnerPointer& animator ); /** - * Retrieve the animators from an animation. - * @return The container of animators. - */ - AnimatorContainer& GetAnimators() - { - return mAnimators; - } - - /** * This causes the animators to change the properties of objects in the scene graph. * @pre The animation is playing or paused. * @param[in] bufferIndex The buffer to update. @@ -290,7 +292,7 @@ protected: /** * Protected constructor. See New() */ - Animation( float durationSeconds, float speedFactor, const Vector2& playRange, int loopCount, EndAction endAction, EndAction disconnectAction ); + Animation( float durationSeconds, float speedFactor, const Vector2& playRange, int32_t loopCount, EndAction endAction, EndAction disconnectAction ); private: @@ -325,24 +327,28 @@ private: protected: + OwnerContainer< AnimatorBase* > mAnimators; + + Vector2 mPlayRange; + float mDurationSeconds; + float mDelaySeconds; + float mElapsedSeconds; float mSpeedFactor; + float mProgressMarker; // Progress marker to trigger a notification + + int32_t mPlayedCount; // Incremented at end of animation or completion of all loops + // Never incremented when looping forever. Event thread tracks to signal end. + int32_t mLoopCount; // N loop setting + int32_t mCurrentLoop; // Current loop number + EndAction mEndAction; EndAction mDisconnectAction; State mState; - float mElapsedSeconds; - int mPlayedCount; // Incremented at end of animation or completion of all loops - // Never incremented when looping forever. Event thread tracks to signal end. - int mLoopCount; // N loop setting - int mCurrentLoop; // Current loop number - - Vector2 mPlayRange; - float mProgressMarker; // Progress marker to trigger a notification bool mProgressReachedSignalRequired; // Flag to indicate the progress marker was hit - - AnimatorContainer mAnimators; + bool mAutoReverseEnabled; // Flag to identify that the looping mode is auto reverse. }; }; //namespace SceneGraph @@ -357,10 +363,10 @@ namespace SceneGraph inline void SetDurationMessage( EventThreadServices& eventThreadServices, const Animation& animation, float durationSeconds ) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = MessageValue1< Animation, float >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetDuration, durationSeconds ); @@ -368,22 +374,22 @@ inline void SetDurationMessage( EventThreadServices& eventThreadServices, const inline void SetProgressNotificationMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress ) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = MessageValue1< Animation, float >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetProgressNotification, progress ); } -inline void SetLoopingMessage( EventThreadServices& eventThreadServices, const Animation& animation, int loopCount ) +inline void SetLoopingMessage( EventThreadServices& eventThreadServices, const Animation& animation, int32_t loopCount ) { - typedef MessageValue1< Animation, int > LocalType; + using LocalType = MessageValue1< Animation, int32_t >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetLoopCount, loopCount ); @@ -391,10 +397,10 @@ inline void SetLoopingMessage( EventThreadServices& eventThreadServices, const A inline void SetEndActionMessage( EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action ) { - typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType; + using LocalType = MessageValue1< Animation, Dali::Animation::EndAction >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetEndAction, action ); @@ -402,10 +408,10 @@ inline void SetEndActionMessage( EventThreadServices& eventThreadServices, const inline void SetDisconnectActionMessage( EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action ) { - typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType; + using LocalType = MessageValue1< Animation, Dali::Animation::EndAction >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetDisconnectAction, action ); @@ -413,10 +419,10 @@ inline void SetDisconnectActionMessage( EventThreadServices& eventThreadServices inline void SetCurrentProgressMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress ) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = MessageValue1< Animation, float >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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 ); @@ -424,10 +430,10 @@ inline void SetCurrentProgressMessage( EventThreadServices& eventThreadServices, inline void SetSpeedFactorMessage( EventThreadServices& eventThreadServices, const Animation& animation, float factor ) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = MessageValue1< Animation, float >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetSpeedFactor, factor ); @@ -435,10 +441,10 @@ inline void SetSpeedFactorMessage( EventThreadServices& eventThreadServices, con inline void SetPlayRangeMessage( EventThreadServices& eventThreadServices, const Animation& animation, const Vector2& range ) { - typedef MessageValue1< Animation, Vector2 > LocalType; + using LocalType = MessageValue1< Animation, Vector2 >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::SetPlayRange, range ); @@ -446,10 +452,10 @@ inline void SetPlayRangeMessage( EventThreadServices& eventThreadServices, const inline void PlayAnimationMessage( EventThreadServices& eventThreadServices, const Animation& animation ) { - typedef Message< Animation > LocalType; + using LocalType = Message< Animation >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::Play ); @@ -457,10 +463,10 @@ inline void PlayAnimationMessage( EventThreadServices& eventThreadServices, cons inline void PlayAnimationFromMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress ) { - typedef MessageValue1< Animation,float > LocalType; + using LocalType = MessageValue1< Animation, float >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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 ); @@ -468,10 +474,10 @@ inline void PlayAnimationFromMessage( EventThreadServices& eventThreadServices, inline void PauseAnimationMessage( EventThreadServices& eventThreadServices, const Animation& animation ) { - typedef Message< Animation > LocalType; + using LocalType = Message< Animation >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.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::Pause ); @@ -479,16 +485,37 @@ inline void PauseAnimationMessage( EventThreadServices& eventThreadServices, con inline void AddAnimatorMessage( EventThreadServices& eventThreadServices, const Animation& animation, AnimatorBase& animator ) { - typedef MessageValue1< Animation, OwnerPointer > LocalType; + using LocalType = MessageValue1< Animation, OwnerPointer >; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value OwnerPointer parameter( &animator ); new (slot) LocalType( &animation, &Animation::AddAnimator, parameter ); } +inline void PlayAfterMessage( EventThreadServices& eventThreadServices, const Animation& animation, float delaySeconds ) +{ + using LocalType = MessageValue1< Animation, float >; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.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::PlayAfter, delaySeconds ); +} + +inline void SetLoopingModeMessage( EventThreadServices& eventThreadServices, const Animation& animation, bool loopingMode ) +{ + using LocalType = MessageValue1< Animation, bool >; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.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::SetLoopingMode, loopingMode ); +} } // namespace SceneGraph @@ -496,4 +523,4 @@ inline void AddAnimatorMessage( EventThreadServices& eventThreadServices, const } // namespace Dali -#endif // __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ +#endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H