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 switch ( relativeValue.GetType() )
291 case Property::BOOLEAN:
293 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
294 target.propertyIndex,
295 target.componentIndex,
296 AnimateByBoolean(relativeValue.Get<bool>()),
302 case Property::FLOAT:
304 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
305 target.propertyIndex,
306 target.componentIndex,
307 AnimateByFloat(relativeValue.Get<float>()),
313 case Property::INTEGER:
315 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
316 target.propertyIndex,
317 target.componentIndex,
318 AnimateByInteger(relativeValue.Get<int>()),
324 case Property::VECTOR2:
326 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
327 target.propertyIndex,
328 target.componentIndex,
329 AnimateByVector2(relativeValue.Get<Vector2>()),
335 case Property::VECTOR3:
337 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
338 target.propertyIndex,
339 target.componentIndex,
340 AnimateByVector3(relativeValue.Get<Vector3>()),
346 case Property::VECTOR4:
348 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
349 target.propertyIndex,
350 target.componentIndex,
351 AnimateByVector4(relativeValue.Get<Vector4>()),
357 case Property::ROTATION:
359 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
361 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
362 target.propertyIndex,
363 target.componentIndex,
364 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
371 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
376 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
378 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
381 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
383 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
386 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
388 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
391 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
393 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
395 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
398 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
400 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
401 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
403 if( type == Property::VECTOR2
404 || type == Property::VECTOR3
405 || type == Property::VECTOR4 )
407 type = Property::FLOAT;
410 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
412 switch (destinationValue.GetType())
414 case Property::BOOLEAN:
416 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
419 AnimateToBoolean(destinationValue.Get<bool>()),
425 case Property::FLOAT:
427 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
430 AnimateToFloat(destinationValue.Get<float>()),
436 case Property::INTEGER:
438 AddAnimatorConnector( AnimatorConnector<int>::New(targetObject,
441 AnimateToInteger(destinationValue.Get<int>()),
447 case Property::VECTOR2:
449 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
452 AnimateToVector2(destinationValue.Get<Vector2>()),
458 case Property::VECTOR3:
460 if ( Dali::Actor::SIZE == targetPropertyIndex )
462 // Test whether this is actually an Actor
463 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
466 // Notify the actor that its size is being animated
467 maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
471 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
474 AnimateToVector3(destinationValue.Get<Vector3>()),
480 case Property::VECTOR4:
482 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
485 AnimateToVector4(destinationValue.Get<Vector4>()),
491 case Property::ROTATION:
493 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
496 RotateToQuaternion(destinationValue.Get<Quaternion>()),
503 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
508 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
510 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
513 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
515 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
518 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
520 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
523 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
525 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
527 switch(keyFrames.GetType())
529 case Dali::Property::BOOLEAN:
531 const KeyFrameBoolean* kf;
532 GetSpecialization(keyFrames, kf);
533 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
534 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
535 target.propertyIndex,
536 target.componentIndex,
537 KeyFrameBooleanFunctor(kfCopy),
543 case Dali::Property::FLOAT:
545 const KeyFrameNumber* kf;
546 GetSpecialization(keyFrames, kf);
547 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
548 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
549 target.propertyIndex,
550 target.componentIndex,
551 KeyFrameNumberFunctor(kfCopy),
557 case Dali::Property::INTEGER:
559 const KeyFrameInteger* kf;
560 GetSpecialization(keyFrames, kf);
561 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
562 AddAnimatorConnector( AnimatorConnector<int>::New( proxy,
563 target.propertyIndex,
564 target.componentIndex,
565 KeyFrameIntegerFunctor(kfCopy),
571 case Dali::Property::VECTOR2:
573 const KeyFrameVector2* kf;
574 GetSpecialization(keyFrames, kf);
575 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
576 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
577 target.propertyIndex,
578 target.componentIndex,
579 KeyFrameVector2Functor(kfCopy),
585 case Dali::Property::VECTOR3:
587 const KeyFrameVector3* kf;
588 GetSpecialization(keyFrames, kf);
589 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
590 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
591 target.propertyIndex,
592 target.componentIndex,
593 KeyFrameVector3Functor(kfCopy),
599 case Dali::Property::VECTOR4:
601 const KeyFrameVector4* kf;
602 GetSpecialization(keyFrames, kf);
603 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
604 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
605 target.propertyIndex,
606 target.componentIndex,
607 KeyFrameVector4Functor(kfCopy),
613 case Dali::Property::ROTATION:
615 const KeyFrameQuaternion* kf;
616 GetSpecialization(keyFrames, kf);
617 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
618 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
619 target.propertyIndex,
620 target.componentIndex,
621 KeyFrameQuaternionFunctor(kfCopy),
627 default: // not all property types are animateable
632 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
634 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
637 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
639 Animate( target, targetType, func, alpha, mDurationSeconds );
642 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
644 Animate( target, targetType, func, mDefaultAlpha, period );
647 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
649 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
650 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
652 if( type == Property::VECTOR2
653 || type == Property::VECTOR3
654 || type == Property::VECTOR4 )
656 type = Property::FLOAT;
659 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
661 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
663 switch ( targetType )
665 case Property::BOOLEAN:
667 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
668 target.propertyIndex,
669 target.componentIndex,
670 AnyCast< AnimatorFunctionBool >( func ),
676 case Property::FLOAT:
678 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
679 target.propertyIndex,
680 target.componentIndex,
681 AnyCast< AnimatorFunctionFloat >( func ),
687 case Property::INTEGER:
689 AddAnimatorConnector( AnimatorConnector<int>::New(proxy,
690 target.propertyIndex,
691 target.componentIndex,
692 AnyCast< AnimatorFunctionInteger >( func ),
698 case Property::VECTOR2:
700 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
701 target.propertyIndex,
702 target.componentIndex,
703 AnyCast< AnimatorFunctionVector2 >( func ),
709 case Property::VECTOR3:
711 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
712 target.propertyIndex,
713 target.componentIndex,
714 AnyCast< AnimatorFunctionVector3 >( func ),
720 case Property::VECTOR4:
722 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
723 target.propertyIndex,
724 target.componentIndex,
725 AnyCast< AnimatorFunctionVector4 >( func ),
731 case Property::ROTATION:
733 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
734 target.propertyIndex,
735 target.componentIndex,
736 AnyCast< AnimatorFunctionQuaternion >( func ),
743 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
748 bool Animation::HasFinished()
750 bool hasFinished(false);
751 const int playCount(mAnimation->GetPlayCount());
753 // If the play count has been incremented, then another notification is required
754 if (playCount > mNotificationCount)
756 // Note that only one signal is emitted, if the animation has been played repeatedly
757 mNotificationCount = playCount;
765 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
767 return mFinishedSignal;
770 void Animation::EmitSignalFinish()
772 if ( !mFinishedSignal.Empty() )
774 Dali::Animation handle( this );
775 mFinishedSignal.Emit( handle );
778 // This callback is used internally, to avoid the overhead of using a signal.
779 if ( mFinishedCallback )
781 mFinishedCallback( mFinishedCallbackObject );
785 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
787 bool connected( true );
788 Animation* animation = dynamic_cast<Animation*>(object);
790 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
792 animation->FinishedSignal().Connect( tracker, functor );
796 // signalName does not match any signal
803 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
805 mFinishedCallback = callback;
806 mFinishedCallbackObject = object;
809 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
811 DALI_ASSERT_DEBUG( NULL != connector );
813 connector->SetParent(*this);
815 mConnectors.PushBack( connector );
818 void Animation::MoveBy(Actor& actor, float x, float y, float z)
820 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
823 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
825 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
828 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
830 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
831 Dali::Actor::POSITION,
832 Property::INVALID_COMPONENT_INDEX,
833 AnimateByVector3(displacement),
835 TimePeriod(delaySeconds, durationSeconds) ) );
838 void Animation::MoveTo(Actor& actor, float x, float y, float z)
840 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
843 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
845 MoveTo(actor, position, alpha, 0.0f, GetDuration());
848 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
850 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
851 Dali::Actor::POSITION,
852 Property::INVALID_COMPONENT_INDEX,
853 AnimateToVector3(position),
855 TimePeriod(delaySeconds, durationSeconds) ) );
858 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
860 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
861 Dali::Actor::POSITION,
862 Property::INVALID_COMPONENT_INDEX,
865 TimePeriod(delaySeconds, durationSeconds) ) );
868 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
870 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
873 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
875 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
878 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
880 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
881 Dali::Actor::ROTATION,
882 Property::INVALID_COMPONENT_INDEX,
883 RotateByAngleAxis(angle, axis),
885 TimePeriod(delaySeconds, durationSeconds) ) );
888 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
890 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
891 normalizedAxis.Normalize();
893 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
895 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
898 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
900 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
903 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
905 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
906 normalizedAxis.Normalize();
908 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
910 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
913 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
915 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
918 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
920 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
921 normalizedAxis.Normalize();
923 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
925 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
928 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
930 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
931 Dali::Actor::ROTATION,
932 Property::INVALID_COMPONENT_INDEX,
933 RotateToQuaternion(rotation),
935 TimePeriod(delaySeconds, durationSeconds) ) );
938 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
940 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
941 Dali::Actor::ROTATION,
942 Property::INVALID_COMPONENT_INDEX,
945 TimePeriod(delaySeconds, durationSeconds) ) );
948 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
950 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
953 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
955 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
958 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
960 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
962 Property::INVALID_COMPONENT_INDEX,
963 AnimateByVector3(scale),
965 TimePeriod(delaySeconds, durationSeconds) ) );
968 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
970 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
973 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
975 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
978 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
980 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
982 Property::INVALID_COMPONENT_INDEX,
983 AnimateToVector3(scale),
985 TimePeriod(delaySeconds, durationSeconds) ) );
988 void Animation::Show(Actor& actor, float delaySeconds)
990 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
991 Dali::Actor::VISIBLE,
992 Property::INVALID_COMPONENT_INDEX,
993 AnimateToBoolean(SHOW_VALUE),
994 AlphaFunctions::Default,
995 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
998 void Animation::Hide(Actor& actor, float delaySeconds)
1000 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
1001 Dali::Actor::VISIBLE,
1002 Property::INVALID_COMPONENT_INDEX,
1003 AnimateToBoolean(HIDE_VALUE),
1004 AlphaFunctions::Default,
1005 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
1008 void Animation::OpacityBy(Actor& actor, float opacity)
1010 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1013 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
1015 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
1018 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1020 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1022 Property::INVALID_COMPONENT_INDEX,
1023 AnimateByOpacity(opacity),
1025 TimePeriod(delaySeconds, durationSeconds) ) );
1028 void Animation::OpacityTo(Actor& actor, float opacity)
1030 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
1033 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
1035 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
1038 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1040 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1042 Property::INVALID_COMPONENT_INDEX,
1043 AnimateToOpacity(opacity),
1045 TimePeriod(delaySeconds, durationSeconds) ) );
1048 void Animation::ColorBy(Actor& actor, const Vector4& color)
1050 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1053 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
1055 ColorBy(actor, color, alpha, 0.0f, GetDuration());
1058 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1060 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1062 Property::INVALID_COMPONENT_INDEX,
1063 AnimateByVector4(color),
1065 TimePeriod(delaySeconds, durationSeconds) ) );
1068 void Animation::ColorTo(Actor& actor, const Vector4& color)
1070 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1073 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1075 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1078 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1080 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1082 Property::INVALID_COMPONENT_INDEX,
1083 AnimateToVector4(color),
1085 TimePeriod(delaySeconds, durationSeconds) ) );
1088 void Animation::Resize(Actor& actor, float width, float height)
1090 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1093 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1095 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1098 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1100 Vector3 targetSize( width, height, min(width, height) );
1102 // notify the actor impl that its size is being animated
1103 actor.OnSizeAnimation( *this, targetSize );
1105 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1107 Property::INVALID_COMPONENT_INDEX,
1108 AnimateToVector3(targetSize),
1110 TimePeriod(delaySeconds, durationSeconds) ) );
1113 void Animation::Resize(Actor& actor, const Vector3& size)
1115 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1118 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1120 Resize(actor, size, alpha, 0.0f, GetDuration());
1123 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1125 // notify the actor impl that its size is being animated
1126 actor.OnSizeAnimation( *this, size );
1128 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1130 Property::INVALID_COMPONENT_INDEX,
1131 AnimateToVector3(size),
1133 TimePeriod(delaySeconds, durationSeconds) ) );
1136 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin)
1138 ParentOriginTo(actor, parentOrigin, mDefaultAlpha, 0.0f, GetDuration());
1141 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha)
1143 ParentOriginTo(actor, parentOrigin, alpha, 0.0f, GetDuration());
1146 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1148 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1149 Dali::Actor::PARENT_ORIGIN,
1150 Property::INVALID_COMPONENT_INDEX,
1151 AnimateToVector3(parentOrigin),
1153 TimePeriod(delaySeconds, durationSeconds) ) );
1156 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint)
1158 AnchorPointTo(actor, anchorPoint, mDefaultAlpha, 0.0f, GetDuration());
1161 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha)
1163 AnchorPointTo(actor, anchorPoint, alpha, 0.0f, GetDuration());
1166 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1168 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1169 Dali::Actor::ANCHOR_POINT,
1170 Property::INVALID_COMPONENT_INDEX,
1171 AnimateToVector3(anchorPoint),
1173 TimePeriod(delaySeconds, durationSeconds) ) );
1176 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value )
1178 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1181 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha )
1183 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1186 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1188 Property::Value propertyValue( value );
1190 // Register the property if it does not exist
1191 Property::Index index = shaderEffect.GetPropertyIndex( name );
1192 if ( Property::INVALID_INDEX == index )
1194 index = shaderEffect.RegisterProperty( name, propertyValue );
1197 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1200 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value )
1202 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration());
1205 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha )
1207 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1210 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1212 Property::Value propertyValue( value );
1214 // Register the property if it does not exist
1215 Property::Index index = shaderEffect.GetPropertyIndex( name );
1216 if ( Property::INVALID_INDEX == index )
1218 index = shaderEffect.RegisterProperty( name, propertyValue );
1221 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1224 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value )
1226 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1229 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha )
1231 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1234 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1236 Property::Value propertyValue( value );
1238 // Register the property if it does not exist
1239 Property::Index index = shaderEffect.GetPropertyIndex( name );
1240 if ( Property::INVALID_INDEX == index )
1242 index = shaderEffect.RegisterProperty( name, propertyValue );
1245 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1248 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value )
1250 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1253 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha )
1255 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1258 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1260 Property::Value propertyValue( value );
1262 // Register the property if it does not exist
1263 Property::Index index = shaderEffect.GetPropertyIndex( name );
1264 if ( Property::INVALID_INDEX == index )
1266 index = shaderEffect.RegisterProperty( name, propertyValue );
1269 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1272 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1275 Animation* animation = dynamic_cast<Animation*>(object);
1279 if(Dali::Animation::ACTION_PLAY == actionName)
1281 if(attributes.size() > 0)
1283 animation->SetDuration(attributes[0].Get<float>());
1289 else if(Dali::Animation::ACTION_STOP == actionName)
1294 else if(Dali::Animation::ACTION_PAUSE == actionName)
1304 float Animation::GetCurrentProgress()
1308 return mAnimation->GetCurrentProgress();
1314 void Animation::SetCurrentProgress(float progress)
1316 if( mAnimation && progress >= 0.0f && progress <= 1.0f )
1318 // mAnimation is being used in a separate thread; queue a message to set the current progress
1319 SetCurrentProgressMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
1323 } // namespace Internal