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::VECTOR2:
315 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
316 target.propertyIndex,
317 target.componentIndex,
318 AnimateByVector2(relativeValue.Get<Vector2>()),
324 case Property::VECTOR3:
326 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
327 target.propertyIndex,
328 target.componentIndex,
329 AnimateByVector3(relativeValue.Get<Vector3>()),
335 case Property::VECTOR4:
337 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
338 target.propertyIndex,
339 target.componentIndex,
340 AnimateByVector4(relativeValue.Get<Vector4>()),
346 case Property::ROTATION:
348 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
350 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
351 target.propertyIndex,
352 target.componentIndex,
353 RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
360 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
365 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
367 AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
370 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
372 AnimateTo(target, destinationValue, alpha, mDurationSeconds);
375 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
377 AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
380 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
382 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
384 AnimateTo( proxy, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
387 void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
389 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
390 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
392 if( type == Property::VECTOR2
393 || type == Property::VECTOR3
394 || type == Property::VECTOR4 )
396 type = Property::FLOAT;
399 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
401 switch (destinationValue.GetType())
403 case Property::BOOLEAN:
405 AddAnimatorConnector( AnimatorConnector<bool>::New(targetObject,
408 AnimateToBoolean(destinationValue.Get<bool>()),
414 case Property::FLOAT:
416 AddAnimatorConnector( AnimatorConnector<float>::New(targetObject,
419 AnimateToFloat(destinationValue.Get<float>()),
425 case Property::VECTOR2:
427 AddAnimatorConnector( AnimatorConnector<Vector2>::New(targetObject,
430 AnimateToVector2(destinationValue.Get<Vector2>()),
436 case Property::VECTOR3:
438 if ( Dali::Actor::SIZE == targetPropertyIndex )
440 // Test whether this is actually an Actor
441 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
444 // Notify the actor that its size is being animated
445 maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
449 AddAnimatorConnector( AnimatorConnector<Vector3>::New(targetObject,
452 AnimateToVector3(destinationValue.Get<Vector3>()),
458 case Property::VECTOR4:
460 AddAnimatorConnector( AnimatorConnector<Vector4>::New(targetObject,
463 AnimateToVector4(destinationValue.Get<Vector4>()),
469 case Property::ROTATION:
471 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(targetObject,
474 RotateToQuaternion(destinationValue.Get<Quaternion>()),
481 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
486 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
488 AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds);
491 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
493 AnimateBetween(target, keyFrames, mDefaultAlpha, period);
496 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
498 AnimateBetween(target, keyFrames, alpha, mDurationSeconds);
501 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
503 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
505 switch(keyFrames.GetType())
507 case Dali::Property::BOOLEAN:
509 const KeyFrameBoolean* kf;
510 GetSpecialization(keyFrames, kf);
511 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
512 AddAnimatorConnector( AnimatorConnector<bool>::New( proxy,
513 target.propertyIndex,
514 target.componentIndex,
515 KeyFrameBooleanFunctor(kfCopy),
520 case Dali::Property::FLOAT:
522 const KeyFrameNumber* kf;
523 GetSpecialization(keyFrames, kf);
524 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
525 AddAnimatorConnector( AnimatorConnector<float>::New( proxy,
526 target.propertyIndex,
527 target.componentIndex,
528 KeyFrameNumberFunctor(kfCopy),
534 case Dali::Property::VECTOR2:
536 const KeyFrameVector2* kf;
537 GetSpecialization(keyFrames, kf);
538 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
539 AddAnimatorConnector( AnimatorConnector<Vector2>::New( proxy,
540 target.propertyIndex,
541 target.componentIndex,
542 KeyFrameVector2Functor(kfCopy),
548 case Dali::Property::VECTOR3:
550 const KeyFrameVector3* kf;
551 GetSpecialization(keyFrames, kf);
552 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
553 AddAnimatorConnector( AnimatorConnector<Vector3>::New( proxy,
554 target.propertyIndex,
555 target.componentIndex,
556 KeyFrameVector3Functor(kfCopy),
562 case Dali::Property::VECTOR4:
564 const KeyFrameVector4* kf;
565 GetSpecialization(keyFrames, kf);
566 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
567 AddAnimatorConnector( AnimatorConnector<Vector4>::New( proxy,
568 target.propertyIndex,
569 target.componentIndex,
570 KeyFrameVector4Functor(kfCopy),
576 case Dali::Property::ROTATION:
578 const KeyFrameQuaternion* kf;
579 GetSpecialization(keyFrames, kf);
580 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
581 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( proxy,
582 target.propertyIndex,
583 target.componentIndex,
584 KeyFrameQuaternionFunctor(kfCopy),
590 default: // not all property types are animateable
595 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func )
597 Animate( target, targetType, func, mDefaultAlpha, mDurationSeconds );
600 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha )
602 Animate( target, targetType, func, alpha, mDurationSeconds );
605 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period )
607 Animate( target, targetType, func, mDefaultAlpha, period );
610 void Animation::Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period )
612 Property::Type type = target.object.GetPropertyType(target.propertyIndex);
613 if(target.componentIndex != Property::INVALID_COMPONENT_INDEX)
615 if( type == Property::VECTOR2
616 || type == Property::VECTOR3
617 || type == Property::VECTOR4 )
619 type = Property::FLOAT;
622 DALI_ASSERT_ALWAYS( type == targetType && "Animation function must match target property type" );
624 ProxyObject& proxy = dynamic_cast<ProxyObject&>( GetImplementation(target.object) );
626 switch ( targetType )
628 case Property::BOOLEAN:
630 AddAnimatorConnector( AnimatorConnector<bool>::New(proxy,
631 target.propertyIndex,
632 target.componentIndex,
633 AnyCast< AnimatorFunctionBool >( func ),
639 case Property::FLOAT:
641 AddAnimatorConnector( AnimatorConnector<float>::New(proxy,
642 target.propertyIndex,
643 target.componentIndex,
644 AnyCast< AnimatorFunctionFloat >( func ),
650 case Property::VECTOR2:
652 AddAnimatorConnector( AnimatorConnector<Vector2>::New(proxy,
653 target.propertyIndex,
654 target.componentIndex,
655 AnyCast< AnimatorFunctionVector2 >( func ),
661 case Property::VECTOR3:
663 AddAnimatorConnector( AnimatorConnector<Vector3>::New(proxy,
664 target.propertyIndex,
665 target.componentIndex,
666 AnyCast< AnimatorFunctionVector3 >( func ),
672 case Property::VECTOR4:
674 AddAnimatorConnector( AnimatorConnector<Vector4>::New(proxy,
675 target.propertyIndex,
676 target.componentIndex,
677 AnyCast< AnimatorFunctionVector4 >( func ),
683 case Property::ROTATION:
685 AddAnimatorConnector( AnimatorConnector<Quaternion>::New(proxy,
686 target.propertyIndex,
687 target.componentIndex,
688 AnyCast< AnimatorFunctionQuaternion >( func ),
695 DALI_ASSERT_ALWAYS(false && "Property type enumeration out of bounds" ); // should never come here
700 bool Animation::HasFinished()
702 bool hasFinished(false);
703 const int playCount(mAnimation->GetPlayCount());
705 // If the play count has been incremented, then another notification is required
706 if (playCount > mNotificationCount)
708 // Note that only one signal is emitted, if the animation has been played repeatedly
709 mNotificationCount = playCount;
717 Dali::Animation::AnimationSignalV2& Animation::FinishedSignal()
719 return mFinishedSignal;
722 void Animation::EmitSignalFinish()
724 if ( !mFinishedSignal.Empty() )
726 Dali::Animation handle( this );
727 mFinishedSignal.Emit( handle );
730 // This callback is used internally, to avoid the overhead of using a signal.
731 if ( mFinishedCallback )
733 mFinishedCallback( mFinishedCallbackObject );
737 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
739 bool connected( true );
740 Animation* animation = dynamic_cast<Animation*>(object);
742 if ( Dali::Animation::SIGNAL_FINISHED == signalName )
744 animation->FinishedSignal().Connect( tracker, functor );
748 // signalName does not match any signal
755 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
757 mFinishedCallback = callback;
758 mFinishedCallbackObject = object;
761 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
763 DALI_ASSERT_DEBUG( NULL != connector );
765 connector->SetParent(*this);
767 mConnectors.PushBack( connector );
770 void Animation::MoveBy(Actor& actor, float x, float y, float z)
772 MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
775 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
777 MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
780 void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
782 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
783 Dali::Actor::POSITION,
784 Property::INVALID_COMPONENT_INDEX,
785 AnimateByVector3(displacement),
787 TimePeriod(delaySeconds, durationSeconds) ) );
790 void Animation::MoveTo(Actor& actor, float x, float y, float z)
792 MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
795 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
797 MoveTo(actor, position, alpha, 0.0f, GetDuration());
800 void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
802 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
803 Dali::Actor::POSITION,
804 Property::INVALID_COMPONENT_INDEX,
805 AnimateToVector3(position),
807 TimePeriod(delaySeconds, durationSeconds) ) );
810 void Animation::Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
812 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
813 Dali::Actor::POSITION,
814 Property::INVALID_COMPONENT_INDEX,
817 TimePeriod(delaySeconds, durationSeconds) ) );
820 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
822 RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
825 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
827 RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
830 void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
832 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
833 Dali::Actor::ROTATION,
834 Property::INVALID_COMPONENT_INDEX,
835 RotateByAngleAxis(angle, axis),
837 TimePeriod(delaySeconds, durationSeconds) ) );
840 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
842 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
843 normalizedAxis.Normalize();
845 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
847 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
850 void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
852 RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
855 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
857 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
858 normalizedAxis.Normalize();
860 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
862 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
865 void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
867 RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
870 void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
872 Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
873 normalizedAxis.Normalize();
875 Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
877 RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
880 void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
882 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
883 Dali::Actor::ROTATION,
884 Property::INVALID_COMPONENT_INDEX,
885 RotateToQuaternion(rotation),
887 TimePeriod(delaySeconds, durationSeconds) ) );
890 void Animation::Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds)
892 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
893 Dali::Actor::ROTATION,
894 Property::INVALID_COMPONENT_INDEX,
897 TimePeriod(delaySeconds, durationSeconds) ) );
900 void Animation::ScaleBy(Actor& actor, float x, float y, float z)
902 ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
905 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
907 ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
910 void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
912 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
914 Property::INVALID_COMPONENT_INDEX,
915 AnimateByVector3(scale),
917 TimePeriod(delaySeconds, durationSeconds) ) );
920 void Animation::ScaleTo(Actor& actor, float x, float y, float z)
922 ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
925 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
927 ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
930 void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
932 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
934 Property::INVALID_COMPONENT_INDEX,
935 AnimateToVector3(scale),
937 TimePeriod(delaySeconds, durationSeconds) ) );
940 void Animation::Show(Actor& actor, float delaySeconds)
942 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
943 Dali::Actor::VISIBLE,
944 Property::INVALID_COMPONENT_INDEX,
945 AnimateToBoolean(SHOW_VALUE),
946 AlphaFunctions::Default,
947 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
950 void Animation::Hide(Actor& actor, float delaySeconds)
952 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
953 Dali::Actor::VISIBLE,
954 Property::INVALID_COMPONENT_INDEX,
955 AnimateToBoolean(HIDE_VALUE),
956 AlphaFunctions::Default,
957 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
960 void Animation::OpacityBy(Actor& actor, float opacity)
962 OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
965 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
967 OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
970 void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
972 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
974 Property::INVALID_COMPONENT_INDEX,
975 AnimateByOpacity(opacity),
977 TimePeriod(delaySeconds, durationSeconds) ) );
980 void Animation::OpacityTo(Actor& actor, float opacity)
982 OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
985 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
987 OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
990 void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
992 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
994 Property::INVALID_COMPONENT_INDEX,
995 AnimateToOpacity(opacity),
997 TimePeriod(delaySeconds, durationSeconds) ) );
1000 void Animation::ColorBy(Actor& actor, const Vector4& color)
1002 ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1005 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
1007 ColorBy(actor, color, alpha, 0.0f, GetDuration());
1010 void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1012 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1014 Property::INVALID_COMPONENT_INDEX,
1015 AnimateByVector4(color),
1017 TimePeriod(delaySeconds, durationSeconds) ) );
1020 void Animation::ColorTo(Actor& actor, const Vector4& color)
1022 ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
1025 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
1027 ColorTo(actor, color, alpha, 0.0f, GetDuration());
1030 void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1032 AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
1034 Property::INVALID_COMPONENT_INDEX,
1035 AnimateToVector4(color),
1037 TimePeriod(delaySeconds, durationSeconds) ) );
1040 void Animation::Resize(Actor& actor, float width, float height)
1042 Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
1045 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
1047 Resize(actor, width, height, alpha, 0.0f, GetDuration());
1050 void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1052 Vector3 targetSize( width, height, min(width, height) );
1054 // notify the actor impl that its size is being animated
1055 actor.OnSizeAnimation( *this, targetSize );
1057 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1059 Property::INVALID_COMPONENT_INDEX,
1060 AnimateToVector3(targetSize),
1062 TimePeriod(delaySeconds, durationSeconds) ) );
1065 void Animation::Resize(Actor& actor, const Vector3& size)
1067 Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
1070 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
1072 Resize(actor, size, alpha, 0.0f, GetDuration());
1075 void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1077 // notify the actor impl that its size is being animated
1078 actor.OnSizeAnimation( *this, size );
1080 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1082 Property::INVALID_COMPONENT_INDEX,
1083 AnimateToVector3(size),
1085 TimePeriod(delaySeconds, durationSeconds) ) );
1088 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin)
1090 ParentOriginTo(actor, parentOrigin, mDefaultAlpha, 0.0f, GetDuration());
1093 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha)
1095 ParentOriginTo(actor, parentOrigin, alpha, 0.0f, GetDuration());
1098 void Animation::ParentOriginTo(Actor& actor, const Vector3& parentOrigin, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1100 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1101 Dali::Actor::PARENT_ORIGIN,
1102 Property::INVALID_COMPONENT_INDEX,
1103 AnimateToVector3(parentOrigin),
1105 TimePeriod(delaySeconds, durationSeconds) ) );
1108 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint)
1110 AnchorPointTo(actor, anchorPoint, mDefaultAlpha, 0.0f, GetDuration());
1113 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha)
1115 AnchorPointTo(actor, anchorPoint, alpha, 0.0f, GetDuration());
1118 void Animation::AnchorPointTo(Actor& actor, const Vector3& anchorPoint, AlphaFunction alpha, float delaySeconds, float durationSeconds)
1120 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
1121 Dali::Actor::ANCHOR_POINT,
1122 Property::INVALID_COMPONENT_INDEX,
1123 AnimateToVector3(anchorPoint),
1125 TimePeriod(delaySeconds, durationSeconds) ) );
1128 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value )
1130 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1133 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha )
1135 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1138 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, float value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1140 Property::Value propertyValue( value );
1142 // Register the property if it does not exist
1143 Property::Index index = shaderEffect.GetPropertyIndex( name );
1144 if ( Property::INVALID_INDEX == index )
1146 index = shaderEffect.RegisterProperty( name, propertyValue );
1149 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1152 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value )
1154 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration());
1157 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha )
1159 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1162 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector2 value, AlphaFunction alpha, float delaySeconds, float durationSeconds )
1164 Property::Value propertyValue( value );
1166 // Register the property if it does not exist
1167 Property::Index index = shaderEffect.GetPropertyIndex( name );
1168 if ( Property::INVALID_INDEX == index )
1170 index = shaderEffect.RegisterProperty( name, propertyValue );
1173 AnimateTo( shaderEffect, index, Property::INVALID_COMPONENT_INDEX, propertyValue, alpha, TimePeriod(delaySeconds, durationSeconds) );
1176 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value )
1178 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1181 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 value, AlphaFunction alpha )
1183 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1186 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector3 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, Vector4 value )
1202 AnimateProperty( shaderEffect, name, value, GetDefaultAlphaFunction(), 0, GetDuration() );
1205 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 value, AlphaFunction alpha )
1207 AnimateProperty( shaderEffect, name, value, alpha, 0, GetDuration() );
1210 void Animation::AnimateProperty( Internal::ShaderEffect& shaderEffect, const std::string& name, Vector4 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 bool Animation::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
1227 Animation* animation = dynamic_cast<Animation*>(object);
1231 if(Dali::Animation::ACTION_PLAY == actionName)
1233 if(attributes.size() > 0)
1235 animation->SetDuration(attributes[0].Get<float>());
1241 else if(Dali::Animation::ACTION_STOP == actionName)
1246 else if(Dali::Animation::ACTION_PAUSE == actionName)
1256 float Animation::GetCurrentProgress()
1260 return mAnimation->GetCurrentProgress();
1266 void Animation::SetCurrentProgress(float progress)
1268 if( mAnimation && progress >= 0.0f && progress <= 1.0f )
1270 // mAnimation is being used in a separate thread; queue a message to set the current progress
1271 SetCurrentProgressMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
1275 } // namespace Internal