2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/animation/animation-impl.h>
20 #include <dali/public-api/object/property-map.h>
25 #include <dali/public-api/animation/alpha-function.h>
26 #include <dali/public-api/animation/time-period.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/radian.h>
31 #include <dali/internal/event/animation/animation-playlist.h>
32 #include <dali/internal/event/animation/animator-connector.h>
33 #include <dali/internal/event/animation/path-impl.h>
34 #include <dali/internal/event/common/notification-manager.h>
35 #include <dali/internal/event/common/property-helper.h>
36 #include <dali/internal/event/common/stage-impl.h>
37 #include <dali/internal/event/common/thread-local-storage.h>
38 #include <dali/internal/update/animation/scene-graph-animator.h>
39 #include <dali/internal/update/manager/update-manager.h>
41 using Dali::Internal::SceneGraph::UpdateManager;
42 using Dali::Internal::SceneGraph::AnimatorBase;
43 using Dali::Internal::SceneGraph::Shader;
51 static bool SHOW_VALUE = true;
52 static bool HIDE_VALUE = false;
59 const char* const SIGNAL_FINISHED = "finished";
63 const char* const ACTION_PLAY = "play";
64 const char* const ACTION_STOP = "stop";
65 const char* const ACTION_PAUSE = "pause";
69 return Dali::Animation::New(0.f);
72 TypeRegistration mType( typeid( Dali::Animation ), typeid( Dali::BaseHandle ), Create );
74 SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &Animation::DoConnectSignal );
76 TypeAction action1( mType, ACTION_PLAY, &Animation::DoAction );
77 TypeAction action2( mType, ACTION_STOP, &Animation::DoAction );
78 TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction );
80 const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::BAKE );
81 const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BAKE_FINAL );
82 const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::LINEAR );
83 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
86 * Helper to tell if a property is animatable (if we have animators for it)
88 * @param type type to check
89 * @return true if animatable
91 inline bool IsAnimatable( Property::Type type )
93 bool animatable = false;
96 case Property::BOOLEAN :
97 case Property::FLOAT :
98 case Property::INTEGER :
99 case Property::VECTOR2 :
100 case Property::VECTOR3 :
101 case Property::VECTOR4 :
102 case Property::ROTATION :
107 case Property::MATRIX : // matrix is allowed as a scene graph property but there's no animators for it
108 case Property::MATRIX3 : // matrix3 is allowed as a scene graph property but there's no animators for it
109 case Property::NONE :
110 case Property::RECTANGLE :
111 case Property::STRING :
112 case Property::ARRAY :
114 case Property::EXTENTS :
123 * Helper to validate animation input values
125 * @param propertyType type of the property that is being animated
126 * @param destinationType type of the target
127 * @param period time period of the animation
129 void ValidateParameters( Property::Type propertyType, Property::Type destinationType, const TimePeriod& period )
131 // destination value has to be animatable
132 DALI_ASSERT_ALWAYS( IsAnimatable( propertyType ) && "Property type is not animatable" );
133 DALI_ASSERT_ALWAYS( IsAnimatable( destinationType ) && "Target value is not animatable" );
134 DALI_ASSERT_ALWAYS( propertyType == destinationType && "Property and target types don't match" );
135 DALI_ASSERT_ALWAYS( period.durationSeconds >= 0 && "Duration must be >=0" );
138 } // anonymous namespace
141 AnimationPtr Animation::New(float durationSeconds)
143 if( durationSeconds < 0.0f )
145 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
146 durationSeconds = 0.0f;
149 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
150 AnimationPtr animation = new Animation( tls.GetEventThreadServices(), tls.GetAnimationPlaylist(), durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
152 // Second-phase construction
153 animation->Initialize();
158 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
159 : mAnimation( nullptr ),
160 mEventThreadServices( eventThreadServices ),
161 mPlaylist( playlist ),
164 mConnectorTargetValues(),
165 mPlayRange( Vector2(0.0f,1.0f)),
166 mDurationSeconds( durationSeconds ),
168 mNotificationCount( 0 ),
171 mEndAction( endAction ),
172 mDisconnectAction( disconnectAction ),
173 mDefaultAlpha( defaultAlpha ),
174 mState(Dali::Animation::STOPPED),
175 mProgressReachedMarker( 0.0f ),
176 mDelaySeconds( 0.0f ),
177 mAutoReverseEnabled( false )
181 void Animation::Initialize()
183 // Connect to the animation playlist
184 mPlaylist.AnimationCreated( *this );
191 Animation::~Animation()
193 // Guard to allow handle destruction after Core has been destroyed
194 if ( Stage::IsInstalled() )
196 // Disconnect from the animation playlist
197 mPlaylist.AnimationDestroyed( *this );
199 DestroySceneObject();
205 void Animation::CreateSceneObject()
207 DALI_ASSERT_DEBUG( mAnimation == NULL );
209 // Create a new animation, Keep a const pointer to the animation.
210 mAnimation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction );
211 OwnerPointer< SceneGraph::Animation > transferOwnership( const_cast< SceneGraph::Animation* >( mAnimation ) );
212 AddAnimationMessage( mEventThreadServices.GetUpdateManager(), transferOwnership );
215 void Animation::DestroySceneObject()
217 if ( mAnimation != nullptr )
219 // Remove animation using a message to the update manager
220 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
221 mAnimation = nullptr;
225 void Animation::SetDuration(float seconds)
229 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
233 mDurationSeconds = seconds;
235 // mAnimation is being used in a separate thread; queue a message to set the value
236 SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
239 void Animation::SetProgressNotification( float progress )
241 // mAnimation is being used in a separate thread; queue a message to set the value
242 mProgressReachedMarker = progress;
245 float Animation::GetProgressNotification()
247 return mProgressReachedMarker;
250 float Animation::GetDuration() const
252 // This is not animatable; the cached value is up-to-date.
253 return mDurationSeconds;
256 void Animation::SetLooping(bool on)
258 SetLoopCount( on ? 0 : 1 );
261 void Animation::SetLoopCount(int32_t count)
263 // Cache for public getters
266 // mAnimation is being used in a separate thread; queue a message to set the value
267 SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
270 int32_t Animation::GetLoopCount()
275 int32_t Animation::GetCurrentLoop()
280 bool Animation::IsLooping() const
282 return mLoopCount != 1;
285 void Animation::SetEndAction(EndAction action)
287 // Cache for public getters
290 // mAnimation is being used in a separate thread; queue a message to set the value
291 SetEndActionMessage( mEventThreadServices, *mAnimation, action );
294 Dali::Animation::EndAction Animation::GetEndAction() const
296 // This is not animatable; the cached value is up-to-date.
300 void Animation::SetDisconnectAction(EndAction action)
302 // Cache for public getters
303 mDisconnectAction = action;
305 // mAnimation is being used in a separate thread; queue a message to set the value
306 SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
309 Dali::Animation::EndAction Animation::GetDisconnectAction() const
311 // This is not animatable; the cached value is up-to-date.
312 return mDisconnectAction;
315 void Animation::Play()
317 // Update the current playlist
318 mPlaylist.OnPlay( *this );
320 mState = Dali::Animation::PLAYING;
322 NotifyObjects( Notify::USE_TARGET_VALUE );
324 SendFinalProgressNotificationMessage();
326 // mAnimation is being used in a separate thread; queue a Play message
327 PlayAnimationMessage( mEventThreadServices, *mAnimation );
330 void Animation::PlayFrom( float progress )
332 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
334 // Update the current playlist
335 mPlaylist.OnPlay( *this );
337 mState = Dali::Animation::PLAYING;
339 NotifyObjects( Notify::USE_TARGET_VALUE );
341 SendFinalProgressNotificationMessage();
343 // mAnimation is being used in a separate thread; queue a Play message
344 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
348 void Animation::PlayAfter( float delaySeconds )
350 // The negative delay means play immediately.
351 delaySeconds = std::max( 0.f, delaySeconds );
353 mDelaySeconds = delaySeconds;
355 // Update the current playlist
356 mPlaylist.OnPlay( *this );
358 mState = Dali::Animation::PLAYING;
360 NotifyObjects( Notify::USE_TARGET_VALUE );
362 SendFinalProgressNotificationMessage();
364 // mAnimation is being used in a separate thread; queue a message to set the value
365 PlayAfterMessage( mEventThreadServices, *mAnimation, delaySeconds );
368 void Animation::Pause()
370 mState = Dali::Animation::PAUSED;
372 // mAnimation is being used in a separate thread; queue a Pause message
373 PauseAnimationMessage( mEventThreadServices, *mAnimation );
375 // Notify the objects with the _paused_, i.e. current values
376 NotifyObjects( Notify::FORCE_CURRENT_VALUE );
379 Dali::Animation::State Animation::GetState() const
384 void Animation::Stop()
386 mState = Dali::Animation::STOPPED;
388 // mAnimation is being used in a separate thread; queue a Stop message
389 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
391 // Only notify the objects with the _stopped_, i.e. current values if the end action is set to BAKE
392 if( mEndAction == EndAction::BAKE )
394 NotifyObjects( Notify::USE_CURRENT_VALUE );
398 void Animation::Clear()
400 DALI_ASSERT_DEBUG(mAnimation);
402 // Only notify the objects with the current values if the end action is set to BAKE
403 if( mEndAction == EndAction::BAKE )
405 NotifyObjects( Notify::USE_CURRENT_VALUE );
408 // Remove all the connectors
411 // Reset the connector target values
412 mConnectorTargetValues.clear();
414 // Replace the old scene-object with a new one
415 DestroySceneObject();
418 // Reset the notification count, since the new scene-object has never been played
419 mNotificationCount = 0;
421 // Update the current playlist
422 mPlaylist.OnClear( *this );
425 void Animation::AnimateBy(Property& target, Property::Value relativeValue)
427 AnimateBy(target, std::move(relativeValue), mDefaultAlpha, TimePeriod(mDurationSeconds));
430 void Animation::AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha)
432 AnimateBy(target, std::move(relativeValue), alpha, TimePeriod(mDurationSeconds));
435 void Animation::AnimateBy(Property& target, Property::Value relativeValue, TimePeriod period)
437 AnimateBy(target, std::move(relativeValue), mDefaultAlpha, period);
440 void Animation::AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
442 Object& object = GetImplementation(target.object);
443 const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
444 const Property::Type destinationType = relativeValue.GetType();
446 // validate animation parameters, if component index is set then use float as checked type
447 ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
448 destinationType, period );
450 ExtendDuration(period);
452 // keep the current count.
453 auto connectorIndex = mConnectors.Count();
455 // using destination type so component animation gets correct type
456 switch ( destinationType )
458 case Property::BOOLEAN:
460 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
461 target.propertyIndex,
462 target.componentIndex,
463 new AnimateByBoolean(relativeValue.Get<bool>()),
469 case Property::INTEGER:
471 AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
472 target.propertyIndex,
473 target.componentIndex,
474 new AnimateByInteger(relativeValue.Get<int32_t>()),
480 case Property::FLOAT:
482 AddAnimatorConnector( AnimatorConnector<float>::New( object,
483 target.propertyIndex,
484 target.componentIndex,
485 new AnimateByFloat(relativeValue.Get<float>()),
491 case Property::VECTOR2:
493 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
494 target.propertyIndex,
495 target.componentIndex,
496 new AnimateByVector2(relativeValue.Get<Vector2>()),
502 case Property::VECTOR3:
504 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
505 target.propertyIndex,
506 target.componentIndex,
507 new AnimateByVector3(relativeValue.Get<Vector3>()),
513 case Property::VECTOR4:
515 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
516 target.propertyIndex,
517 target.componentIndex,
518 new AnimateByVector4(relativeValue.Get<Vector4>()),
524 case Property::ROTATION:
526 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
528 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
529 target.propertyIndex,
530 target.componentIndex,
531 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
539 DALI_ASSERT_DEBUG(false && "Property not supported");
542 // Store data to later notify the object that its property is being animated
543 mConnectorTargetValues.push_back({std::move(relativeValue), period, connectorIndex, Animation::BY});
546 void Animation::AnimateTo(Property& target, Property::Value destinationValue)
548 AnimateTo(target, std::move(destinationValue), mDefaultAlpha, TimePeriod(mDurationSeconds));
551 void Animation::AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha)
553 AnimateTo(target, std::move(destinationValue), alpha, TimePeriod(mDurationSeconds));
556 void Animation::AnimateTo(Property& target, Property::Value destinationValue, TimePeriod period)
558 AnimateTo(target, std::move(destinationValue), mDefaultAlpha, period);
561 void Animation::AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
563 Object& object = GetImplementation( target.object );
564 const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
565 const Property::Type destinationType = destinationValue.GetType();
567 // validate animation parameters, if component index is set then use float as checked type
568 ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
569 destinationType, period );
571 ExtendDuration( period );
573 // keep the current count.
574 auto connectorIndex = mConnectors.Count();
576 // using destination type so component animation gets correct type
577 switch ( destinationType )
579 case Property::BOOLEAN:
581 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
582 target.propertyIndex,
583 target.componentIndex,
584 new AnimateToBoolean( destinationValue.Get<bool>() ),
590 case Property::INTEGER:
592 AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
593 target.propertyIndex,
594 target.componentIndex,
595 new AnimateToInteger( destinationValue.Get<int32_t>() ),
601 case Property::FLOAT:
603 AddAnimatorConnector( AnimatorConnector<float>::New( object,
604 target.propertyIndex,
605 target.componentIndex,
606 new AnimateToFloat( destinationValue.Get<float>() ),
612 case Property::VECTOR2:
614 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
615 target.propertyIndex,
616 target.componentIndex,
617 new AnimateToVector2( destinationValue.Get<Vector2>() ),
623 case Property::VECTOR3:
625 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
626 target.propertyIndex,
627 target.componentIndex,
628 new AnimateToVector3( destinationValue.Get<Vector3>() ),
634 case Property::VECTOR4:
636 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
637 target.propertyIndex,
638 target.componentIndex,
639 new AnimateToVector4( destinationValue.Get<Vector4>() ),
645 case Property::ROTATION:
647 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
648 target.propertyIndex,
649 target.componentIndex,
650 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
658 DALI_ASSERT_DEBUG(false && "Property not supported");
661 // Store data to later notify the object that its property is being animated
662 mConnectorTargetValues.push_back({std::move(destinationValue), period, connectorIndex, Animation::TO});
665 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames )
667 AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
670 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, Interpolation interpolation )
672 AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
675 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period )
677 AnimateBetween( target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION );
680 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation )
682 AnimateBetween( target, keyFrames, mDefaultAlpha, period, interpolation );
685 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha )
687 AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
690 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation )
692 AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation );
695 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period )
697 AnimateBetween( target, keyFrames, alpha, period, DEFAULT_INTERPOLATION );
700 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
702 Object& object = GetImplementation( target.object );
703 const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
704 const Property::Type destinationType = keyFrames.GetType();
706 // validate animation parameters, if component index is set then use float as checked type
707 ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
708 destinationType, period );
710 ExtendDuration( period );
712 // Store data to later notify the object that its property is being animated
713 mConnectorTargetValues.push_back({keyFrames.GetLastKeyFrameValue(), period, mConnectors.Count(), BETWEEN});
715 // using destination type so component animation gets correct type
716 switch( destinationType )
718 case Dali::Property::BOOLEAN:
720 const KeyFrameBoolean* kf;
721 GetSpecialization(keyFrames, kf);
722 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
723 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
724 target.propertyIndex,
725 target.componentIndex,
726 new KeyFrameBooleanFunctor(kfCopy),
732 case Dali::Property::INTEGER:
734 const KeyFrameInteger* kf;
735 GetSpecialization(keyFrames, kf);
736 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
737 AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
738 target.propertyIndex,
739 target.componentIndex,
740 new KeyFrameIntegerFunctor(kfCopy,interpolation),
746 case Dali::Property::FLOAT:
748 const KeyFrameNumber* kf;
749 GetSpecialization(keyFrames, kf);
750 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
751 AddAnimatorConnector( AnimatorConnector<float>::New( object,
752 target.propertyIndex,
753 target.componentIndex,
754 new KeyFrameNumberFunctor(kfCopy,interpolation),
760 case Dali::Property::VECTOR2:
762 const KeyFrameVector2* kf;
763 GetSpecialization(keyFrames, kf);
764 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
765 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
766 target.propertyIndex,
767 target.componentIndex,
768 new KeyFrameVector2Functor(kfCopy,interpolation),
774 case Dali::Property::VECTOR3:
776 const KeyFrameVector3* kf;
777 GetSpecialization(keyFrames, kf);
778 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
779 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
780 target.propertyIndex,
781 target.componentIndex,
782 new KeyFrameVector3Functor(kfCopy,interpolation),
788 case Dali::Property::VECTOR4:
790 const KeyFrameVector4* kf;
791 GetSpecialization(keyFrames, kf);
792 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
793 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
794 target.propertyIndex,
795 target.componentIndex,
796 new KeyFrameVector4Functor(kfCopy,interpolation),
802 case Dali::Property::ROTATION:
804 const KeyFrameQuaternion* kf;
805 GetSpecialization(keyFrames, kf);
806 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
807 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
808 target.propertyIndex,
809 target.componentIndex,
810 new KeyFrameQuaternionFunctor(kfCopy),
818 DALI_ASSERT_DEBUG(false && "Property not supported");
823 bool Animation::HasFinished()
825 bool hasFinished(false);
826 const int32_t playedCount(mAnimation->GetPlayedCount());
828 // If the play count has been incremented, then another notification is required
829 mCurrentLoop = mAnimation->GetCurrentLoop();
831 if (playedCount > mNotificationCount)
833 // Note that only one signal is emitted, if the animation has been played repeatedly
834 mNotificationCount = playedCount;
838 mState = Dali::Animation::STOPPED;
844 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
846 return mFinishedSignal;
849 Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal()
851 return mProgressReachedSignal;
854 void Animation::EmitSignalFinish()
856 if ( !mFinishedSignal.Empty() )
858 Dali::Animation handle( this );
859 mFinishedSignal.Emit( handle );
863 void Animation::EmitSignalProgressReached()
865 if ( !mProgressReachedSignal.Empty() )
867 Dali::Animation handle( this );
868 mProgressReachedSignal.Emit( handle );
872 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
874 bool connected( false );
875 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
877 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
879 animation->FinishedSignal().Connect( tracker, functor );
886 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
888 DALI_ASSERT_DEBUG( NULL != connector );
890 connector->SetParent(*this);
892 mConnectors.PushBack( connector );
895 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
897 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
900 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
902 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
905 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
907 Animate( actor, path, forward, mDefaultAlpha, period );
910 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
912 ExtendDuration( period );
914 PathPtr pathCopy = Path::Clone(path);
917 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
918 Dali::Actor::Property::POSITION,
919 Property::INVALID_COMPONENT_INDEX,
920 new PathPositionFunctor( pathCopy ),
924 //If forward is zero, PathRotationFunctor will always return the unit quaternion
925 if( forward != Vector3::ZERO )
928 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
929 Dali::Actor::Property::ORIENTATION,
930 Property::INVALID_COMPONENT_INDEX,
931 new PathRotationFunctor( pathCopy, forward ),
937 void Animation::Show(Actor& actor, float delaySeconds)
939 ExtendDuration( TimePeriod(delaySeconds, 0) );
941 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
942 Dali::Actor::Property::VISIBLE,
943 Property::INVALID_COMPONENT_INDEX,
944 new AnimateToBoolean(SHOW_VALUE),
946 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
949 void Animation::Hide(Actor& actor, float delaySeconds)
951 ExtendDuration( TimePeriod(delaySeconds, 0) );
953 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
954 Dali::Actor::Property::VISIBLE,
955 Property::INVALID_COMPONENT_INDEX,
956 new AnimateToBoolean(HIDE_VALUE),
958 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
961 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
964 Animation* animation = dynamic_cast<Animation*>( object );
968 if( 0 == actionName.compare( ACTION_PLAY ) )
970 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
972 animation->SetDuration( value->Get<float>() );
978 else if( 0 == actionName.compare( ACTION_STOP ) )
983 else if( 0 == actionName.compare( ACTION_PAUSE ) )
993 void Animation::SetCurrentProgress(float progress)
995 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
997 // mAnimation is being used in a separate thread; queue a message to set the current progress
998 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
1002 float Animation::GetCurrentProgress()
1004 float progress = 0.f;
1005 if( mAnimation ) // always exists in practice
1007 progress = mAnimation->GetCurrentProgress();
1013 void Animation::ExtendDuration( const TimePeriod& timePeriod )
1015 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
1017 if( duration > mDurationSeconds )
1019 SetDuration( duration );
1023 void Animation::SetSpeedFactor( float factor )
1027 mSpeedFactor = factor;
1028 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
1032 float Animation::GetSpeedFactor() const
1034 return mSpeedFactor;
1037 void Animation::SetPlayRange( const Vector2& range)
1039 //Make sure the range specified is between 0.0 and 1.0
1040 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
1042 Vector2 orderedRange( range );
1043 //If the range is not in order swap values
1044 if( range.x > range.y )
1046 orderedRange = Vector2(range.y, range.x);
1049 // Cache for public getters
1050 mPlayRange = orderedRange;
1052 // mAnimation is being used in a separate thread; queue a message to set play range
1053 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
1057 Vector2 Animation::GetPlayRange() const
1062 void Animation::SetLoopingMode( Dali::Animation::LoopingMode loopingMode )
1064 mAutoReverseEnabled = ( loopingMode == Dali::Animation::LoopingMode::AUTO_REVERSE );
1066 // mAnimation is being used in a separate thread; queue a message to set play range
1067 SetLoopingModeMessage( mEventThreadServices, *mAnimation, mAutoReverseEnabled );
1070 Dali::Animation::LoopingMode Animation::GetLoopingMode() const
1072 return mAutoReverseEnabled ? Dali::Animation::AUTO_REVERSE : Dali::Animation::RESTART;
1075 bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
1077 return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
1080 void Animation::NotifyObjects( Animation::Notify notifyValueType )
1082 // If the animation is discarded, then we do not want to change the target values unless we want to force the current values
1083 if( mEndAction != EndAction::DISCARD || notifyValueType == Notify::FORCE_CURRENT_VALUE )
1085 // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
1086 // Only do this if we're using the target value
1087 if( notifyValueType == Notify::USE_TARGET_VALUE )
1089 std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
1092 // Loop through all connector target values sorted by increasing end time
1093 ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
1094 const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
1095 for( ; iter != endIter; ++iter )
1097 AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
1099 Object* object = connector->GetObject();
1100 if(object && object->IsAnimationPossible())
1102 const auto propertyIndex = connector->GetPropertyIndex();
1103 object->NotifyPropertyAnimation(
1106 ( notifyValueType == Notify::USE_TARGET_VALUE ) ? iter->targetValue : object->GetCurrentProperty( propertyIndex ),
1107 ( notifyValueType == Notify::USE_TARGET_VALUE ) ? iter->animatorType : Animation::TO ); // If we're setting the current value, then use TO as we want to set, not adjust, the current value
1114 void Animation::SendFinalProgressNotificationMessage()
1116 if ( mProgressReachedMarker > 0.0f )
1118 float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker;
1119 SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds );
1123 } // namespace Internal