2 * Copyright (c) 2014 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>
22 #include <dali/public-api/animation/alpha-functions.h>
23 #include <dali/public-api/animation/time-period.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/radian.h>
28 #include <dali/internal/event/actors/actor-impl.h>
29 #include <dali/internal/event/common/stage-impl.h>
30 #include <dali/internal/event/animation/animator-connector.h>
31 #include <dali/internal/event/animation/animation-playlist.h>
32 #include <dali/internal/event/common/notification-manager.h>
33 #include <dali/internal/update/manager/update-manager.h>
34 #include <dali/internal/event/effects/shader-effect-impl.h>
35 #include <dali/internal/event/common/thread-local-storage.h>
39 using Dali::Internal::SceneGraph::UpdateManager;
40 using Dali::Internal::SceneGraph::AnimatorBase;
41 using Dali::Internal::SceneGraph::Shader;
49 static bool SHOW_VALUE = true;
50 static bool HIDE_VALUE = false;
57 return Dali::Animation::New(0.f);
60 TypeRegistration mType( typeid(Dali::Animation), typeid(Dali::BaseHandle), Create );
62 SignalConnectorType signalConnector1( mType, Dali::Animation::SIGNAL_FINISHED, &Animation::DoConnectSignal );
64 TypeAction action1( mType, Dali::Animation::ACTION_PLAY, &Animation::DoAction );
65 TypeAction action2( mType, Dali::Animation::ACTION_STOP, &Animation::DoAction );
66 TypeAction action3( mType, Dali::Animation::ACTION_PAUSE, &Animation::DoAction );
71 AnimationPtr Animation::New(float durationSeconds)
73 return New(durationSeconds, Dali::Animation::Bake, Dali::Animation::Bake, Dali::AlphaFunctions::Linear);
76 AnimationPtr Animation::New(float durationSeconds, EndAction endAction, EndAction destroyAction)
78 return New(durationSeconds, endAction, destroyAction, Dali::AlphaFunctions::Linear);
81 AnimationPtr Animation::New(float durationSeconds, EndAction endAction, EndAction destroyAction, AlphaFunction alpha)
83 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
84 UpdateManager& updateManager = tls.GetUpdateManager();
86 AnimationPlaylist& playlist = Stage::GetCurrent()->GetAnimationPlaylist();
88 AnimationPtr progress = new Animation( updateManager, playlist, durationSeconds, endAction, destroyAction, alpha );
90 // Second-phase construction
91 progress->Initialize();
96 Animation::Animation( UpdateManager& updateManager, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction destroyAction, AlphaFunction defaultAlpha )
97 : mUpdateManager( updateManager ),
98 mPlaylist( playlist ),
100 mNotificationCount( 0 ),
101 mFinishedCallback( NULL ),
102 mFinishedCallbackObject( NULL ),
103 mDurationSeconds( durationSeconds ),
106 mPlayRange( Vector2(0.0f,1.0f)),
107 mEndAction( endAction ),
108 mDestroyAction( destroyAction ),
109 mDefaultAlpha( defaultAlpha )
113 void Animation::Initialize()
115 // Connect to the animation playlist
116 mPlaylist.AnimationCreated( *this );
123 Animation::~Animation()
125 // Guard to allow handle destruction after Core has been destroyed
126 if ( Stage::IsInstalled() )
128 // Disconnect from the animation playlist
129 mPlaylist.AnimationDestroyed( *this );
131 DestroySceneObject();
137 void Animation::CreateSceneObject()
139 DALI_ASSERT_DEBUG( mAnimation == NULL );
141 // Create a new animation, temporarily owned
142 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mIsLooping, mEndAction, mDestroyAction );
144 // Keep a const pointer to the animation.
145 mAnimation = animation;
147 // Transfer animation ownership to the update manager through a message
148 AddAnimationMessage( mUpdateManager, animation );
151 void Animation::DestroySceneObject()
153 if ( mAnimation != NULL )
155 // Remove animation using a message to the update manager
156 RemoveAnimationMessage( mUpdateManager, *mAnimation );
161 void Animation::SetDuration(float seconds)
163 // Cache for public getters
164 mDurationSeconds = seconds;
166 // mAnimation is being used in a separate thread; queue a message to set the value
167 SetDurationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, seconds );
170 float Animation::GetDuration() const
172 // This is not animatable; the cached value is up-to-date.
173 return mDurationSeconds;
176 void Animation::SetLooping(bool looping)
178 // Cache for public getters
179 mIsLooping = looping;
181 // mAnimation is being used in a separate thread; queue a message to set the value
182 SetLoopingMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, looping );
185 bool Animation::IsLooping() const
187 // This is not animatable; the cached value is up-to-date.
191 void Animation::SetEndAction(EndAction action)
193 // Cache for public getters
196 // mAnimation is being used in a separate thread; queue a message to set the value
197 SetEndActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
200 Dali::Animation::EndAction Animation::GetEndAction() const
202 // This is not animatable; the cached value is up-to-date.
206 void Animation::SetDestroyAction(EndAction action)
208 // Cache for public getters
209 mDestroyAction = action;
211 // mAnimation is being used in a separate thread; queue a message to set the value
212 SetDestroyActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
215 Dali::Animation::EndAction Animation::GetDestroyAction() const
217 // This is not animatable; the cached value is up-to-date.
218 return mDestroyAction;
221 void Animation::Play()
223 // Update the current playlist
224 mPlaylist.OnPlay( *this );
226 // mAnimation is being used in a separate thread; queue a Play message
227 PlayAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
230 void Animation::PlayFrom( float progress )
232 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
234 // Update the current playlist
235 mPlaylist.OnPlay( *this );
237 // mAnimation is being used in a separate thread; queue a Play message
238 PlayAnimationFromMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
242 void Animation::Pause()
244 // mAnimation is being used in a separate thread; queue a Pause message
245 PauseAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
248 void Animation::Stop()
250 // mAnimation is being used in a separate thread; queue a Stop message
251 StopAnimationMessage( mUpdateManager, *mAnimation );
254 void Animation::Clear()
256 DALI_ASSERT_DEBUG(mAnimation);
258 // Remove all the connectors
261 // Replace the old scene-object with a new one
262 DestroySceneObject();
265 // Reset the notification count, since the new scene-object has never been played
266 mNotificationCount = 0;
268 // Update the current playlist
269 mPlaylist.OnClear( *this );
272 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
274 AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds);
277 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
279 AnimateBy(target, relativeValue, alpha, mDurationSeconds);
282 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
284 AnimateBy(target, relativeValue, AlphaFunctions::Default, period);
287 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
289 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
291 ExtendDuration( period );
293 switch ( relativeValue.GetType() )
295 case Property::BOOLEAN:
297 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
298 target.propertyIndex,
299 target.componentIndex,
300 AnimateByBoolean(relativeValue.Get<bool>()),
306 case Property::FLOAT:
308 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
309 target.propertyIndex,
310 target.componentIndex,
311 AnimateByFloat(relativeValue.Get<float>()),
317 case Property::INTEGER:
319 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
320 target.propertyIndex,
321 target.componentIndex,
322 AnimateByInteger(relativeValue.Get<int>()),
328 case Property::VECTOR2:
330 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
331 target.propertyIndex,
332 target.componentIndex,
333 AnimateByVector2(relativeValue.Get<Vector2>()),
339 case Property::VECTOR3:
341 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
342 target.propertyIndex,
343 target.componentIndex,
344 AnimateByVector3(relativeValue.Get<Vector3>()),
350 case Property::VECTOR4:
352 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
353 target.propertyIndex,
354 target.componentIndex,
355 AnimateByVector4(relativeValue.Get<Vector4>()),
361 case Property::ROTATION:
363 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
365 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
366 target.propertyIndex,
367 target.componentIndex,
368 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
375 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
380 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
382 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
385 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
387 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
390 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
392 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
395 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
397 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
399 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
402 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
404 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
405 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
407 if( type == Property::VECTOR2
408 || type == Property::VECTOR3
409 || type == Property::VECTOR4 )
411 type = Property::FLOAT;
414 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
416 ExtendDuration( period );
418 switch (destinationValue.GetType())
420 case Property::BOOLEAN:
422 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
425 AnimateToBoolean(destinationValue.Get<bool>()),
431 case Property::FLOAT:
433 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
436 AnimateToFloat(destinationValue.Get<float>()),
442 case Property::INTEGER:
444 AddAnimatorConnector( AnimatorConnector<int>::New(targetObject,
447 AnimateToInteger(destinationValue.Get<int>()),
453 case Property::VECTOR2:
455 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
458 AnimateToVector2(destinationValue.Get<Vector2>()),
464 case Property::VECTOR3:
466 if ( Dali::Actor::SIZE == targetPropertyIndex )
468 // Test whether this is actually an Actor
469 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
472 // Notify the actor that its size is being animated
473 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
477 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
480 AnimateToVector3(destinationValue.Get<Vector3>()),
486 case Property::VECTOR4:
488 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
491 AnimateToVector4(destinationValue.Get<Vector4>()),
497 case Property::ROTATION:
499 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
502 RotateToQuaternion(destinationValue.Get<Quaternion>()),
509 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
514 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
516 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
519 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
521 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
524 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
526 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
529 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
531 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
533 ExtendDuration( period );
535 switch(keyFrames.GetType())
537 case Dali::Property::BOOLEAN:
539 const KeyFrameBoolean* kf;
540 GetSpecialization(keyFrames, kf);
541 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
542 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
543 target.propertyIndex,
544 target.componentIndex,
545 KeyFrameBooleanFunctor(kfCopy),
551 case Dali::Property::FLOAT:
553 const KeyFrameNumber* kf;
554 GetSpecialization(keyFrames, kf);
555 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
556 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
557 target.propertyIndex,
558 target.componentIndex,
559 KeyFrameNumberFunctor(kfCopy),
565 case Dali::Property::INTEGER:
567 const KeyFrameInteger* kf;
568 GetSpecialization(keyFrames, kf);
569 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
570 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
571 target.propertyIndex,
572 target.componentIndex,
573 KeyFrameIntegerFunctor(kfCopy),
579 case Dali::Property::VECTOR2:
581 const KeyFrameVector2* kf;
582 GetSpecialization(keyFrames, kf);
583 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
584 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
585 target.propertyIndex,
586 target.componentIndex,
587 KeyFrameVector2Functor(kfCopy),
593 case Dali::Property::VECTOR3:
595 const KeyFrameVector3* kf;
596 GetSpecialization(keyFrames, kf);
597 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
598 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
599 target.propertyIndex,
600 target.componentIndex,
601 KeyFrameVector3Functor(kfCopy),
607 case Dali::Property::VECTOR4:
609 const KeyFrameVector4* kf;
610 GetSpecialization(keyFrames, kf);
611 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
612 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
613 target.propertyIndex,
614 target.componentIndex,
615 KeyFrameVector4Functor(kfCopy),
621 case Dali::Property::ROTATION:
623 const KeyFrameQuaternion* kf;
624 GetSpecialization(keyFrames, kf);
625 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
626 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
627 target.propertyIndex,
628 target.componentIndex,
629 KeyFrameQuaternionFunctor(kfCopy),
635 default: // not all property types are animateable
640 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
642 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
645 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
647 Animate( target, targetType, func, alpha, mDurationSeconds );
650 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
652 Animate( target, targetType, func, mDefaultAlpha, period );
655 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
657 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
658 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
660 if( type == Property::VECTOR2
661 || type == Property::VECTOR3
662 || type == Property::VECTOR4 )
664 type = Property::FLOAT;
667 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
669 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
671 ExtendDuration( period );
673 switch ( targetType )
675 case Property::BOOLEAN:
677 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
678 target.propertyIndex,
679 target.componentIndex,
680 AnyCast< AnimatorFunctionBool >( func ),
686 case Property::FLOAT:
688 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
689 target.propertyIndex,
690 target.componentIndex,
691 AnyCast< AnimatorFunctionFloat >( func ),
697 case Property::INTEGER:
699 AddAnimatorConnector( AnimatorConnector<int>::New(proxy,
700 target.propertyIndex,
701 target.componentIndex,
702 AnyCast< AnimatorFunctionInteger >( func ),
708 case Property::VECTOR2:
710 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
711 target.propertyIndex,
712 target.componentIndex,
713 AnyCast< AnimatorFunctionVector2 >( func ),
719 case Property::VECTOR3:
721 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
722 target.propertyIndex,
723 target.componentIndex,
724 AnyCast< AnimatorFunctionVector3 >( func ),
730 case Property::VECTOR4:
732 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
733 target.propertyIndex,
734 target.componentIndex,
735 AnyCast< AnimatorFunctionVector4 >( func ),
741 case Property::ROTATION:
743 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
744 target.propertyIndex,
745 target.componentIndex,
746 AnyCast< AnimatorFunctionQuaternion >( func ),
753 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
758 bool Animation::HasFinished()
760 bool hasFinished(false);
761 const int playCount(mAnimation->GetPlayCount());
763 // If the play count has been incremented, then another notification is required
764 if (playCount > mNotificationCount)
766 // Note that only one signal is emitted, if the animation has been played repeatedly
767 mNotificationCount = playCount;
775 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
777 return mFinishedSignal;
780 void Animation::EmitSignalFinish()
782 if ( !mFinishedSignal.Empty() )
784 Dali::Animation handle( this );
785 mFinishedSignal.Emit( handle );
788 // This callback is used internally, to avoid the overhead of using a signal.
789 if ( mFinishedCallback )
791 mFinishedCallback( mFinishedCallbackObject );
795 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
797 bool connected( true );
798 Animation* animation = dynamic_cast<Animation*>(object);
800 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
802 animation->FinishedSignal().Connect( tracker, functor );
806 // signalName does not match any signal
813 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
815 mFinishedCallback = callback;
816 mFinishedCallbackObject = object;
819 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
821 DALI_ASSERT_DEBUG( NULL != connector );
823 connector->SetParent(*this);
825 mConnectors.PushBack( connector );
828 void Animation::MoveBy(Actor& actor, float x, float y, float z)
830 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
833 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
835 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
838 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
840 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
842 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
843 Dali::Actor::POSITION,
844 Property::INVALID_COMPONENT_INDEX,
845 AnimateByVector3(displacement),
847 TimePeriod(delaySeconds, durationSeconds) ) );
850 void Animation::MoveTo(Actor& actor, float x, float y, float z)
852 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
855 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
857 MoveTo(actor, position, alpha, 0.0f, GetDuration());
860 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
862 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
864 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
865 Dali::Actor::POSITION,
866 Property::INVALID_COMPONENT_INDEX,
867 AnimateToVector3(position),
869 TimePeriod(delaySeconds, durationSeconds) ) );
872 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
874 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
876 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
877 Dali::Actor::POSITION,
878 Property::INVALID_COMPONENT_INDEX,
881 TimePeriod(delaySeconds, durationSeconds) ) );
884 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
886 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
889 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
891 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
894 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
896 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
898 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
899 Dali::Actor::ROTATION,
900 Property::INVALID_COMPONENT_INDEX,
901 RotateByAngleAxis(angle, axis),
903 TimePeriod(delaySeconds, durationSeconds) ) );
906 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
908 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
909 normalizedAxis.Normalize();
911 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
913 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
916 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
918 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
921 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
923 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
924 normalizedAxis.Normalize();
926 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
928 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
931 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
933 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
936 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
938 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
939 normalizedAxis.Normalize();
941 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
943 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
946 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
948 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
950 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
951 Dali::Actor::ROTATION,
952 Property::INVALID_COMPONENT_INDEX,
953 RotateToQuaternion(rotation),
955 TimePeriod(delaySeconds, durationSeconds) ) );
958 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
960 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
962 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
963 Dali::Actor::ROTATION,
964 Property::INVALID_COMPONENT_INDEX,
967 TimePeriod(delaySeconds, durationSeconds) ) );
970 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
972 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
975 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
977 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
980 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
982 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
984 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
986 Property::INVALID_COMPONENT_INDEX,
987 AnimateByVector3(scale),
989 TimePeriod(delaySeconds, durationSeconds) ) );
992 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
994 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
997 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
999 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
1002 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1004 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1006 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1008 Property::INVALID_COMPONENT_INDEX,
1009 AnimateToVector3(scale),
1011 TimePeriod(delaySeconds, durationSeconds) ) );
1014 void Animation::Show(Actor& actor, float delaySeconds)
1016 ExtendDuration( TimePeriod(delaySeconds, 0) );
1018 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1019 Dali::Actor::VISIBLE,
1020 Property::INVALID_COMPONENT_INDEX,
1021 AnimateToBoolean(SHOW_VALUE),
1022 AlphaFunctions::Default,
1023 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1026 void Animation::Hide(Actor& actor, float delaySeconds)
1028 ExtendDuration( TimePeriod(delaySeconds, 0) );
1030 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1031 Dali::Actor::VISIBLE,
1032 Property::INVALID_COMPONENT_INDEX,
1033 AnimateToBoolean(HIDE_VALUE),
1034 AlphaFunctions::Default,
1035 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1038 void Animation::OpacityBy(Actor& actor, float opacity)
1040 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1043 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
1045 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
1048 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1050 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1052 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1054 Property::INVALID_COMPONENT_INDEX,
1055 AnimateByOpacity(opacity),
1057 TimePeriod(delaySeconds, durationSeconds) ) );
1060 void Animation::OpacityTo(Actor& actor, float opacity)
1062 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1065 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
1067 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
1070 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1072 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1074 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1076 Property::INVALID_COMPONENT_INDEX,
1077 AnimateToOpacity(opacity),
1079 TimePeriod(delaySeconds, durationSeconds) ) );
1082 void Animation::ColorBy(Actor& actor, const Vector4& color)
1084 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1087 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
1089 ColorBy(actor, color, alpha, 0.0f, GetDuration());
1092 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1094 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1096 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1098 Property::INVALID_COMPONENT_INDEX,
1099 AnimateByVector4(color),
1101 TimePeriod(delaySeconds, durationSeconds) ) );
1104 void Animation::ColorTo(Actor& actor, const Vector4& color)
1106 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1109 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1111 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1114 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1116 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1118 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1120 Property::INVALID_COMPONENT_INDEX,
1121 AnimateToVector4(color),
1123 TimePeriod(delaySeconds, durationSeconds) ) );
1126 void Animation::Resize(Actor& actor, float width, float height)
1128 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1131 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1133 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1136 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1138 Vector3 targetSize( width, height, min(width, height) );
1140 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1142 // Notify the actor impl that its size is being animated
1143 actor.NotifySizeAnimation( *this, targetSize );
1145 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1147 Property::INVALID_COMPONENT_INDEX,
1148 AnimateToVector3(targetSize),
1150 TimePeriod(delaySeconds, durationSeconds) ) );
1153 void Animation::Resize(Actor& actor, const Vector3& size)
1155 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1158 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1160 Resize(actor, size, alpha, 0.0f, GetDuration());
1163 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1165 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1167 // Notify the actor impl that its size is being animated
1168 actor.NotifySizeAnimation( *this, size );
1170 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1172 Property::INVALID_COMPONENT_INDEX,
1173 AnimateToVector3(size),
1175 TimePeriod(delaySeconds, durationSeconds) ) );
1178 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1181 Animation* animation = dynamic_cast<Animation*>(object);
1185 if(Dali::Animation::ACTION_PLAY == actionName)
1187 if(attributes.size() > 0)
1189 animation->SetDuration(attributes[0].Get<float>());
1195 else if(Dali::Animation::ACTION_STOP == actionName)
1200 else if(Dali::Animation::ACTION_PAUSE == actionName)
1210 void Animation::SetCurrentProgress(float progress)
1212 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
1214 // mAnimation is being used in a separate thread; queue a message to set the current progress
1215 SetCurrentProgressMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
1219 float Animation::GetCurrentProgress()
1223 return mAnimation->GetCurrentProgress();
1229 void Animation::ExtendDuration( const TimePeriod& timePeriod )
1231 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
1233 if( duration > mDurationSeconds )
1235 SetDuration( duration );
1239 void Animation::SetSpeedFactor( float factor )
1243 mSpeedFactor = factor;
1244 SetSpeedFactorMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, factor );
1248 float Animation::GetSpeedFactor() const
1250 return mSpeedFactor;
1253 void Animation::SetPlayRange( const Vector2& range)
1255 //Make sure the range specified is between 0.0 and 1.0
1256 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
1258 Vector2 orderedRange( range );
1259 //If the range is not in order swap values
1260 if( range.x > range.y )
1262 orderedRange = Vector2(range.y, range.x);
1265 // Cache for public getters
1266 mPlayRange = orderedRange;
1268 // mAnimation is being used in a separate thread; queue a message to set play range
1269 SetPlayRangeMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, orderedRange );
1273 Vector2 Animation::GetPlayRange() const
1279 } // namespace Internal