2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/animation/animation-impl.h>
21 #include <dali/public-api/animation/alpha-functions.h>
22 #include <dali/public-api/animation/time-period.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/math/vector2.h>
26 #include <dali/public-api/math/radian.h>
27 #include <dali/internal/event/actors/actor-impl.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/event/animation/animator-connector.h>
30 #include <dali/internal/event/animation/animation-playlist.h>
31 #include <dali/internal/event/common/notification-manager.h>
32 #include <dali/internal/update/manager/update-manager.h>
33 #include <dali/internal/event/effects/shader-effect-impl.h>
34 #include <dali/internal/event/common/thread-local-storage.h>
38 using Dali::Internal::SceneGraph::UpdateManager;
39 using Dali::Internal::SceneGraph::AnimatorBase;
40 using Dali::Internal::SceneGraph::Shader;
48 static bool SHOW_VALUE = true;
49 static bool HIDE_VALUE = false;
56 return Dali::Animation::New(0.f);
59 TypeRegistration mType( typeid(Dali::Animation), typeid(Dali::BaseHandle), Create );
61 SignalConnectorType signalConnector1( mType, Dali::Animation::SIGNAL_FINISHED, &Animation::DoConnectSignal );
63 TypeAction action1( mType, Dali::Animation::ACTION_PLAY, &Animation::DoAction );
64 TypeAction action2( mType, Dali::Animation::ACTION_STOP, &Animation::DoAction );
65 TypeAction action3( mType, Dali::Animation::ACTION_PAUSE, &Animation::DoAction );
70 AnimationPtr Animation::New(float durationSeconds)
72 return New(durationSeconds, Dali::Animation::Bake, Dali::Animation::Bake, Dali::AlphaFunctions::Linear);
75 AnimationPtr Animation::New(float durationSeconds, EndAction endAction, EndAction destroyAction)
77 return New(durationSeconds, endAction, destroyAction, Dali::AlphaFunctions::Linear);
80 AnimationPtr Animation::New(float durationSeconds, EndAction endAction, EndAction destroyAction, AlphaFunction alpha)
82 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
83 UpdateManager& updateManager = tls.GetUpdateManager();
85 AnimationPlaylist& playlist = Stage::GetCurrent()->GetAnimationPlaylist();
87 AnimationPtr progress = new Animation( updateManager, playlist, durationSeconds, endAction, destroyAction, alpha );
89 // Second-phase construction
90 progress->Initialize();
95 Animation::Animation( UpdateManager& updateManager, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction destroyAction, AlphaFunction defaultAlpha )
96 : mUpdateManager( updateManager ),
97 mPlaylist( playlist ),
99 mNotificationCount( 0 ),
100 mFinishedCallback( NULL ),
101 mFinishedCallbackObject( NULL ),
102 mDurationSeconds( durationSeconds ),
104 mEndAction( endAction ),
105 mDestroyAction( destroyAction ),
106 mDefaultAlpha( defaultAlpha )
110 void Animation::Initialize()
112 // Connect to the animation playlist
113 mPlaylist.AnimationCreated( *this );
120 Animation::~Animation()
122 // Guard to allow handle destruction after Core has been destroyed
123 if ( Stage::IsInstalled() )
125 // Disconnect from the animation playlist
126 mPlaylist.AnimationDestroyed( *this );
128 DestroySceneObject();
134 void Animation::CreateSceneObject()
136 DALI_ASSERT_DEBUG( mAnimation == NULL );
138 // Create a new animation, temporarily owned
139 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mIsLooping, mEndAction, mDestroyAction );
141 // Keep a const pointer to the animation.
142 mAnimation = animation;
144 // Transfer animation ownership to the update manager through a message
145 AddAnimationMessage( mUpdateManager, animation );
148 void Animation::DestroySceneObject()
150 if ( mAnimation != NULL )
152 // Remove animation using a message to the update manager
153 RemoveAnimationMessage( mUpdateManager, *mAnimation );
158 void Animation::SetDuration(float seconds)
160 // Cache for public getters
161 mDurationSeconds = seconds;
163 // mAnimation is being used in a separate thread; queue a message to set the value
164 SetDurationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, seconds );
167 float Animation::GetDuration() const
169 // This is not animatable; the cached value is up-to-date.
170 return mDurationSeconds;
173 void Animation::SetLooping(bool looping)
175 // Cache for public getters
176 mIsLooping = looping;
178 // mAnimation is being used in a separate thread; queue a message to set the value
179 SetLoopingMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, looping );
182 bool Animation::IsLooping() const
184 // This is not animatable; the cached value is up-to-date.
188 void Animation::SetEndAction(EndAction action)
190 // Cache for public getters
193 // mAnimation is being used in a separate thread; queue a message to set the value
194 SetEndActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
197 Dali::Animation::EndAction Animation::GetEndAction() const
199 // This is not animatable; the cached value is up-to-date.
203 void Animation::SetDestroyAction(EndAction action)
205 // Cache for public getters
206 mDestroyAction = action;
208 // mAnimation is being used in a separate thread; queue a message to set the value
209 SetDestroyActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
212 Dali::Animation::EndAction Animation::GetDestroyAction() const
214 // This is not animatable; the cached value is up-to-date.
215 return mDestroyAction;
218 void Animation::Play()
220 // Update the current playlist
221 mPlaylist.OnPlay( *this );
223 // mAnimation is being used in a separate thread; queue a Play message
224 PlayAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
227 void Animation::Pause()
229 // mAnimation is being used in a separate thread; queue a Pause message
230 PauseAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
233 void Animation::Stop()
235 // mAnimation is being used in a separate thread; queue a Stop message
236 StopAnimationMessage( mUpdateManager, *mAnimation );
239 void Animation::Clear()
241 DALI_ASSERT_DEBUG(mAnimation);
243 // Remove all the connectors
246 // Replace the old scene-object with a new one
247 DestroySceneObject();
250 // Reset the notification count, since the new scene-object has never been played
251 mNotificationCount = 0;
253 // Update the current playlist
254 mPlaylist.OnClear( *this );
257 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
259 AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds);
262 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
264 AnimateBy(target, relativeValue, alpha, mDurationSeconds);
267 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
269 AnimateBy(target, relativeValue, AlphaFunctions::Default, period);
272 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
274 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
276 switch ( relativeValue.GetType() )
278 case Property::BOOLEAN:
280 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
281 target.propertyIndex,
282 target.componentIndex,
283 AnimateByBoolean(relativeValue.Get<bool>()),
289 case Property::FLOAT:
291 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
292 target.propertyIndex,
293 target.componentIndex,
294 AnimateByFloat(relativeValue.Get<float>()),
300 case Property::VECTOR2:
302 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
303 target.propertyIndex,
304 target.componentIndex,
305 AnimateByVector2(relativeValue.Get<Vector2>()),
311 case Property::VECTOR3:
313 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
314 target.propertyIndex,
315 target.componentIndex,
316 AnimateByVector3(relativeValue.Get<Vector3>()),
322 case Property::VECTOR4:
324 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
325 target.propertyIndex,
326 target.componentIndex,
327 AnimateByVector4(relativeValue.Get<Vector4>()),
333 case Property::ROTATION:
335 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
337 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
338 target.propertyIndex,
339 target.componentIndex,
340 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
347 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
352 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
354 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
357 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
359 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
362 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
364 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
367 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
369 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
371 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
374 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
376 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
377 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
379 if( type == Property::VECTOR2
380 || type == Property::VECTOR3
381 || type == Property::VECTOR4 )
383 type = Property::FLOAT;
386 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
388 switch (destinationValue.GetType())
390 case Property::BOOLEAN:
392 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
395 AnimateToBoolean(destinationValue.Get<bool>()),
401 case Property::FLOAT:
403 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
406 AnimateToFloat(destinationValue.Get<float>()),
412 case Property::VECTOR2:
414 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
417 AnimateToVector2(destinationValue.Get<Vector2>()),
423 case Property::VECTOR3:
425 if ( Dali::Actor::SIZE == targetPropertyIndex )
427 // Test whether this is actually an Actor
428 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
431 // Notify the actor that its size is being animated
432 maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
436 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
439 AnimateToVector3(destinationValue.Get<Vector3>()),
445 case Property::VECTOR4:
447 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
450 AnimateToVector4(destinationValue.Get<Vector4>()),
456 case Property::ROTATION:
458 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
461 RotateToQuaternion(destinationValue.Get<Quaternion>()),
468 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
473 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
475 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
478 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
480 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
483 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
485 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
488 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
490 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
492 switch(keyFrames.GetType())
494 case Dali::Property::BOOLEAN:
496 const KeyFrameBoolean* kf;
497 GetSpecialization(keyFrames, kf);
498 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
499 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
500 target.propertyIndex,
501 target.componentIndex,
502 KeyFrameBooleanFunctor(kfCopy),
507 case Dali::Property::FLOAT:
509 const KeyFrameNumber* kf;
510 GetSpecialization(keyFrames, kf);
511 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
512 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
513 target.propertyIndex,
514 target.componentIndex,
515 KeyFrameNumberFunctor(kfCopy),
521 case Dali::Property::VECTOR2:
523 const KeyFrameVector2* kf;
524 GetSpecialization(keyFrames, kf);
525 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
526 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
527 target.propertyIndex,
528 target.componentIndex,
529 KeyFrameVector2Functor(kfCopy),
535 case Dali::Property::VECTOR3:
537 const KeyFrameVector3* kf;
538 GetSpecialization(keyFrames, kf);
539 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
540 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
541 target.propertyIndex,
542 target.componentIndex,
543 KeyFrameVector3Functor(kfCopy),
549 case Dali::Property::VECTOR4:
551 const KeyFrameVector4* kf;
552 GetSpecialization(keyFrames, kf);
553 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
554 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
555 target.propertyIndex,
556 target.componentIndex,
557 KeyFrameVector4Functor(kfCopy),
563 case Dali::Property::ROTATION:
565 const KeyFrameQuaternion* kf;
566 GetSpecialization(keyFrames, kf);
567 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
568 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
569 target.propertyIndex,
570 target.componentIndex,
571 KeyFrameQuaternionFunctor(kfCopy),
577 default: // not all property types are animateable
582 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
584 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
587 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
589 Animate( target, targetType, func, alpha, mDurationSeconds );
592 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
594 Animate( target, targetType, func, mDefaultAlpha, period );
597 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
599 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
600 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
602 if( type == Property::VECTOR2
603 || type == Property::VECTOR3
604 || type == Property::VECTOR4 )
606 type = Property::FLOAT;
609 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
611 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
613 switch ( targetType )
615 case Property::BOOLEAN:
617 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
618 target.propertyIndex,
619 target.componentIndex,
620 AnyCast< AnimatorFunctionBool >( func ),
626 case Property::FLOAT:
628 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
629 target.propertyIndex,
630 target.componentIndex,
631 AnyCast< AnimatorFunctionFloat >( func ),
637 case Property::VECTOR2:
639 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
640 target.propertyIndex,
641 target.componentIndex,
642 AnyCast< AnimatorFunctionVector2 >( func ),
648 case Property::VECTOR3:
650 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
651 target.propertyIndex,
652 target.componentIndex,
653 AnyCast< AnimatorFunctionVector3 >( func ),
659 case Property::VECTOR4:
661 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
662 target.propertyIndex,
663 target.componentIndex,
664 AnyCast< AnimatorFunctionVector4 >( func ),
670 case Property::ROTATION:
672 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
673 target.propertyIndex,
674 target.componentIndex,
675 AnyCast< AnimatorFunctionQuaternion >( func ),
682 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
687 bool Animation::HasFinished()
689 bool hasFinished(false);
690 const int playCount(mAnimation->GetPlayCount());
692 // If the play count has been incremented, then another notification is required
693 if (playCount > mNotificationCount)
695 // Note that only one signal is emitted, if the animation has been played repeatedly
696 mNotificationCount = playCount;
704 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
706 return mFinishedSignal;
709 void Animation::EmitSignalFinish()
711 if ( !mFinishedSignal.Empty() )
713 Dali::Animation handle( this );
714 mFinishedSignal.Emit( handle );
717 // This callback is used internally, to avoid the overhead of using a signal.
718 if ( mFinishedCallback )
720 mFinishedCallback( mFinishedCallbackObject );
724 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
726 bool connected( true );
727 Animation* animation = dynamic_cast<Animation*>(object);
729 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
731 animation->FinishedSignal().Connect( tracker, functor );
735 // signalName does not match any signal
742 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
744 mFinishedCallback = callback;
745 mFinishedCallbackObject = object;
748 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
750 DALI_ASSERT_DEBUG( NULL != connector );
752 connector->SetParent(*this);
754 mConnectors.PushBack( connector );
757 void Animation::MoveBy(Actor& actor, float x, float y, float z)
759 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
762 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
764 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
767 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
769 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
770 Dali::Actor::POSITION,
771 Property::INVALID_COMPONENT_INDEX,
772 AnimateByVector3(displacement),
774 TimePeriod(delaySeconds, durationSeconds) ) );
777 void Animation::MoveTo(Actor& actor, float x, float y, float z)
779 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
782 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
784 MoveTo(actor, position, alpha, 0.0f, GetDuration());
787 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
789 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
790 Dali::Actor::POSITION,
791 Property::INVALID_COMPONENT_INDEX,
792 AnimateToVector3(position),
794 TimePeriod(delaySeconds, durationSeconds) ) );
797 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
799 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
800 Dali::Actor::POSITION,
801 Property::INVALID_COMPONENT_INDEX,
804 TimePeriod(delaySeconds, durationSeconds) ) );
807 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
809 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
812 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
814 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
817 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
819 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
820 Dali::Actor::ROTATION,
821 Property::INVALID_COMPONENT_INDEX,
822 RotateByAngleAxis(angle, axis),
824 TimePeriod(delaySeconds, durationSeconds) ) );
827 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
829 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
830 normalizedAxis.Normalize();
832 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
834 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
837 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
839 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
842 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
844 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
845 normalizedAxis.Normalize();
847 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
849 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
852 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
854 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
857 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
859 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
860 normalizedAxis.Normalize();
862 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
864 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
867 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
869 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
870 Dali::Actor::ROTATION,
871 Property::INVALID_COMPONENT_INDEX,
872 RotateToQuaternion(rotation),
874 TimePeriod(delaySeconds, durationSeconds) ) );
877 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
879 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
880 Dali::Actor::ROTATION,
881 Property::INVALID_COMPONENT_INDEX,
884 TimePeriod(delaySeconds, durationSeconds) ) );
887 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
889 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
892 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
894 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
897 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
899 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
901 Property::INVALID_COMPONENT_INDEX,
902 AnimateByVector3(scale),
904 TimePeriod(delaySeconds, durationSeconds) ) );
907 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
909 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
912 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
914 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
917 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
919 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
921 Property::INVALID_COMPONENT_INDEX,
922 AnimateToVector3(scale),
924 TimePeriod(delaySeconds, durationSeconds) ) );
927 void Animation::Show(Actor& actor, float delaySeconds)
929 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
930 Dali::Actor::VISIBLE,
931 Property::INVALID_COMPONENT_INDEX,
932 AnimateToBoolean(SHOW_VALUE),
933 AlphaFunctions::Default,
934 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
937 void Animation::Hide(Actor& actor, float delaySeconds)
939 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
940 Dali::Actor::VISIBLE,
941 Property::INVALID_COMPONENT_INDEX,
942 AnimateToBoolean(HIDE_VALUE),
943 AlphaFunctions::Default,
944 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
947 void Animation::OpacityBy(Actor& actor, float opacity)
949 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
952 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
954 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
957 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
959 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
961 Property::INVALID_COMPONENT_INDEX,
962 AnimateByOpacity(opacity),
964 TimePeriod(delaySeconds, durationSeconds) ) );
967 void Animation::OpacityTo(Actor& actor, float opacity)
969 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
972 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
974 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
977 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
979 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
981 Property::INVALID_COMPONENT_INDEX,
982 AnimateToOpacity(opacity),
984 TimePeriod(delaySeconds, durationSeconds) ) );
987 void Animation::ColorBy(Actor& actor, const Vector4& color)
989 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
992 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
994 ColorBy(actor, color, alpha, 0.0f, GetDuration());
997 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
999 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1001 Property::INVALID_COMPONENT_INDEX,
1002 AnimateByVector4(color),
1004 TimePeriod(delaySeconds, durationSeconds) ) );
1007 void Animation::ColorTo(Actor& actor, const Vector4& color)
1009 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1012 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1014 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1017 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1019 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1021 Property::INVALID_COMPONENT_INDEX,
1022 AnimateToVector4(color),
1024 TimePeriod(delaySeconds, durationSeconds) ) );
1027 void Animation::Resize(Actor& actor, float width, float height)
1029 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1032 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1034 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1037 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1039 Vector3 targetSize( width, height, min(width, height) );
1041 // notify the actor impl that its size is being animated
1042 actor.OnSizeAnimation( *this, targetSize );
1044 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1046 Property::INVALID_COMPONENT_INDEX,
1047 AnimateToVector3(targetSize),
1049 TimePeriod(delaySeconds, durationSeconds) ) );
1052 void Animation::Resize(Actor& actor, const Vector3& size)
1054 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1057 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1059 Resize(actor, size, alpha, 0.0f, GetDuration());
1062 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1064 // notify the actor impl that its size is being animated
1065 actor.OnSizeAnimation( *this, size );
1067 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1069 Property::INVALID_COMPONENT_INDEX,
1070 AnimateToVector3(size),
1072 TimePeriod(delaySeconds, durationSeconds) ) );
1075 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin)
1077 ParentOriginTo(actor, parentOrigin, mDefaultAlpha, 0.0f, GetDuration());
1080 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha)
1082 ParentOriginTo(actor, parentOrigin, alpha, 0.0f, GetDuration());
1085 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1087 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1088 Dali::Actor::PARENT_ORIGIN,
1089 Property::INVALID_COMPONENT_INDEX,
1090 AnimateToVector3(parentOrigin),
1092 TimePeriod(delaySeconds, durationSeconds) ) );
1095 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint)
1097 AnchorPointTo(actor, anchorPoint, mDefaultAlpha, 0.0f, GetDuration());
1100 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha)
1102 AnchorPointTo(actor, anchorPoint, alpha, 0.0f, GetDuration());
1105 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1107 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1108 Dali::Actor::ANCHOR_POINT,
1109 Property::INVALID_COMPONENT_INDEX,
1110 AnimateToVector3(anchorPoint),
1112 TimePeriod(delaySeconds, durationSeconds) ) );
1115 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value )
1117 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1120 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha )
1122 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1125 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1127 Property::Value propertyValue( value );
1129 // Register the property if it does not exist
1130 Property::Index index = shaderEffect.GetPropertyIndex( name );
1131 if ( Property::INVALID_INDEX == index )
1133 index = shaderEffect.RegisterProperty( name, propertyValue );
1136 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1139 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value )
1141 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration());
1144 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha )
1146 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1149 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1151 Property::Value propertyValue( value );
1153 // Register the property if it does not exist
1154 Property::Index index = shaderEffect.GetPropertyIndex( name );
1155 if ( Property::INVALID_INDEX == index )
1157 index = shaderEffect.RegisterProperty( name, propertyValue );
1160 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1163 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value )
1165 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1168 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha )
1170 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1173 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1175 Property::Value propertyValue( value );
1177 // Register the property if it does not exist
1178 Property::Index index = shaderEffect.GetPropertyIndex( name );
1179 if ( Property::INVALID_INDEX == index )
1181 index = shaderEffect.RegisterProperty( name, propertyValue );
1184 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1187 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value )
1189 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1192 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha )
1194 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1197 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1199 Property::Value propertyValue( value );
1201 // Register the property if it does not exist
1202 Property::Index index = shaderEffect.GetPropertyIndex( name );
1203 if ( Property::INVALID_INDEX == index )
1205 index = shaderEffect.RegisterProperty( name, propertyValue );
1208 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1211 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1214 Animation* animation = dynamic_cast<Animation*>(object);
1218 if(Dali::Animation::ACTION_PLAY == actionName)
1220 if(attributes.size() > 0)
1222 animation->SetDuration(attributes[0].Get<float>());
1228 else if(Dali::Animation::ACTION_STOP == actionName)
1233 else if(Dali::Animation::ACTION_PAUSE == actionName)
1243 } // namespace Internal