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::PlayFrom( float progress )
230 if( progress >= 0.0f && progress <= 1.0f )
232 // Update the current playlist
233 mPlaylist.OnPlay( *this );
235 // mAnimation is being used in a separate thread; queue a Play message
236 PlayAnimationFromMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
240 void Animation::Pause()
242 // mAnimation is being used in a separate thread; queue a Pause message
243 PauseAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
246 void Animation::Stop()
248 // mAnimation is being used in a separate thread; queue a Stop message
249 StopAnimationMessage( mUpdateManager, *mAnimation );
252 void Animation::Clear()
254 DALI_ASSERT_DEBUG(mAnimation);
256 // Remove all the connectors
259 // Replace the old scene-object with a new one
260 DestroySceneObject();
263 // Reset the notification count, since the new scene-object has never been played
264 mNotificationCount = 0;
266 // Update the current playlist
267 mPlaylist.OnClear( *this );
270 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
272 AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds);
275 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
277 AnimateBy(target, relativeValue, alpha, mDurationSeconds);
280 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
282 AnimateBy(target, relativeValue, AlphaFunctions::Default, period);
285 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
287 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
289 ExtendDuration( period );
291 switch ( relativeValue.GetType() )
293 case Property::BOOLEAN:
295 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
296 target.propertyIndex,
297 target.componentIndex,
298 AnimateByBoolean(relativeValue.Get<bool>()),
304 case Property::FLOAT:
306 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
307 target.propertyIndex,
308 target.componentIndex,
309 AnimateByFloat(relativeValue.Get<float>()),
315 case Property::INTEGER:
317 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
318 target.propertyIndex,
319 target.componentIndex,
320 AnimateByInteger(relativeValue.Get<int>()),
326 case Property::VECTOR2:
328 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
329 target.propertyIndex,
330 target.componentIndex,
331 AnimateByVector2(relativeValue.Get<Vector2>()),
337 case Property::VECTOR3:
339 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
340 target.propertyIndex,
341 target.componentIndex,
342 AnimateByVector3(relativeValue.Get<Vector3>()),
348 case Property::VECTOR4:
350 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
351 target.propertyIndex,
352 target.componentIndex,
353 AnimateByVector4(relativeValue.Get<Vector4>()),
359 case Property::ROTATION:
361 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
363 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
364 target.propertyIndex,
365 target.componentIndex,
366 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
373 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
378 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
380 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
383 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
385 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
388 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
390 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
393 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
395 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
397 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
400 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
402 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
403 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
405 if( type == Property::VECTOR2
406 || type == Property::VECTOR3
407 || type == Property::VECTOR4 )
409 type = Property::FLOAT;
412 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
414 ExtendDuration( period );
416 switch (destinationValue.GetType())
418 case Property::BOOLEAN:
420 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
423 AnimateToBoolean(destinationValue.Get<bool>()),
429 case Property::FLOAT:
431 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
434 AnimateToFloat(destinationValue.Get<float>()),
440 case Property::INTEGER:
442 AddAnimatorConnector( AnimatorConnector<int>::New(targetObject,
445 AnimateToInteger(destinationValue.Get<int>()),
451 case Property::VECTOR2:
453 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
456 AnimateToVector2(destinationValue.Get<Vector2>()),
462 case Property::VECTOR3:
464 if ( Dali::Actor::SIZE == targetPropertyIndex )
466 // Test whether this is actually an Actor
467 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
470 // Notify the actor that its size is being animated
471 maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
475 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
478 AnimateToVector3(destinationValue.Get<Vector3>()),
484 case Property::VECTOR4:
486 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
489 AnimateToVector4(destinationValue.Get<Vector4>()),
495 case Property::ROTATION:
497 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
500 RotateToQuaternion(destinationValue.Get<Quaternion>()),
507 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
512 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
514 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
517 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
519 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
522 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
524 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
527 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
529 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
531 ExtendDuration( period );
533 switch(keyFrames.GetType())
535 case Dali::Property::BOOLEAN:
537 const KeyFrameBoolean* kf;
538 GetSpecialization(keyFrames, kf);
539 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
540 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
541 target.propertyIndex,
542 target.componentIndex,
543 KeyFrameBooleanFunctor(kfCopy),
549 case Dali::Property::FLOAT:
551 const KeyFrameNumber* kf;
552 GetSpecialization(keyFrames, kf);
553 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
554 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
555 target.propertyIndex,
556 target.componentIndex,
557 KeyFrameNumberFunctor(kfCopy),
563 case Dali::Property::INTEGER:
565 const KeyFrameInteger* kf;
566 GetSpecialization(keyFrames, kf);
567 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
568 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
569 target.propertyIndex,
570 target.componentIndex,
571 KeyFrameIntegerFunctor(kfCopy),
577 case Dali::Property::VECTOR2:
579 const KeyFrameVector2* kf;
580 GetSpecialization(keyFrames, kf);
581 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
582 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
583 target.propertyIndex,
584 target.componentIndex,
585 KeyFrameVector2Functor(kfCopy),
591 case Dali::Property::VECTOR3:
593 const KeyFrameVector3* kf;
594 GetSpecialization(keyFrames, kf);
595 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
596 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
597 target.propertyIndex,
598 target.componentIndex,
599 KeyFrameVector3Functor(kfCopy),
605 case Dali::Property::VECTOR4:
607 const KeyFrameVector4* kf;
608 GetSpecialization(keyFrames, kf);
609 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
610 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
611 target.propertyIndex,
612 target.componentIndex,
613 KeyFrameVector4Functor(kfCopy),
619 case Dali::Property::ROTATION:
621 const KeyFrameQuaternion* kf;
622 GetSpecialization(keyFrames, kf);
623 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
624 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
625 target.propertyIndex,
626 target.componentIndex,
627 KeyFrameQuaternionFunctor(kfCopy),
633 default: // not all property types are animateable
638 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
640 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
643 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
645 Animate( target, targetType, func, alpha, mDurationSeconds );
648 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
650 Animate( target, targetType, func, mDefaultAlpha, period );
653 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
655 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
656 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
658 if( type == Property::VECTOR2
659 || type == Property::VECTOR3
660 || type == Property::VECTOR4 )
662 type = Property::FLOAT;
665 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
667 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
669 ExtendDuration( period );
671 switch ( targetType )
673 case Property::BOOLEAN:
675 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
676 target.propertyIndex,
677 target.componentIndex,
678 AnyCast< AnimatorFunctionBool >( func ),
684 case Property::FLOAT:
686 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
687 target.propertyIndex,
688 target.componentIndex,
689 AnyCast< AnimatorFunctionFloat >( func ),
695 case Property::INTEGER:
697 AddAnimatorConnector( AnimatorConnector<int>::New(proxy,
698 target.propertyIndex,
699 target.componentIndex,
700 AnyCast< AnimatorFunctionInteger >( func ),
706 case Property::VECTOR2:
708 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
709 target.propertyIndex,
710 target.componentIndex,
711 AnyCast< AnimatorFunctionVector2 >( func ),
717 case Property::VECTOR3:
719 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
720 target.propertyIndex,
721 target.componentIndex,
722 AnyCast< AnimatorFunctionVector3 >( func ),
728 case Property::VECTOR4:
730 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
731 target.propertyIndex,
732 target.componentIndex,
733 AnyCast< AnimatorFunctionVector4 >( func ),
739 case Property::ROTATION:
741 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
742 target.propertyIndex,
743 target.componentIndex,
744 AnyCast< AnimatorFunctionQuaternion >( func ),
751 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
756 bool Animation::HasFinished()
758 bool hasFinished(false);
759 const int playCount(mAnimation->GetPlayCount());
761 // If the play count has been incremented, then another notification is required
762 if (playCount > mNotificationCount)
764 // Note that only one signal is emitted, if the animation has been played repeatedly
765 mNotificationCount = playCount;
773 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
775 return mFinishedSignal;
778 void Animation::EmitSignalFinish()
780 if ( !mFinishedSignal.Empty() )
782 Dali::Animation handle( this );
783 mFinishedSignal.Emit( handle );
786 // This callback is used internally, to avoid the overhead of using a signal.
787 if ( mFinishedCallback )
789 mFinishedCallback( mFinishedCallbackObject );
793 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
795 bool connected( true );
796 Animation* animation = dynamic_cast<Animation*>(object);
798 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
800 animation->FinishedSignal().Connect( tracker, functor );
804 // signalName does not match any signal
811 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
813 mFinishedCallback = callback;
814 mFinishedCallbackObject = object;
817 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
819 DALI_ASSERT_DEBUG( NULL != connector );
821 connector->SetParent(*this);
823 mConnectors.PushBack( connector );
826 void Animation::MoveBy(Actor& actor, float x, float y, float z)
828 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
831 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
833 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
836 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
838 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
840 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
841 Dali::Actor::POSITION,
842 Property::INVALID_COMPONENT_INDEX,
843 AnimateByVector3(displacement),
845 TimePeriod(delaySeconds, durationSeconds) ) );
848 void Animation::MoveTo(Actor& actor, float x, float y, float z)
850 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
853 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
855 MoveTo(actor, position, alpha, 0.0f, GetDuration());
858 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
860 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
862 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
863 Dali::Actor::POSITION,
864 Property::INVALID_COMPONENT_INDEX,
865 AnimateToVector3(position),
867 TimePeriod(delaySeconds, durationSeconds) ) );
870 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
872 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
874 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
875 Dali::Actor::POSITION,
876 Property::INVALID_COMPONENT_INDEX,
879 TimePeriod(delaySeconds, durationSeconds) ) );
882 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
884 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
887 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
889 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
892 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
894 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
896 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
897 Dali::Actor::ROTATION,
898 Property::INVALID_COMPONENT_INDEX,
899 RotateByAngleAxis(angle, axis),
901 TimePeriod(delaySeconds, durationSeconds) ) );
904 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
906 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
907 normalizedAxis.Normalize();
909 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
911 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
914 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
916 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
919 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
921 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
922 normalizedAxis.Normalize();
924 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
926 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
929 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
931 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
934 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
936 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
937 normalizedAxis.Normalize();
939 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
941 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
944 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
946 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
948 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
949 Dali::Actor::ROTATION,
950 Property::INVALID_COMPONENT_INDEX,
951 RotateToQuaternion(rotation),
953 TimePeriod(delaySeconds, durationSeconds) ) );
956 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
958 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
960 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
961 Dali::Actor::ROTATION,
962 Property::INVALID_COMPONENT_INDEX,
965 TimePeriod(delaySeconds, durationSeconds) ) );
968 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
970 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
973 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
975 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
978 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
980 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
982 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
984 Property::INVALID_COMPONENT_INDEX,
985 AnimateByVector3(scale),
987 TimePeriod(delaySeconds, durationSeconds) ) );
990 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
992 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
995 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
997 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
1000 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1002 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1004 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1006 Property::INVALID_COMPONENT_INDEX,
1007 AnimateToVector3(scale),
1009 TimePeriod(delaySeconds, durationSeconds) ) );
1012 void Animation::Show(Actor& actor, float delaySeconds)
1014 ExtendDuration( TimePeriod(delaySeconds, 0) );
1016 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1017 Dali::Actor::VISIBLE,
1018 Property::INVALID_COMPONENT_INDEX,
1019 AnimateToBoolean(SHOW_VALUE),
1020 AlphaFunctions::Default,
1021 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1024 void Animation::Hide(Actor& actor, float delaySeconds)
1026 ExtendDuration( TimePeriod(delaySeconds, 0) );
1028 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1029 Dali::Actor::VISIBLE,
1030 Property::INVALID_COMPONENT_INDEX,
1031 AnimateToBoolean(HIDE_VALUE),
1032 AlphaFunctions::Default,
1033 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1036 void Animation::OpacityBy(Actor& actor, float opacity)
1038 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1041 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
1043 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
1046 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1048 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1050 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1052 Property::INVALID_COMPONENT_INDEX,
1053 AnimateByOpacity(opacity),
1055 TimePeriod(delaySeconds, durationSeconds) ) );
1058 void Animation::OpacityTo(Actor& actor, float opacity)
1060 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1063 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
1065 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
1068 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1070 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1072 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1074 Property::INVALID_COMPONENT_INDEX,
1075 AnimateToOpacity(opacity),
1077 TimePeriod(delaySeconds, durationSeconds) ) );
1080 void Animation::ColorBy(Actor& actor, const Vector4& color)
1082 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1085 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
1087 ColorBy(actor, color, alpha, 0.0f, GetDuration());
1090 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1092 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1094 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1096 Property::INVALID_COMPONENT_INDEX,
1097 AnimateByVector4(color),
1099 TimePeriod(delaySeconds, durationSeconds) ) );
1102 void Animation::ColorTo(Actor& actor, const Vector4& color)
1104 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1107 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1109 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1112 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1114 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1116 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1118 Property::INVALID_COMPONENT_INDEX,
1119 AnimateToVector4(color),
1121 TimePeriod(delaySeconds, durationSeconds) ) );
1124 void Animation::Resize(Actor& actor, float width, float height)
1126 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1129 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1131 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1134 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1136 Vector3 targetSize( width, height, min(width, height) );
1138 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1140 // notify the actor impl that its size is being animated
1141 actor.OnSizeAnimation( *this, targetSize );
1143 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1145 Property::INVALID_COMPONENT_INDEX,
1146 AnimateToVector3(targetSize),
1148 TimePeriod(delaySeconds, durationSeconds) ) );
1151 void Animation::Resize(Actor& actor, const Vector3& size)
1153 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1156 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1158 Resize(actor, size, alpha, 0.0f, GetDuration());
1161 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1163 ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
1165 // notify the actor impl that its size is being animated
1166 actor.OnSizeAnimation( *this, size );
1168 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1170 Property::INVALID_COMPONENT_INDEX,
1171 AnimateToVector3(size),
1173 TimePeriod(delaySeconds, durationSeconds) ) );
1176 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1179 Animation* animation = dynamic_cast<Animation*>(object);
1183 if(Dali::Animation::ACTION_PLAY == actionName)
1185 if(attributes.size() > 0)
1187 animation->SetDuration(attributes[0].Get<float>());
1193 else if(Dali::Animation::ACTION_STOP == actionName)
1198 else if(Dali::Animation::ACTION_PAUSE == actionName)
1208 float Animation::GetCurrentProgress()
1212 return mAnimation->GetCurrentProgress();
1218 void Animation::SetCurrentProgress(float progress)
1220 if( mAnimation && progress >= 0.0f && progress <= 1.0f )
1222 // mAnimation is being used in a separate thread; queue a message to set the current progress
1223 SetCurrentProgressMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
1227 void Animation::ExtendDuration( const TimePeriod& timePeriod )
1229 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
1231 if( duration > mDurationSeconds )
1233 SetDuration( duration );
1237 } // namespace Internal