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 mEndAction( endAction ),
107 mDestroyAction( destroyAction ),
108 mDefaultAlpha( defaultAlpha )
112 void Animation::Initialize()
114 // Connect to the animation playlist
115 mPlaylist.AnimationCreated( *this );
122 Animation::~Animation()
124 // Guard to allow handle destruction after Core has been destroyed
125 if ( Stage::IsInstalled() )
127 // Disconnect from the animation playlist
128 mPlaylist.AnimationDestroyed( *this );
130 DestroySceneObject();
136 void Animation::CreateSceneObject()
138 DALI_ASSERT_DEBUG( mAnimation == NULL );
140 // Create a new animation, temporarily owned
141 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mIsLooping, mEndAction, mDestroyAction );
143 // Keep a const pointer to the animation.
144 mAnimation = animation;
146 // Transfer animation ownership to the update manager through a message
147 AddAnimationMessage( mUpdateManager, animation );
150 void Animation::DestroySceneObject()
152 if ( mAnimation != NULL )
154 // Remove animation using a message to the update manager
155 RemoveAnimationMessage( mUpdateManager, *mAnimation );
160 void Animation::SetDuration(float seconds)
162 // Cache for public getters
163 mDurationSeconds = seconds;
165 // mAnimation is being used in a separate thread; queue a message to set the value
166 SetDurationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, seconds );
169 float Animation::GetDuration() const
171 // This is not animatable; the cached value is up-to-date.
172 return mDurationSeconds;
175 void Animation::SetLooping(bool looping)
177 // Cache for public getters
178 mIsLooping = looping;
180 // mAnimation is being used in a separate thread; queue a message to set the value
181 SetLoopingMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, looping );
184 bool Animation::IsLooping() const
186 // This is not animatable; the cached value is up-to-date.
190 void Animation::SetEndAction(EndAction action)
192 // Cache for public getters
195 // mAnimation is being used in a separate thread; queue a message to set the value
196 SetEndActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
199 Dali::Animation::EndAction Animation::GetEndAction() const
201 // This is not animatable; the cached value is up-to-date.
205 void Animation::SetDestroyAction(EndAction action)
207 // Cache for public getters
208 mDestroyAction = action;
210 // mAnimation is being used in a separate thread; queue a message to set the value
211 SetDestroyActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
214 Dali::Animation::EndAction Animation::GetDestroyAction() const
216 // This is not animatable; the cached value is up-to-date.
217 return mDestroyAction;
220 void Animation::Play()
222 // Update the current playlist
223 mPlaylist.OnPlay( *this );
225 // mAnimation is being used in a separate thread; queue a Play message
226 PlayAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
229 void Animation::PlayFrom( float progress )
231 if( progress >= 0.0f && progress <= 1.0f )
233 // Update the current playlist
234 mPlaylist.OnPlay( *this );
236 // mAnimation is being used in a separate thread; queue a Play message
237 PlayAnimationFromMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
241 void Animation::Pause()
243 // mAnimation is being used in a separate thread; queue a Pause message
244 PauseAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
247 void Animation::Stop()
249 // mAnimation is being used in a separate thread; queue a Stop message
250 StopAnimationMessage( mUpdateManager, *mAnimation );
253 void Animation::Clear()
255 DALI_ASSERT_DEBUG(mAnimation);
257 // Remove all the connectors
260 // Replace the old scene-object with a new one
261 DestroySceneObject();
264 // Reset the notification count, since the new scene-object has never been played
265 mNotificationCount = 0;
267 // Update the current playlist
268 mPlaylist.OnClear( *this );
271 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
273 AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds);
276 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
278 AnimateBy(target, relativeValue, alpha, mDurationSeconds);
281 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
283 AnimateBy(target, relativeValue, AlphaFunctions::Default, period);
286 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
288 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
290 ExtendDuration( period );
292 switch ( relativeValue.GetType() )
294 case Property::BOOLEAN:
296 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
297 target.propertyIndex,
298 target.componentIndex,
299 AnimateByBoolean(relativeValue.Get<bool>()),
305 case Property::FLOAT:
307 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
308 target.propertyIndex,
309 target.componentIndex,
310 AnimateByFloat(relativeValue.Get<float>()),
316 case Property::INTEGER:
318 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
319 target.propertyIndex,
320 target.componentIndex,
321 AnimateByInteger(relativeValue.Get<int>()),
327 case Property::VECTOR2:
329 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
330 target.propertyIndex,
331 target.componentIndex,
332 AnimateByVector2(relativeValue.Get<Vector2>()),
338 case Property::VECTOR3:
340 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
341 target.propertyIndex,
342 target.componentIndex,
343 AnimateByVector3(relativeValue.Get<Vector3>()),
349 case Property::VECTOR4:
351 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
352 target.propertyIndex,
353 target.componentIndex,
354 AnimateByVector4(relativeValue.Get<Vector4>()),
360 case Property::ROTATION:
362 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
364 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
365 target.propertyIndex,
366 target.componentIndex,
367 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
374 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
379 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
381 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
384 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
386 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
389 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
391 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
394 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
396 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
398 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
401 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
403 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
404 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
406 if( type == Property::VECTOR2
407 || type == Property::VECTOR3
408 || type == Property::VECTOR4 )
410 type = Property::FLOAT;
413 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
415 ExtendDuration( period );
417 switch (destinationValue.GetType())
419 case Property::BOOLEAN:
421 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
424 AnimateToBoolean(destinationValue.Get<bool>()),
430 case Property::FLOAT:
432 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
435 AnimateToFloat(destinationValue.Get<float>()),
441 case Property::INTEGER:
443 AddAnimatorConnector( AnimatorConnector<int>::New(targetObject,
446 AnimateToInteger(destinationValue.Get<int>()),
452 case Property::VECTOR2:
454 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
457 AnimateToVector2(destinationValue.Get<Vector2>()),
463 case Property::VECTOR3:
465 if ( Dali::Actor::SIZE == targetPropertyIndex )
467 // Test whether this is actually an Actor
468 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
471 // Notify the actor that its size is being animated
472 maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
476 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
479 AnimateToVector3(destinationValue.Get<Vector3>()),
485 case Property::VECTOR4:
487 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
490 AnimateToVector4(destinationValue.Get<Vector4>()),
496 case Property::ROTATION:
498 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
501 RotateToQuaternion(destinationValue.Get<Quaternion>()),
508 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
513 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
515 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
518 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
520 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
523 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
525 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
528 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
530 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
532 ExtendDuration( period );
534 switch(keyFrames.GetType())
536 case Dali::Property::BOOLEAN:
538 const KeyFrameBoolean* kf;
539 GetSpecialization(keyFrames, kf);
540 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
541 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
542 target.propertyIndex,
543 target.componentIndex,
544 KeyFrameBooleanFunctor(kfCopy),
550 case Dali::Property::FLOAT:
552 const KeyFrameNumber* kf;
553 GetSpecialization(keyFrames, kf);
554 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
555 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
556 target.propertyIndex,
557 target.componentIndex,
558 KeyFrameNumberFunctor(kfCopy),
564 case Dali::Property::INTEGER:
566 const KeyFrameInteger* kf;
567 GetSpecialization(keyFrames, kf);
568 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
569 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
570 target.propertyIndex,
571 target.componentIndex,
572 KeyFrameIntegerFunctor(kfCopy),
578 case Dali::Property::VECTOR2:
580 const KeyFrameVector2* kf;
581 GetSpecialization(keyFrames, kf);
582 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
583 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
584 target.propertyIndex,
585 target.componentIndex,
586 KeyFrameVector2Functor(kfCopy),
592 case Dali::Property::VECTOR3:
594 const KeyFrameVector3* kf;
595 GetSpecialization(keyFrames, kf);
596 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
597 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
598 target.propertyIndex,
599 target.componentIndex,
600 KeyFrameVector3Functor(kfCopy),
606 case Dali::Property::VECTOR4:
608 const KeyFrameVector4* kf;
609 GetSpecialization(keyFrames, kf);
610 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
611 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
612 target.propertyIndex,
613 target.componentIndex,
614 KeyFrameVector4Functor(kfCopy),
620 case Dali::Property::ROTATION:
622 const KeyFrameQuaternion* kf;
623 GetSpecialization(keyFrames, kf);
624 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
625 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
626 target.propertyIndex,
627 target.componentIndex,
628 KeyFrameQuaternionFunctor(kfCopy),
634 default: // not all property types are animateable
639 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
641 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
644 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
646 Animate( target, targetType, func, alpha, mDurationSeconds );
649 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
651 Animate( target, targetType, func, mDefaultAlpha, period );
654 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
656 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
657 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
659 if( type == Property::VECTOR2
660 || type == Property::VECTOR3
661 || type == Property::VECTOR4 )
663 type = Property::FLOAT;
666 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
668 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
670 ExtendDuration( period );
672 switch ( targetType )
674 case Property::BOOLEAN:
676 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
677 target.propertyIndex,
678 target.componentIndex,
679 AnyCast< AnimatorFunctionBool >( func ),
685 case Property::FLOAT:
687 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
688 target.propertyIndex,
689 target.componentIndex,
690 AnyCast< AnimatorFunctionFloat >( func ),
696 case Property::INTEGER:
698 AddAnimatorConnector( AnimatorConnector<int>::New(proxy,
699 target.propertyIndex,
700 target.componentIndex,
701 AnyCast< AnimatorFunctionInteger >( func ),
707 case Property::VECTOR2:
709 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
710 target.propertyIndex,
711 target.componentIndex,
712 AnyCast< AnimatorFunctionVector2 >( func ),
718 case Property::VECTOR3:
720 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
721 target.propertyIndex,
722 target.componentIndex,
723 AnyCast< AnimatorFunctionVector3 >( func ),
729 case Property::VECTOR4:
731 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
732 target.propertyIndex,
733 target.componentIndex,
734 AnyCast< AnimatorFunctionVector4 >( func ),
740 case Property::ROTATION:
742 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
743 target.propertyIndex,
744 target.componentIndex,
745 AnyCast< AnimatorFunctionQuaternion >( func ),
752 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
757 bool Animation::HasFinished()
759 bool hasFinished(false);
760 const int playCount(mAnimation->GetPlayCount());
762 // If the play count has been incremented, then another notification is required
763 if (playCount > mNotificationCount)
765 // Note that only one signal is emitted, if the animation has been played repeatedly
766 mNotificationCount = playCount;
774 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
776 return mFinishedSignal;
779 void Animation::EmitSignalFinish()
781 if ( !mFinishedSignal.Empty() )
783 Dali::Animation handle( this );
784 mFinishedSignal.Emit( handle );
787 // This callback is used internally, to avoid the overhead of using a signal.
788 if ( mFinishedCallback )
790 mFinishedCallback( mFinishedCallbackObject );
794 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
796 bool connected( true );
797 Animation* animation = dynamic_cast<Animation*>(object);
799 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
801 animation->FinishedSignal().Connect( tracker, functor );
805 // signalName does not match any signal
812 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
814 mFinishedCallback = callback;
815 mFinishedCallbackObject = object;
818 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
820 DALI_ASSERT_DEBUG( NULL != connector );
822 connector->SetParent(*this);
824 mConnectors.PushBack( connector );
827 void Animation::MoveBy(Actor& actor, float x, float y, float z)
829 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
832 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
834 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
837 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
839 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
841 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
842 Dali::Actor::POSITION,
843 Property::INVALID_COMPONENT_INDEX,
844 AnimateByVector3(displacement),
846 TimePeriod(delaySeconds, durationSeconds) ) );
849 void Animation::MoveTo(Actor& actor, float x, float y, float z)
851 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
854 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
856 MoveTo(actor, position, alpha, 0.0f, GetDuration());
859 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
861 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
863 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
864 Dali::Actor::POSITION,
865 Property::INVALID_COMPONENT_INDEX,
866 AnimateToVector3(position),
868 TimePeriod(delaySeconds, durationSeconds) ) );
871 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
873 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
875 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
876 Dali::Actor::POSITION,
877 Property::INVALID_COMPONENT_INDEX,
880 TimePeriod(delaySeconds, durationSeconds) ) );
883 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
885 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
888 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
890 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
893 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
895 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
897 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
898 Dali::Actor::ROTATION,
899 Property::INVALID_COMPONENT_INDEX,
900 RotateByAngleAxis(angle, axis),
902 TimePeriod(delaySeconds, durationSeconds) ) );
905 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
907 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
908 normalizedAxis.Normalize();
910 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
912 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
915 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
917 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
920 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
922 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
923 normalizedAxis.Normalize();
925 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
927 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
930 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
932 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
935 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
937 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
938 normalizedAxis.Normalize();
940 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
942 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
945 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
947 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
949 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
950 Dali::Actor::ROTATION,
951 Property::INVALID_COMPONENT_INDEX,
952 RotateToQuaternion(rotation),
954 TimePeriod(delaySeconds, durationSeconds) ) );
957 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
959 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
961 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
962 Dali::Actor::ROTATION,
963 Property::INVALID_COMPONENT_INDEX,
966 TimePeriod(delaySeconds, durationSeconds) ) );
969 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
971 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
974 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
976 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
979 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
981 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
983 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
985 Property::INVALID_COMPONENT_INDEX,
986 AnimateByVector3(scale),
988 TimePeriod(delaySeconds, durationSeconds) ) );
991 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
993 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
996 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
998 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
1001 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1003 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1005 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1007 Property::INVALID_COMPONENT_INDEX,
1008 AnimateToVector3(scale),
1010 TimePeriod(delaySeconds, durationSeconds) ) );
1013 void Animation::Show(Actor& actor, float delaySeconds)
1015 ExtendDuration( TimePeriod(delaySeconds, 0) );
1017 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1018 Dali::Actor::VISIBLE,
1019 Property::INVALID_COMPONENT_INDEX,
1020 AnimateToBoolean(SHOW_VALUE),
1021 AlphaFunctions::Default,
1022 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1025 void Animation::Hide(Actor& actor, float delaySeconds)
1027 ExtendDuration( TimePeriod(delaySeconds, 0) );
1029 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1030 Dali::Actor::VISIBLE,
1031 Property::INVALID_COMPONENT_INDEX,
1032 AnimateToBoolean(HIDE_VALUE),
1033 AlphaFunctions::Default,
1034 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1037 void Animation::OpacityBy(Actor& actor, float opacity)
1039 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1042 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
1044 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
1047 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1049 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1051 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1053 Property::INVALID_COMPONENT_INDEX,
1054 AnimateByOpacity(opacity),
1056 TimePeriod(delaySeconds, durationSeconds) ) );
1059 void Animation::OpacityTo(Actor& actor, float opacity)
1061 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1064 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
1066 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
1069 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1071 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1073 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1075 Property::INVALID_COMPONENT_INDEX,
1076 AnimateToOpacity(opacity),
1078 TimePeriod(delaySeconds, durationSeconds) ) );
1081 void Animation::ColorBy(Actor& actor, const Vector4& color)
1083 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1086 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
1088 ColorBy(actor, color, alpha, 0.0f, GetDuration());
1091 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1093 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1095 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1097 Property::INVALID_COMPONENT_INDEX,
1098 AnimateByVector4(color),
1100 TimePeriod(delaySeconds, durationSeconds) ) );
1103 void Animation::ColorTo(Actor& actor, const Vector4& color)
1105 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1108 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1110 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1113 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1115 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1117 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1119 Property::INVALID_COMPONENT_INDEX,
1120 AnimateToVector4(color),
1122 TimePeriod(delaySeconds, durationSeconds) ) );
1125 void Animation::Resize(Actor& actor, float width, float height)
1127 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1130 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1132 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1135 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1137 Vector3 targetSize( width, height, min(width, height) );
1139 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1141 // notify the actor impl that its size is being animated
1142 actor.OnSizeAnimation( *this, targetSize );
1144 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1146 Property::INVALID_COMPONENT_INDEX,
1147 AnimateToVector3(targetSize),
1149 TimePeriod(delaySeconds, durationSeconds) ) );
1152 void Animation::Resize(Actor& actor, const Vector3& size)
1154 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1157 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1159 Resize(actor, size, alpha, 0.0f, GetDuration());
1162 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1164 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1166 // notify the actor impl that its size is being animated
1167 actor.OnSizeAnimation( *this, size );
1169 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1171 Property::INVALID_COMPONENT_INDEX,
1172 AnimateToVector3(size),
1174 TimePeriod(delaySeconds, durationSeconds) ) );
1177 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1180 Animation* animation = dynamic_cast<Animation*>(object);
1184 if(Dali::Animation::ACTION_PLAY == actionName)
1186 if(attributes.size() > 0)
1188 animation->SetDuration(attributes[0].Get<float>());
1194 else if(Dali::Animation::ACTION_STOP == actionName)
1199 else if(Dali::Animation::ACTION_PAUSE == actionName)
1209 float Animation::GetCurrentProgress()
1213 return mAnimation->GetCurrentProgress();
1219 void Animation::SetCurrentProgress(float progress)
1221 if( mAnimation && progress >= 0.0f && progress <= 1.0f )
1223 // mAnimation is being used in a separate thread; queue a message to set the current progress
1224 SetCurrentProgressMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
1228 void Animation::ExtendDuration( const TimePeriod& timePeriod )
1230 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
1232 if( duration > mDurationSeconds )
1234 SetDuration( duration );
1238 void Animation::SetSpeedFactor( float factor )
1242 mSpeedFactor = factor;
1243 SetSpeedFactorMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, factor );
1247 float Animation::GetSpeedFactor() const
1249 return mSpeedFactor;
1254 } // namespace Internal