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 ),
105 mEndAction( endAction ),
106 mDestroyAction( destroyAction ),
107 mDefaultAlpha( defaultAlpha )
111 void Animation::Initialize()
113 // Connect to the animation playlist
114 mPlaylist.AnimationCreated( *this );
121 Animation::~Animation()
123 // Guard to allow handle destruction after Core has been destroyed
124 if ( Stage::IsInstalled() )
126 // Disconnect from the animation playlist
127 mPlaylist.AnimationDestroyed( *this );
129 DestroySceneObject();
135 void Animation::CreateSceneObject()
137 DALI_ASSERT_DEBUG( mAnimation == NULL );
139 // Create a new animation, temporarily owned
140 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mIsLooping, mEndAction, mDestroyAction );
142 // Keep a const pointer to the animation.
143 mAnimation = animation;
145 // Transfer animation ownership to the update manager through a message
146 AddAnimationMessage( mUpdateManager, animation );
149 void Animation::DestroySceneObject()
151 if ( mAnimation != NULL )
153 // Remove animation using a message to the update manager
154 RemoveAnimationMessage( mUpdateManager, *mAnimation );
159 void Animation::SetDuration(float seconds)
161 // Cache for public getters
162 mDurationSeconds = seconds;
164 // mAnimation is being used in a separate thread; queue a message to set the value
165 SetDurationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, seconds );
168 float Animation::GetDuration() const
170 // This is not animatable; the cached value is up-to-date.
171 return mDurationSeconds;
174 void Animation::SetLooping(bool looping)
176 // Cache for public getters
177 mIsLooping = looping;
179 // mAnimation is being used in a separate thread; queue a message to set the value
180 SetLoopingMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, looping );
183 bool Animation::IsLooping() const
185 // This is not animatable; the cached value is up-to-date.
189 void Animation::SetEndAction(EndAction action)
191 // Cache for public getters
194 // mAnimation is being used in a separate thread; queue a message to set the value
195 SetEndActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
198 Dali::Animation::EndAction Animation::GetEndAction() const
200 // This is not animatable; the cached value is up-to-date.
204 void Animation::SetDestroyAction(EndAction action)
206 // Cache for public getters
207 mDestroyAction = action;
209 // mAnimation is being used in a separate thread; queue a message to set the value
210 SetDestroyActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
213 Dali::Animation::EndAction Animation::GetDestroyAction() const
215 // This is not animatable; the cached value is up-to-date.
216 return mDestroyAction;
219 void Animation::Play()
221 // Update the current playlist
222 mPlaylist.OnPlay( *this );
224 // mAnimation is being used in a separate thread; queue a Play message
225 PlayAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
228 void Animation::Pause()
230 // mAnimation is being used in a separate thread; queue a Pause message
231 PauseAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
234 void Animation::Stop()
236 // mAnimation is being used in a separate thread; queue a Stop message
237 StopAnimationMessage( mUpdateManager, *mAnimation );
240 void Animation::Clear()
242 DALI_ASSERT_DEBUG(mAnimation);
244 // Remove all the connectors
247 // Replace the old scene-object with a new one
248 DestroySceneObject();
251 // Reset the notification count, since the new scene-object has never been played
252 mNotificationCount = 0;
254 // Update the current playlist
255 mPlaylist.OnClear( *this );
258 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
260 AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds);
263 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
265 AnimateBy(target, relativeValue, alpha, mDurationSeconds);
268 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
270 AnimateBy(target, relativeValue, AlphaFunctions::Default, period);
273 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
275 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
277 switch ( relativeValue.GetType() )
279 case Property::BOOLEAN:
281 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
282 target.propertyIndex,
283 target.componentIndex,
284 AnimateByBoolean(relativeValue.Get<bool>()),
290 case Property::FLOAT:
292 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
293 target.propertyIndex,
294 target.componentIndex,
295 AnimateByFloat(relativeValue.Get<float>()),
301 case Property::VECTOR2:
303 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
304 target.propertyIndex,
305 target.componentIndex,
306 AnimateByVector2(relativeValue.Get<Vector2>()),
312 case Property::VECTOR3:
314 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
315 target.propertyIndex,
316 target.componentIndex,
317 AnimateByVector3(relativeValue.Get<Vector3>()),
323 case Property::VECTOR4:
325 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
326 target.propertyIndex,
327 target.componentIndex,
328 AnimateByVector4(relativeValue.Get<Vector4>()),
334 case Property::ROTATION:
336 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
338 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
339 target.propertyIndex,
340 target.componentIndex,
341 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
348 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
353 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
355 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
358 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
360 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
363 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
365 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
368 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
370 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
372 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
375 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
377 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
378 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
380 if( type == Property::VECTOR2
381 || type == Property::VECTOR3
382 || type == Property::VECTOR4 )
384 type = Property::FLOAT;
387 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
389 switch (destinationValue.GetType())
391 case Property::BOOLEAN:
393 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
396 AnimateToBoolean(destinationValue.Get<bool>()),
402 case Property::FLOAT:
404 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
407 AnimateToFloat(destinationValue.Get<float>()),
413 case Property::VECTOR2:
415 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
418 AnimateToVector2(destinationValue.Get<Vector2>()),
424 case Property::VECTOR3:
426 if ( Dali::Actor::SIZE == targetPropertyIndex )
428 // Test whether this is actually an Actor
429 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
432 // Notify the actor that its size is being animated
433 maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
437 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
440 AnimateToVector3(destinationValue.Get<Vector3>()),
446 case Property::VECTOR4:
448 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
451 AnimateToVector4(destinationValue.Get<Vector4>()),
457 case Property::ROTATION:
459 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
462 RotateToQuaternion(destinationValue.Get<Quaternion>()),
469 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
474 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
476 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
479 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
481 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
484 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
486 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
489 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
491 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
493 switch(keyFrames.GetType())
495 case Dali::Property::BOOLEAN:
497 const KeyFrameBoolean* kf;
498 GetSpecialization(keyFrames, kf);
499 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
500 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
501 target.propertyIndex,
502 target.componentIndex,
503 KeyFrameBooleanFunctor(kfCopy),
508 case Dali::Property::FLOAT:
510 const KeyFrameNumber* kf;
511 GetSpecialization(keyFrames, kf);
512 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
513 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
514 target.propertyIndex,
515 target.componentIndex,
516 KeyFrameNumberFunctor(kfCopy),
522 case Dali::Property::VECTOR2:
524 const KeyFrameVector2* kf;
525 GetSpecialization(keyFrames, kf);
526 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
527 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
528 target.propertyIndex,
529 target.componentIndex,
530 KeyFrameVector2Functor(kfCopy),
536 case Dali::Property::VECTOR3:
538 const KeyFrameVector3* kf;
539 GetSpecialization(keyFrames, kf);
540 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
541 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
542 target.propertyIndex,
543 target.componentIndex,
544 KeyFrameVector3Functor(kfCopy),
550 case Dali::Property::VECTOR4:
552 const KeyFrameVector4* kf;
553 GetSpecialization(keyFrames, kf);
554 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
555 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
556 target.propertyIndex,
557 target.componentIndex,
558 KeyFrameVector4Functor(kfCopy),
564 case Dali::Property::ROTATION:
566 const KeyFrameQuaternion* kf;
567 GetSpecialization(keyFrames, kf);
568 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
569 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
570 target.propertyIndex,
571 target.componentIndex,
572 KeyFrameQuaternionFunctor(kfCopy),
578 default: // not all property types are animateable
583 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
585 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
588 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
590 Animate( target, targetType, func, alpha, mDurationSeconds );
593 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
595 Animate( target, targetType, func, mDefaultAlpha, period );
598 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
600 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
601 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
603 if( type == Property::VECTOR2
604 || type == Property::VECTOR3
605 || type == Property::VECTOR4 )
607 type = Property::FLOAT;
610 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
612 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
614 switch ( targetType )
616 case Property::BOOLEAN:
618 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
619 target.propertyIndex,
620 target.componentIndex,
621 AnyCast< AnimatorFunctionBool >( func ),
627 case Property::FLOAT:
629 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
630 target.propertyIndex,
631 target.componentIndex,
632 AnyCast< AnimatorFunctionFloat >( func ),
638 case Property::VECTOR2:
640 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
641 target.propertyIndex,
642 target.componentIndex,
643 AnyCast< AnimatorFunctionVector2 >( func ),
649 case Property::VECTOR3:
651 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
652 target.propertyIndex,
653 target.componentIndex,
654 AnyCast< AnimatorFunctionVector3 >( func ),
660 case Property::VECTOR4:
662 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
663 target.propertyIndex,
664 target.componentIndex,
665 AnyCast< AnimatorFunctionVector4 >( func ),
671 case Property::ROTATION:
673 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
674 target.propertyIndex,
675 target.componentIndex,
676 AnyCast< AnimatorFunctionQuaternion >( func ),
683 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
688 bool Animation::HasFinished()
690 bool hasFinished(false);
691 const int playCount(mAnimation->GetPlayCount());
693 // If the play count has been incremented, then another notification is required
694 if (playCount > mNotificationCount)
696 // Note that only one signal is emitted, if the animation has been played repeatedly
697 mNotificationCount = playCount;
705 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
707 return mFinishedSignal;
710 void Animation::EmitSignalFinish()
712 if ( !mFinishedSignal.Empty() )
714 Dali::Animation handle( this );
715 mFinishedSignal.Emit( handle );
718 // This callback is used internally, to avoid the overhead of using a signal.
719 if ( mFinishedCallback )
721 mFinishedCallback( mFinishedCallbackObject );
725 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
727 bool connected( true );
728 Animation* animation = dynamic_cast<Animation*>(object);
730 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
732 animation->FinishedSignal().Connect( tracker, functor );
736 // signalName does not match any signal
743 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
745 mFinishedCallback = callback;
746 mFinishedCallbackObject = object;
749 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
751 DALI_ASSERT_DEBUG( NULL != connector );
753 connector->SetParent(*this);
755 mConnectors.PushBack( connector );
758 void Animation::MoveBy(Actor& actor, float x, float y, float z)
760 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
763 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
765 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
768 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
770 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
771 Dali::Actor::POSITION,
772 Property::INVALID_COMPONENT_INDEX,
773 AnimateByVector3(displacement),
775 TimePeriod(delaySeconds, durationSeconds) ) );
778 void Animation::MoveTo(Actor& actor, float x, float y, float z)
780 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
783 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
785 MoveTo(actor, position, alpha, 0.0f, GetDuration());
788 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
790 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
791 Dali::Actor::POSITION,
792 Property::INVALID_COMPONENT_INDEX,
793 AnimateToVector3(position),
795 TimePeriod(delaySeconds, durationSeconds) ) );
798 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
800 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
801 Dali::Actor::POSITION,
802 Property::INVALID_COMPONENT_INDEX,
805 TimePeriod(delaySeconds, durationSeconds) ) );
808 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
810 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
813 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
815 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
818 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
820 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
821 Dali::Actor::ROTATION,
822 Property::INVALID_COMPONENT_INDEX,
823 RotateByAngleAxis(angle, axis),
825 TimePeriod(delaySeconds, durationSeconds) ) );
828 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
830 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
831 normalizedAxis.Normalize();
833 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
835 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
838 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
840 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
843 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
845 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
846 normalizedAxis.Normalize();
848 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
850 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
853 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
855 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
858 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
860 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
861 normalizedAxis.Normalize();
863 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
865 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
868 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
870 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
871 Dali::Actor::ROTATION,
872 Property::INVALID_COMPONENT_INDEX,
873 RotateToQuaternion(rotation),
875 TimePeriod(delaySeconds, durationSeconds) ) );
878 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
880 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
881 Dali::Actor::ROTATION,
882 Property::INVALID_COMPONENT_INDEX,
885 TimePeriod(delaySeconds, durationSeconds) ) );
888 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
890 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
893 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
895 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
898 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
900 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
902 Property::INVALID_COMPONENT_INDEX,
903 AnimateByVector3(scale),
905 TimePeriod(delaySeconds, durationSeconds) ) );
908 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
910 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
913 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
915 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
918 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
920 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
922 Property::INVALID_COMPONENT_INDEX,
923 AnimateToVector3(scale),
925 TimePeriod(delaySeconds, durationSeconds) ) );
928 void Animation::Show(Actor& actor, float delaySeconds)
930 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
931 Dali::Actor::VISIBLE,
932 Property::INVALID_COMPONENT_INDEX,
933 AnimateToBoolean(SHOW_VALUE),
934 AlphaFunctions::Default,
935 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
938 void Animation::Hide(Actor& actor, float delaySeconds)
940 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
941 Dali::Actor::VISIBLE,
942 Property::INVALID_COMPONENT_INDEX,
943 AnimateToBoolean(HIDE_VALUE),
944 AlphaFunctions::Default,
945 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
948 void Animation::OpacityBy(Actor& actor, float opacity)
950 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
953 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
955 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
958 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
960 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
962 Property::INVALID_COMPONENT_INDEX,
963 AnimateByOpacity(opacity),
965 TimePeriod(delaySeconds, durationSeconds) ) );
968 void Animation::OpacityTo(Actor& actor, float opacity)
970 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
973 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
975 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
978 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
980 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
982 Property::INVALID_COMPONENT_INDEX,
983 AnimateToOpacity(opacity),
985 TimePeriod(delaySeconds, durationSeconds) ) );
988 void Animation::ColorBy(Actor& actor, const Vector4& color)
990 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
993 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
995 ColorBy(actor, color, alpha, 0.0f, GetDuration());
998 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1000 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1002 Property::INVALID_COMPONENT_INDEX,
1003 AnimateByVector4(color),
1005 TimePeriod(delaySeconds, durationSeconds) ) );
1008 void Animation::ColorTo(Actor& actor, const Vector4& color)
1010 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1013 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1015 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1018 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1020 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1022 Property::INVALID_COMPONENT_INDEX,
1023 AnimateToVector4(color),
1025 TimePeriod(delaySeconds, durationSeconds) ) );
1028 void Animation::Resize(Actor& actor, float width, float height)
1030 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1033 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1035 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1038 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1040 Vector3 targetSize( width, height, min(width, height) );
1042 // notify the actor impl that its size is being animated
1043 actor.OnSizeAnimation( *this, targetSize );
1045 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1047 Property::INVALID_COMPONENT_INDEX,
1048 AnimateToVector3(targetSize),
1050 TimePeriod(delaySeconds, durationSeconds) ) );
1053 void Animation::Resize(Actor& actor, const Vector3& size)
1055 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1058 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1060 Resize(actor, size, alpha, 0.0f, GetDuration());
1063 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1065 // notify the actor impl that its size is being animated
1066 actor.OnSizeAnimation( *this, size );
1068 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1070 Property::INVALID_COMPONENT_INDEX,
1071 AnimateToVector3(size),
1073 TimePeriod(delaySeconds, durationSeconds) ) );
1076 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin)
1078 ParentOriginTo(actor, parentOrigin, mDefaultAlpha, 0.0f, GetDuration());
1081 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha)
1083 ParentOriginTo(actor, parentOrigin, alpha, 0.0f, GetDuration());
1086 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1088 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1089 Dali::Actor::PARENT_ORIGIN,
1090 Property::INVALID_COMPONENT_INDEX,
1091 AnimateToVector3(parentOrigin),
1093 TimePeriod(delaySeconds, durationSeconds) ) );
1096 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint)
1098 AnchorPointTo(actor, anchorPoint, mDefaultAlpha, 0.0f, GetDuration());
1101 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha)
1103 AnchorPointTo(actor, anchorPoint, alpha, 0.0f, GetDuration());
1106 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1108 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1109 Dali::Actor::ANCHOR_POINT,
1110 Property::INVALID_COMPONENT_INDEX,
1111 AnimateToVector3(anchorPoint),
1113 TimePeriod(delaySeconds, durationSeconds) ) );
1116 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value )
1118 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1121 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha )
1123 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1126 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1128 Property::Value propertyValue( value );
1130 // Register the property if it does not exist
1131 Property::Index index = shaderEffect.GetPropertyIndex( name );
1132 if ( Property::INVALID_INDEX == index )
1134 index = shaderEffect.RegisterProperty( name, propertyValue );
1137 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1140 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value )
1142 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration());
1145 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha )
1147 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1150 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1152 Property::Value propertyValue( value );
1154 // Register the property if it does not exist
1155 Property::Index index = shaderEffect.GetPropertyIndex( name );
1156 if ( Property::INVALID_INDEX == index )
1158 index = shaderEffect.RegisterProperty( name, propertyValue );
1161 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1164 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value )
1166 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1169 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha )
1171 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1174 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1176 Property::Value propertyValue( value );
1178 // Register the property if it does not exist
1179 Property::Index index = shaderEffect.GetPropertyIndex( name );
1180 if ( Property::INVALID_INDEX == index )
1182 index = shaderEffect.RegisterProperty( name, propertyValue );
1185 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1188 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value )
1190 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1193 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha )
1195 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1198 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1200 Property::Value propertyValue( value );
1202 // Register the property if it does not exist
1203 Property::Index index = shaderEffect.GetPropertyIndex( name );
1204 if ( Property::INVALID_INDEX == index )
1206 index = shaderEffect.RegisterProperty( name, propertyValue );
1209 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1212 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1215 Animation* animation = dynamic_cast<Animation*>(object);
1219 if(Dali::Animation::ACTION_PLAY == actionName)
1221 if(attributes.size() > 0)
1223 animation->SetDuration(attributes[0].Get<float>());
1229 else if(Dali::Animation::ACTION_STOP == actionName)
1234 else if(Dali::Animation::ACTION_PAUSE == actionName)
1244 } // namespace Internal