2 * Copyright (c) 2018 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::BakeFinal );
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( NULL ),
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 != NULL )
219 // Remove animation using a message to the update manager
220 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
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;
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;
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;
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 );
376 Dali::Animation::State Animation::GetState() const
381 void Animation::Stop()
383 mState = Dali::Animation::STOPPED;
385 // mAnimation is being used in a separate thread; queue a Stop message
386 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
389 void Animation::Clear()
391 DALI_ASSERT_DEBUG(mAnimation);
393 // Remove all the connectors
396 // Reset the connector target values
397 mConnectorTargetValues.clear();
399 // Replace the old scene-object with a new one
400 DestroySceneObject();
403 // Reset the notification count, since the new scene-object has never been played
404 mNotificationCount = 0;
406 // Update the current playlist
407 mPlaylist.OnClear( *this );
410 void Animation::AnimateBy( Property& target, Property::Value& relativeValue )
412 AnimateBy( target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds) );
415 void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha )
417 AnimateBy( target, relativeValue, alpha, TimePeriod(mDurationSeconds) );
420 void Animation::AnimateBy( Property& target, Property::Value& relativeValue, TimePeriod period )
422 AnimateBy( target, relativeValue, mDefaultAlpha, period );
425 void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period )
427 Object& object = GetImplementation(target.object);
428 const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
429 const Property::Type destinationType = relativeValue.GetType();
431 // validate animation parameters, if component index is set then use float as checked type
432 ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
433 destinationType, period );
435 ExtendDuration(period);
437 // Store data to later notify the object that its property is being animated
438 ConnectorTargetValues connectorPair;
439 connectorPair.targetValue = relativeValue;
440 connectorPair.connectorIndex = mConnectors.Count();
441 connectorPair.timePeriod = period;
442 connectorPair.animatorType = Animation::BY;
443 mConnectorTargetValues.push_back( connectorPair );
445 // using destination type so component animation gets correct type
446 switch ( destinationType )
448 case Property::BOOLEAN:
450 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
451 target.propertyIndex,
452 target.componentIndex,
453 new AnimateByBoolean(relativeValue.Get<bool>()),
459 case Property::INTEGER:
461 AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
462 target.propertyIndex,
463 target.componentIndex,
464 new AnimateByInteger(relativeValue.Get<int32_t>()),
470 case Property::FLOAT:
472 AddAnimatorConnector( AnimatorConnector<float>::New( object,
473 target.propertyIndex,
474 target.componentIndex,
475 new AnimateByFloat(relativeValue.Get<float>()),
481 case Property::VECTOR2:
483 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
484 target.propertyIndex,
485 target.componentIndex,
486 new AnimateByVector2(relativeValue.Get<Vector2>()),
492 case Property::VECTOR3:
494 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
495 target.propertyIndex,
496 target.componentIndex,
497 new AnimateByVector3(relativeValue.Get<Vector3>()),
503 case Property::VECTOR4:
505 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
506 target.propertyIndex,
507 target.componentIndex,
508 new AnimateByVector4(relativeValue.Get<Vector4>()),
514 case Property::ROTATION:
516 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
518 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
519 target.propertyIndex,
520 target.componentIndex,
521 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
529 // non animatable types handled already
534 void Animation::AnimateTo( Property& target, Property::Value& destinationValue )
536 AnimateTo( target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds) );
539 void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha )
541 AnimateTo( target, destinationValue, alpha, TimePeriod(mDurationSeconds));
544 void Animation::AnimateTo( Property& target, Property::Value& destinationValue, TimePeriod period )
546 AnimateTo( target, destinationValue, mDefaultAlpha, period );
549 void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period )
551 Object& object = GetImplementation( target.object );
552 const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
553 const Property::Type destinationType = destinationValue.GetType();
555 // validate animation parameters, if component index is set then use float as checked type
556 ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
557 destinationType, period );
559 ExtendDuration( period );
561 // Store data to later notify the object that its property is being animated
562 ConnectorTargetValues connectorPair;
563 connectorPair.targetValue = destinationValue;
564 connectorPair.connectorIndex = mConnectors.Count();
565 connectorPair.timePeriod = period;
566 connectorPair.animatorType = Animation::TO;
567 mConnectorTargetValues.push_back( connectorPair );
569 // using destination type so component animation gets correct type
570 switch ( destinationType )
572 case Property::BOOLEAN:
574 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
575 target.propertyIndex,
576 target.componentIndex,
577 new AnimateToBoolean( destinationValue.Get<bool>() ),
583 case Property::INTEGER:
585 AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
586 target.propertyIndex,
587 target.componentIndex,
588 new AnimateToInteger( destinationValue.Get<int32_t>() ),
594 case Property::FLOAT:
596 AddAnimatorConnector( AnimatorConnector<float>::New( object,
597 target.propertyIndex,
598 target.componentIndex,
599 new AnimateToFloat( destinationValue.Get<float>() ),
605 case Property::VECTOR2:
607 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
608 target.propertyIndex,
609 target.componentIndex,
610 new AnimateToVector2( destinationValue.Get<Vector2>() ),
616 case Property::VECTOR3:
618 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
619 target.propertyIndex,
620 target.componentIndex,
621 new AnimateToVector3( destinationValue.Get<Vector3>() ),
627 case Property::VECTOR4:
629 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
630 target.propertyIndex,
631 target.componentIndex,
632 new AnimateToVector4( destinationValue.Get<Vector4>() ),
638 case Property::ROTATION:
640 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
641 target.propertyIndex,
642 target.componentIndex,
643 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
651 // non animatable types handled already
656 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames )
658 AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
661 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, Interpolation interpolation )
663 AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
666 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period )
668 AnimateBetween( target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION );
671 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation )
673 AnimateBetween( target, keyFrames, mDefaultAlpha, period, interpolation );
676 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha )
678 AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
681 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation )
683 AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation );
686 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period )
688 AnimateBetween( target, keyFrames, alpha, period, DEFAULT_INTERPOLATION );
691 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation )
693 Object& object = GetImplementation( target.object );
694 const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
695 const Property::Type destinationType = keyFrames.GetType();
697 // validate animation parameters, if component index is set then use float as checked type
698 ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT,
699 destinationType, period );
701 ExtendDuration( period );
703 // Store data to later notify the object that its property is being animated
704 ConnectorTargetValues connectorPair;
705 connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
706 connectorPair.connectorIndex = mConnectors.Count();
707 connectorPair.timePeriod = period;
708 connectorPair.animatorType = BETWEEN;
709 mConnectorTargetValues.push_back( connectorPair );
711 // using destination type so component animation gets correct type
712 switch( destinationType )
714 case Dali::Property::BOOLEAN:
716 const KeyFrameBoolean* kf;
717 GetSpecialization(keyFrames, kf);
718 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
719 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
720 target.propertyIndex,
721 target.componentIndex,
722 new KeyFrameBooleanFunctor(kfCopy),
728 case Dali::Property::INTEGER:
730 const KeyFrameInteger* kf;
731 GetSpecialization(keyFrames, kf);
732 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
733 AddAnimatorConnector( AnimatorConnector<int32_t>::New( object,
734 target.propertyIndex,
735 target.componentIndex,
736 new KeyFrameIntegerFunctor(kfCopy,interpolation),
742 case Dali::Property::FLOAT:
744 const KeyFrameNumber* kf;
745 GetSpecialization(keyFrames, kf);
746 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
747 AddAnimatorConnector( AnimatorConnector<float>::New( object,
748 target.propertyIndex,
749 target.componentIndex,
750 new KeyFrameNumberFunctor(kfCopy,interpolation),
756 case Dali::Property::VECTOR2:
758 const KeyFrameVector2* kf;
759 GetSpecialization(keyFrames, kf);
760 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
761 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
762 target.propertyIndex,
763 target.componentIndex,
764 new KeyFrameVector2Functor(kfCopy,interpolation),
770 case Dali::Property::VECTOR3:
772 const KeyFrameVector3* kf;
773 GetSpecialization(keyFrames, kf);
774 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
775 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
776 target.propertyIndex,
777 target.componentIndex,
778 new KeyFrameVector3Functor(kfCopy,interpolation),
784 case Dali::Property::VECTOR4:
786 const KeyFrameVector4* kf;
787 GetSpecialization(keyFrames, kf);
788 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
789 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
790 target.propertyIndex,
791 target.componentIndex,
792 new KeyFrameVector4Functor(kfCopy,interpolation),
798 case Dali::Property::ROTATION:
800 const KeyFrameQuaternion* kf;
801 GetSpecialization(keyFrames, kf);
802 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
803 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
804 target.propertyIndex,
805 target.componentIndex,
806 new KeyFrameQuaternionFunctor(kfCopy),
814 // non animatable types handled by keyframes
819 bool Animation::HasFinished()
821 bool hasFinished(false);
822 const int32_t playedCount(mAnimation->GetPlayedCount());
824 // If the play count has been incremented, then another notification is required
825 mCurrentLoop = mAnimation->GetCurrentLoop();
827 if (playedCount > mNotificationCount)
829 // Note that only one signal is emitted, if the animation has been played repeatedly
830 mNotificationCount = playedCount;
834 mState = Dali::Animation::STOPPED;
840 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
842 return mFinishedSignal;
845 Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal()
847 return mProgressReachedSignal;
850 void Animation::EmitSignalFinish()
852 if ( !mFinishedSignal.Empty() )
854 Dali::Animation handle( this );
855 mFinishedSignal.Emit( handle );
859 void Animation::EmitSignalProgressReached()
861 if ( !mProgressReachedSignal.Empty() )
863 Dali::Animation handle( this );
864 mProgressReachedSignal.Emit( handle );
868 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
870 bool connected( false );
871 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
873 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
875 animation->FinishedSignal().Connect( tracker, functor );
882 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
884 DALI_ASSERT_DEBUG( NULL != connector );
886 connector->SetParent(*this);
888 mConnectors.PushBack( connector );
891 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
893 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
896 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
898 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
901 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
903 Animate( actor, path, forward, mDefaultAlpha, period );
906 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
908 ExtendDuration( period );
910 PathPtr pathCopy = Path::Clone(path);
913 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
914 Dali::Actor::Property::POSITION,
915 Property::INVALID_COMPONENT_INDEX,
916 new PathPositionFunctor( pathCopy ),
920 //If forward is zero, PathRotationFunctor will always return the unit quaternion
921 if( forward != Vector3::ZERO )
924 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
925 Dali::Actor::Property::ORIENTATION,
926 Property::INVALID_COMPONENT_INDEX,
927 new PathRotationFunctor( pathCopy, forward ),
933 void Animation::Show(Actor& actor, float delaySeconds)
935 ExtendDuration( TimePeriod(delaySeconds, 0) );
937 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
938 Dali::Actor::Property::VISIBLE,
939 Property::INVALID_COMPONENT_INDEX,
940 new AnimateToBoolean(SHOW_VALUE),
942 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
945 void Animation::Hide(Actor& actor, float delaySeconds)
947 ExtendDuration( TimePeriod(delaySeconds, 0) );
949 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
950 Dali::Actor::Property::VISIBLE,
951 Property::INVALID_COMPONENT_INDEX,
952 new AnimateToBoolean(HIDE_VALUE),
954 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
957 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
960 Animation* animation = dynamic_cast<Animation*>( object );
964 if( 0 == actionName.compare( ACTION_PLAY ) )
966 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
968 animation->SetDuration( value->Get<float>() );
974 else if( 0 == actionName.compare( ACTION_STOP ) )
979 else if( 0 == actionName.compare( ACTION_PAUSE ) )
989 void Animation::SetCurrentProgress(float progress)
991 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
993 // mAnimation is being used in a separate thread; queue a message to set the current progress
994 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
998 float Animation::GetCurrentProgress()
1000 float progress = 0.f;
1001 if( mAnimation ) // always exists in practice
1003 progress = mAnimation->GetCurrentProgress();
1009 void Animation::ExtendDuration( const TimePeriod& timePeriod )
1011 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
1013 if( duration > mDurationSeconds )
1015 SetDuration( duration );
1019 void Animation::SetSpeedFactor( float factor )
1023 mSpeedFactor = factor;
1024 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
1028 float Animation::GetSpeedFactor() const
1030 return mSpeedFactor;
1033 void Animation::SetPlayRange( const Vector2& range)
1035 //Make sure the range specified is between 0.0 and 1.0
1036 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
1038 Vector2 orderedRange( range );
1039 //If the range is not in order swap values
1040 if( range.x > range.y )
1042 orderedRange = Vector2(range.y, range.x);
1045 // Cache for public getters
1046 mPlayRange = orderedRange;
1048 // mAnimation is being used in a separate thread; queue a message to set play range
1049 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
1053 Vector2 Animation::GetPlayRange() const
1058 void Animation::SetLoopingMode( Dali::Animation::LoopingMode loopingMode )
1060 mAutoReverseEnabled = ( loopingMode == Dali::Animation::LoopingMode::AUTO_REVERSE );
1062 // mAnimation is being used in a separate thread; queue a message to set play range
1063 SetLoopingModeMessage( mEventThreadServices, *mAnimation, mAutoReverseEnabled );
1066 Dali::Animation::LoopingMode Animation::GetLoopingMode() const
1068 return mAutoReverseEnabled ? Dali::Animation::AUTO_REVERSE : Dali::Animation::RESTART;
1071 bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
1073 return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
1076 void Animation::NotifyObjects()
1078 if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
1080 // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
1081 std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
1083 // Loop through all connector target values sorted by increasing end time
1084 ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
1085 const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
1086 for( ; iter != endIter; ++iter )
1088 AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
1090 Object* object = connector->GetObject();
1093 object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType );
1100 void Animation::SendFinalProgressNotificationMessage()
1102 if ( mProgressReachedMarker > 0.0f )
1104 float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker;
1105 SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds );
1109 } // namespace Internal