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>
20 #include <dali/public-api/object/property-map.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/animation/alpha-function.h>
27 #include <dali/public-api/animation/time-period.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/math/vector2.h>
31 #include <dali/public-api/math/radian.h>
32 #include <dali/internal/event/actors/actor-impl.h>
33 #include <dali/internal/event/animation/animation-playlist.h>
34 #include <dali/internal/event/animation/animator-connector.h>
35 #include <dali/internal/event/common/notification-manager.h>
36 #include <dali/internal/event/common/property-helper.h>
37 #include <dali/internal/event/common/stage-impl.h>
38 #include <dali/internal/event/common/thread-local-storage.h>
39 #include <dali/internal/event/effects/shader-effect-impl.h>
40 #include <dali/internal/update/manager/update-manager.h>
42 using Dali::Internal::SceneGraph::UpdateManager;
43 using Dali::Internal::SceneGraph::AnimatorBase;
44 using Dali::Internal::SceneGraph::Shader;
52 static bool SHOW_VALUE = true;
53 static bool HIDE_VALUE = false;
60 const char* const SIGNAL_FINISHED = "finished";
64 const char* const ACTION_PLAY = "play";
65 const char* const ACTION_STOP = "stop";
66 const char* const ACTION_PAUSE = "pause";
70 return Dali::Animation::New(0.f);
73 TypeRegistration mType( typeid( Dali::Animation ), typeid( Dali::BaseHandle ), Create );
75 SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &Animation::DoConnectSignal );
77 TypeAction action1( mType, ACTION_PLAY, &Animation::DoAction );
78 TypeAction action2( mType, ACTION_STOP, &Animation::DoAction );
79 TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction );
81 const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::Bake );
82 const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BakeFinal );
83 const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear );
84 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
89 AnimationPtr Animation::New(float durationSeconds)
91 Stage* stage = Stage::GetCurrent();
95 AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
97 if( durationSeconds < 0.0f )
99 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
100 durationSeconds = 0.0f;
103 AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
105 // Second-phase construction
106 animation->Initialize();
116 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
117 : mEventThreadServices( eventThreadServices ),
118 mPlaylist( playlist ),
120 mNotificationCount( 0 ),
121 mFinishedCallback( NULL ),
122 mFinishedCallbackObject( NULL ),
123 mDurationSeconds( durationSeconds ),
127 mPlayRange( Vector2(0.0f,1.0f)),
128 mEndAction( endAction ),
129 mDisconnectAction( disconnectAction ),
130 mDefaultAlpha( defaultAlpha )
134 void Animation::Initialize()
136 // Connect to the animation playlist
137 mPlaylist.AnimationCreated( *this );
144 Animation::~Animation()
146 // Guard to allow handle destruction after Core has been destroyed
147 if ( Stage::IsInstalled() )
149 // Disconnect from the animation playlist
150 mPlaylist.AnimationDestroyed( *this );
152 DestroySceneObject();
158 void Animation::CreateSceneObject()
160 DALI_ASSERT_DEBUG( mAnimation == NULL );
162 // Create a new animation, temporarily owned
163 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction );
165 // Keep a const pointer to the animation.
166 mAnimation = animation;
168 // Transfer animation ownership to the update manager through a message
169 AddAnimationMessage( mEventThreadServices.GetUpdateManager(), animation );
172 void Animation::DestroySceneObject()
174 if ( mAnimation != NULL )
176 // Remove animation using a message to the update manager
177 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
182 void Animation::SetDuration(float seconds)
186 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
190 // Cache for public getters
191 mDurationSeconds = seconds;
193 // mAnimation is being used in a separate thread; queue a message to set the value
194 SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
197 float Animation::GetDuration() const
199 // This is not animatable; the cached value is up-to-date.
200 return mDurationSeconds;
203 void Animation::SetLooping(bool on)
205 SetLoopCount( on ? 0 : 1 );
208 void Animation::SetLoopCount(int count)
210 // Cache for public getters
213 // mAnimation is being used in a separate thread; queue a message to set the value
214 SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
217 int Animation::GetLoopCount()
222 int Animation::GetCurrentLoop()
227 bool Animation::IsLooping() const
229 return mLoopCount != 1;
232 void Animation::SetEndAction(EndAction action)
234 // Cache for public getters
237 // mAnimation is being used in a separate thread; queue a message to set the value
238 SetEndActionMessage( mEventThreadServices, *mAnimation, action );
241 Dali::Animation::EndAction Animation::GetEndAction() const
243 // This is not animatable; the cached value is up-to-date.
247 void Animation::SetDisconnectAction(EndAction action)
249 // Cache for public getters
250 mDisconnectAction = action;
252 // mAnimation is being used in a separate thread; queue a message to set the value
253 SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
256 Dali::Animation::EndAction Animation::GetDisconnectAction() const
258 // This is not animatable; the cached value is up-to-date.
259 return mDisconnectAction;
262 void Animation::Play()
264 // Update the current playlist
265 mPlaylist.OnPlay( *this );
267 // mAnimation is being used in a separate thread; queue a Play message
268 PlayAnimationMessage( mEventThreadServices, *mAnimation );
271 void Animation::PlayFrom( float progress )
273 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
275 // Update the current playlist
276 mPlaylist.OnPlay( *this );
278 // mAnimation is being used in a separate thread; queue a Play message
279 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
283 void Animation::Pause()
285 // mAnimation is being used in a separate thread; queue a Pause message
286 PauseAnimationMessage( mEventThreadServices, *mAnimation );
289 void Animation::Stop()
291 // mAnimation is being used in a separate thread; queue a Stop message
292 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
295 void Animation::Clear()
297 DALI_ASSERT_DEBUG(mAnimation);
299 // Remove all the connectors
302 // Replace the old scene-object with a new one
303 DestroySceneObject();
306 // Reset the notification count, since the new scene-object has never been played
307 mNotificationCount = 0;
309 // Update the current playlist
310 mPlaylist.OnClear( *this );
313 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
315 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
318 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
320 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
323 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
325 AnimateBy(target, relativeValue, mDefaultAlpha, period);
328 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
330 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
332 ExtendDuration( period );
334 switch ( relativeValue.GetType() )
336 case Property::BOOLEAN:
338 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
339 target.propertyIndex,
340 target.componentIndex,
341 new AnimateByBoolean(relativeValue.Get<bool>()),
347 case Property::INTEGER:
349 AddAnimatorConnector( AnimatorConnector<int>::New( object,
350 target.propertyIndex,
351 target.componentIndex,
352 new AnimateByInteger(relativeValue.Get<int>()),
358 case Property::FLOAT:
360 AddAnimatorConnector( AnimatorConnector<float>::New( object,
361 target.propertyIndex,
362 target.componentIndex,
363 new AnimateByFloat(relativeValue.Get<float>()),
369 case Property::VECTOR2:
371 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
372 target.propertyIndex,
373 target.componentIndex,
374 new AnimateByVector2(relativeValue.Get<Vector2>()),
380 case Property::VECTOR3:
382 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
383 target.propertyIndex,
384 target.componentIndex,
385 new AnimateByVector3(relativeValue.Get<Vector3>()),
391 case Property::VECTOR4:
393 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
394 target.propertyIndex,
395 target.componentIndex,
396 new AnimateByVector4(relativeValue.Get<Vector4>()),
402 case Property::ROTATION:
404 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
406 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
407 target.propertyIndex,
408 target.componentIndex,
409 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
416 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
421 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
423 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
426 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
428 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
431 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
433 AnimateTo(target, destinationValue, mDefaultAlpha, period);
436 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
438 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
440 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
443 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
445 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
446 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
448 if( type == Property::VECTOR2
449 || type == Property::VECTOR3
450 || type == Property::VECTOR4 )
452 type = Property::FLOAT;
455 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
457 ExtendDuration( period );
459 switch (destinationValue.GetType())
461 case Property::BOOLEAN:
463 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
466 new AnimateToBoolean( destinationValue.Get<bool>() ),
472 case Property::INTEGER:
474 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
477 new AnimateToInteger( destinationValue.Get<int>() ),
483 case Property::FLOAT:
485 if ( ( Dali::Actor::Property::SIZE_WIDTH == targetPropertyIndex ) ||
486 ( Dali::Actor::Property::SIZE_HEIGHT == targetPropertyIndex ) ||
487 ( Dali::Actor::Property::SIZE_DEPTH == targetPropertyIndex ) )
489 // Test whether this is actually an Actor
490 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
493 // Notify the actor that its size is being animated
494 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
497 else if ( ( Dali::Actor::Property::POSITION_X == targetPropertyIndex ) ||
498 ( Dali::Actor::Property::POSITION_Y == targetPropertyIndex ) ||
499 ( Dali::Actor::Property::POSITION_Z == targetPropertyIndex ) )
501 // Test whether this is actually an Actor
502 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
505 // Notify the actor that its position is being animated
506 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
510 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
513 new AnimateToFloat( destinationValue.Get<float>() ),
519 case Property::VECTOR2:
521 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
524 new AnimateToVector2( destinationValue.Get<Vector2>() ),
530 case Property::VECTOR3:
532 if ( Dali::Actor::Property::SIZE == targetPropertyIndex )
534 // Test whether this is actually an Actor
535 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
538 // Notify the actor that its size is being animated
539 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
542 else if ( Dali::Actor::Property::POSITION == targetPropertyIndex )
544 // Test whether this is actually an Actor
545 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
548 // Notify the actor that its position is being animated
549 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<Vector3>() );
553 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
556 new AnimateToVector3( destinationValue.Get<Vector3>() ),
562 case Property::VECTOR4:
564 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
567 new AnimateToVector4( destinationValue.Get<Vector4>() ),
573 case Property::ROTATION:
575 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
578 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
585 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
590 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
592 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
595 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
597 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
600 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
602 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
605 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
607 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
610 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
612 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
615 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
617 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
620 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
622 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
625 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
627 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
629 ExtendDuration( period );
631 switch(keyFrames.GetType())
633 case Dali::Property::BOOLEAN:
635 const KeyFrameBoolean* kf;
636 GetSpecialization(keyFrames, kf);
637 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
638 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
639 target.propertyIndex,
640 target.componentIndex,
641 new KeyFrameBooleanFunctor(kfCopy),
647 case Dali::Property::INTEGER:
649 const KeyFrameInteger* kf;
650 GetSpecialization(keyFrames, kf);
651 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
652 AddAnimatorConnector( AnimatorConnector<int>::New( object,
653 target.propertyIndex,
654 target.componentIndex,
655 new KeyFrameIntegerFunctor(kfCopy,interpolation),
661 case Dali::Property::FLOAT:
663 const KeyFrameNumber* kf;
664 GetSpecialization(keyFrames, kf);
665 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
666 AddAnimatorConnector( AnimatorConnector<float>::New( object,
667 target.propertyIndex,
668 target.componentIndex,
669 new KeyFrameNumberFunctor(kfCopy,interpolation),
675 case Dali::Property::VECTOR2:
677 const KeyFrameVector2* kf;
678 GetSpecialization(keyFrames, kf);
679 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
680 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
681 target.propertyIndex,
682 target.componentIndex,
683 new KeyFrameVector2Functor(kfCopy,interpolation),
689 case Dali::Property::VECTOR3:
691 const KeyFrameVector3* kf;
692 GetSpecialization(keyFrames, kf);
693 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
694 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
695 target.propertyIndex,
696 target.componentIndex,
697 new KeyFrameVector3Functor(kfCopy,interpolation),
703 case Dali::Property::VECTOR4:
705 const KeyFrameVector4* kf;
706 GetSpecialization(keyFrames, kf);
707 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
708 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
709 target.propertyIndex,
710 target.componentIndex,
711 new KeyFrameVector4Functor(kfCopy,interpolation),
717 case Dali::Property::ROTATION:
719 const KeyFrameQuaternion* kf;
720 GetSpecialization(keyFrames, kf);
721 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
722 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
723 target.propertyIndex,
724 target.componentIndex,
725 new KeyFrameQuaternionFunctor(kfCopy),
731 default: // not all property types are animateable
736 bool Animation::HasFinished()
738 bool hasFinished(false);
739 const int playedCount(mAnimation->GetPlayedCount());
741 // If the play count has been incremented, then another notification is required
742 mCurrentLoop = mAnimation->GetCurrentLoop();
744 if (playedCount > mNotificationCount)
746 // Note that only one signal is emitted, if the animation has been played repeatedly
747 mNotificationCount = playedCount;
755 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
757 return mFinishedSignal;
760 void Animation::EmitSignalFinish()
762 if ( !mFinishedSignal.Empty() )
764 Dali::Animation handle( this );
765 mFinishedSignal.Emit( handle );
768 // This callback is used internally, to avoid the overhead of using a signal.
769 if ( mFinishedCallback )
771 mFinishedCallback( mFinishedCallbackObject );
775 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
777 bool connected( true );
778 Animation* animation = dynamic_cast<Animation*>(object);
780 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
782 animation->FinishedSignal().Connect( tracker, functor );
786 // signalName does not match any signal
793 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
795 mFinishedCallback = callback;
796 mFinishedCallbackObject = object;
799 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
801 DALI_ASSERT_DEBUG( NULL != connector );
803 connector->SetParent(*this);
805 mConnectors.PushBack( connector );
808 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
810 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
813 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
815 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
818 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
820 Animate( actor, path, forward, mDefaultAlpha, period );
823 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
825 ExtendDuration( period );
827 PathPtr pathCopy = Path::Clone(path);
830 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
831 Dali::Actor::Property::POSITION,
832 Property::INVALID_COMPONENT_INDEX,
833 new PathPositionFunctor( pathCopy ),
837 //If forward is zero, PathRotationFunctor will always return the unit quaternion
838 if( forward != Vector3::ZERO )
841 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
842 Dali::Actor::Property::ORIENTATION,
843 Property::INVALID_COMPONENT_INDEX,
844 new PathRotationFunctor( pathCopy, forward ),
850 void Animation::Show(Actor& actor, float delaySeconds)
852 ExtendDuration( TimePeriod(delaySeconds, 0) );
854 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
855 Dali::Actor::Property::VISIBLE,
856 Property::INVALID_COMPONENT_INDEX,
857 new AnimateToBoolean(SHOW_VALUE),
859 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
862 void Animation::Hide(Actor& actor, float delaySeconds)
864 ExtendDuration( TimePeriod(delaySeconds, 0) );
866 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
867 Dali::Actor::Property::VISIBLE,
868 Property::INVALID_COMPONENT_INDEX,
869 new AnimateToBoolean(HIDE_VALUE),
871 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
874 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
877 Animation* animation = dynamic_cast<Animation*>( object );
881 if( 0 == actionName.compare( ACTION_PLAY ) )
883 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
885 animation->SetDuration( value->Get<float>() );
891 else if( 0 == actionName.compare( ACTION_STOP ) )
896 else if( 0 == actionName.compare( ACTION_PAUSE ) )
906 void Animation::SetCurrentProgress(float progress)
908 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
910 // mAnimation is being used in a separate thread; queue a message to set the current progress
911 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
915 float Animation::GetCurrentProgress()
919 return mAnimation->GetCurrentProgress();
925 void Animation::ExtendDuration( const TimePeriod& timePeriod )
927 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
929 if( duration > mDurationSeconds )
931 SetDuration( duration );
935 void Animation::SetSpeedFactor( float factor )
939 mSpeedFactor = factor;
940 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
944 float Animation::GetSpeedFactor() const
949 void Animation::SetPlayRange( const Vector2& range)
951 //Make sure the range specified is between 0.0 and 1.0
952 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
954 Vector2 orderedRange( range );
955 //If the range is not in order swap values
956 if( range.x > range.y )
958 orderedRange = Vector2(range.y, range.x);
961 // Cache for public getters
962 mPlayRange = orderedRange;
964 // mAnimation is being used in a separate thread; queue a message to set play range
965 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
969 Vector2 Animation::GetPlayRange() const
975 } // namespace Internal