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 ),
126 mPlayRange( Vector2(0.0f,1.0f)),
127 mEndAction( endAction ),
128 mDisconnectAction( disconnectAction ),
129 mDefaultAlpha( defaultAlpha )
133 void Animation::Initialize()
135 // Connect to the animation playlist
136 mPlaylist.AnimationCreated( *this );
143 Animation::~Animation()
145 // Guard to allow handle destruction after Core has been destroyed
146 if ( Stage::IsInstalled() )
148 // Disconnect from the animation playlist
149 mPlaylist.AnimationDestroyed( *this );
151 DestroySceneObject();
157 void Animation::CreateSceneObject()
159 DALI_ASSERT_DEBUG( mAnimation == NULL );
161 // Create a new animation, temporarily owned
162 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mIsLooping, mEndAction, mDisconnectAction );
164 // Keep a const pointer to the animation.
165 mAnimation = animation;
167 // Transfer animation ownership to the update manager through a message
168 AddAnimationMessage( mEventThreadServices.GetUpdateManager(), animation );
171 void Animation::DestroySceneObject()
173 if ( mAnimation != NULL )
175 // Remove animation using a message to the update manager
176 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
181 void Animation::SetDuration(float seconds)
185 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
189 // Cache for public getters
190 mDurationSeconds = seconds;
192 // mAnimation is being used in a separate thread; queue a message to set the value
193 SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
196 float Animation::GetDuration() const
198 // This is not animatable; the cached value is up-to-date.
199 return mDurationSeconds;
202 void Animation::SetLooping(bool looping)
204 // Cache for public getters
205 mIsLooping = looping;
207 // mAnimation is being used in a separate thread; queue a message to set the value
208 SetLoopingMessage( mEventThreadServices, *mAnimation, looping );
211 bool Animation::IsLooping() const
213 // This is not animatable; the cached value is up-to-date.
217 void Animation::SetEndAction(EndAction action)
219 // Cache for public getters
222 // mAnimation is being used in a separate thread; queue a message to set the value
223 SetEndActionMessage( mEventThreadServices, *mAnimation, action );
226 Dali::Animation::EndAction Animation::GetEndAction() const
228 // This is not animatable; the cached value is up-to-date.
232 void Animation::SetDisconnectAction(EndAction action)
234 // Cache for public getters
235 mDisconnectAction = action;
237 // mAnimation is being used in a separate thread; queue a message to set the value
238 SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
241 Dali::Animation::EndAction Animation::GetDisconnectAction() const
243 // This is not animatable; the cached value is up-to-date.
244 return mDisconnectAction;
247 void Animation::Play()
249 // Update the current playlist
250 mPlaylist.OnPlay( *this );
252 // mAnimation is being used in a separate thread; queue a Play message
253 PlayAnimationMessage( mEventThreadServices, *mAnimation );
256 void Animation::PlayFrom( float progress )
258 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
260 // Update the current playlist
261 mPlaylist.OnPlay( *this );
263 // mAnimation is being used in a separate thread; queue a Play message
264 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
268 void Animation::Pause()
270 // mAnimation is being used in a separate thread; queue a Pause message
271 PauseAnimationMessage( mEventThreadServices, *mAnimation );
274 void Animation::Stop()
276 // mAnimation is being used in a separate thread; queue a Stop message
277 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
280 void Animation::Clear()
282 DALI_ASSERT_DEBUG(mAnimation);
284 // Remove all the connectors
287 // Replace the old scene-object with a new one
288 DestroySceneObject();
291 // Reset the notification count, since the new scene-object has never been played
292 mNotificationCount = 0;
294 // Update the current playlist
295 mPlaylist.OnClear( *this );
298 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
300 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
303 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
305 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
308 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
310 AnimateBy(target, relativeValue, mDefaultAlpha, period);
313 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
315 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
317 ExtendDuration( period );
319 switch ( relativeValue.GetType() )
321 case Property::BOOLEAN:
323 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
324 target.propertyIndex,
325 target.componentIndex,
326 new AnimateByBoolean(relativeValue.Get<bool>()),
332 case Property::INTEGER:
334 AddAnimatorConnector( AnimatorConnector<int>::New( object,
335 target.propertyIndex,
336 target.componentIndex,
337 new AnimateByInteger(relativeValue.Get<int>()),
343 case Property::FLOAT:
345 AddAnimatorConnector( AnimatorConnector<float>::New( object,
346 target.propertyIndex,
347 target.componentIndex,
348 new AnimateByFloat(relativeValue.Get<float>()),
354 case Property::VECTOR2:
356 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
357 target.propertyIndex,
358 target.componentIndex,
359 new AnimateByVector2(relativeValue.Get<Vector2>()),
365 case Property::VECTOR3:
367 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
368 target.propertyIndex,
369 target.componentIndex,
370 new AnimateByVector3(relativeValue.Get<Vector3>()),
376 case Property::VECTOR4:
378 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
379 target.propertyIndex,
380 target.componentIndex,
381 new AnimateByVector4(relativeValue.Get<Vector4>()),
387 case Property::ROTATION:
389 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
391 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
392 target.propertyIndex,
393 target.componentIndex,
394 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
401 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
406 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
408 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
411 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
413 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
416 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
418 AnimateTo(target, destinationValue, mDefaultAlpha, period);
421 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
423 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
425 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
428 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
430 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
431 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
433 if( type == Property::VECTOR2
434 || type == Property::VECTOR3
435 || type == Property::VECTOR4 )
437 type = Property::FLOAT;
440 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
442 ExtendDuration( period );
444 switch (destinationValue.GetType())
446 case Property::BOOLEAN:
448 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
451 new AnimateToBoolean( destinationValue.Get<bool>() ),
457 case Property::INTEGER:
459 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
462 new AnimateToInteger( destinationValue.Get<int>() ),
468 case Property::FLOAT:
470 if ( ( Dali::Actor::Property::SIZE_WIDTH == targetPropertyIndex ) ||
471 ( Dali::Actor::Property::SIZE_HEIGHT == targetPropertyIndex ) ||
472 ( Dali::Actor::Property::SIZE_DEPTH == targetPropertyIndex ) )
474 // Test whether this is actually an Actor
475 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
478 // Notify the actor that its size is being animated
479 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
482 else if ( ( Dali::Actor::Property::POSITION_X == targetPropertyIndex ) ||
483 ( Dali::Actor::Property::POSITION_Y == targetPropertyIndex ) ||
484 ( Dali::Actor::Property::POSITION_Z == targetPropertyIndex ) )
486 // Test whether this is actually an Actor
487 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
490 // Notify the actor that its position is being animated
491 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
495 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
498 new AnimateToFloat( destinationValue.Get<float>() ),
504 case Property::VECTOR2:
506 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
509 new AnimateToVector2( destinationValue.Get<Vector2>() ),
515 case Property::VECTOR3:
517 if ( Dali::Actor::Property::SIZE == targetPropertyIndex )
519 // Test whether this is actually an Actor
520 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
523 // Notify the actor that its size is being animated
524 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
527 else if ( Dali::Actor::Property::POSITION == targetPropertyIndex )
529 // Test whether this is actually an Actor
530 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
533 // Notify the actor that its position is being animated
534 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<Vector3>() );
538 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
541 new AnimateToVector3( destinationValue.Get<Vector3>() ),
547 case Property::VECTOR4:
549 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
552 new AnimateToVector4( destinationValue.Get<Vector4>() ),
558 case Property::ROTATION:
560 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
563 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
570 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
575 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
577 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
580 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
582 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
585 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
587 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
590 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
592 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
595 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
597 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
600 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
602 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
605 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
607 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
610 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
612 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
614 ExtendDuration( period );
616 switch(keyFrames.GetType())
618 case Dali::Property::BOOLEAN:
620 const KeyFrameBoolean* kf;
621 GetSpecialization(keyFrames, kf);
622 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
623 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
624 target.propertyIndex,
625 target.componentIndex,
626 new KeyFrameBooleanFunctor(kfCopy),
632 case Dali::Property::INTEGER:
634 const KeyFrameInteger* kf;
635 GetSpecialization(keyFrames, kf);
636 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
637 AddAnimatorConnector( AnimatorConnector<int>::New( object,
638 target.propertyIndex,
639 target.componentIndex,
640 new KeyFrameIntegerFunctor(kfCopy,interpolation),
646 case Dali::Property::FLOAT:
648 const KeyFrameNumber* kf;
649 GetSpecialization(keyFrames, kf);
650 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
651 AddAnimatorConnector( AnimatorConnector<float>::New( object,
652 target.propertyIndex,
653 target.componentIndex,
654 new KeyFrameNumberFunctor(kfCopy,interpolation),
660 case Dali::Property::VECTOR2:
662 const KeyFrameVector2* kf;
663 GetSpecialization(keyFrames, kf);
664 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
665 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
666 target.propertyIndex,
667 target.componentIndex,
668 new KeyFrameVector2Functor(kfCopy,interpolation),
674 case Dali::Property::VECTOR3:
676 const KeyFrameVector3* kf;
677 GetSpecialization(keyFrames, kf);
678 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
679 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
680 target.propertyIndex,
681 target.componentIndex,
682 new KeyFrameVector3Functor(kfCopy,interpolation),
688 case Dali::Property::VECTOR4:
690 const KeyFrameVector4* kf;
691 GetSpecialization(keyFrames, kf);
692 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
693 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
694 target.propertyIndex,
695 target.componentIndex,
696 new KeyFrameVector4Functor(kfCopy,interpolation),
702 case Dali::Property::ROTATION:
704 const KeyFrameQuaternion* kf;
705 GetSpecialization(keyFrames, kf);
706 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
707 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
708 target.propertyIndex,
709 target.componentIndex,
710 new KeyFrameQuaternionFunctor(kfCopy),
716 default: // not all property types are animateable
721 bool Animation::HasFinished()
723 bool hasFinished(false);
724 const int playCount(mAnimation->GetPlayCount());
726 // If the play count has been incremented, then another notification is required
727 if (playCount > mNotificationCount)
729 // Note that only one signal is emitted, if the animation has been played repeatedly
730 mNotificationCount = playCount;
738 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
740 return mFinishedSignal;
743 void Animation::EmitSignalFinish()
745 if ( !mFinishedSignal.Empty() )
747 Dali::Animation handle( this );
748 mFinishedSignal.Emit( handle );
751 // This callback is used internally, to avoid the overhead of using a signal.
752 if ( mFinishedCallback )
754 mFinishedCallback( mFinishedCallbackObject );
758 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
760 bool connected( true );
761 Animation* animation = dynamic_cast<Animation*>(object);
763 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
765 animation->FinishedSignal().Connect( tracker, functor );
769 // signalName does not match any signal
776 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
778 mFinishedCallback = callback;
779 mFinishedCallbackObject = object;
782 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
784 DALI_ASSERT_DEBUG( NULL != connector );
786 connector->SetParent(*this);
788 mConnectors.PushBack( connector );
791 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
793 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
796 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
798 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
801 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
803 Animate( actor, path, forward, mDefaultAlpha, period );
806 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
808 ExtendDuration( period );
810 PathPtr pathCopy = Path::Clone(path);
813 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
814 Dali::Actor::Property::POSITION,
815 Property::INVALID_COMPONENT_INDEX,
816 new PathPositionFunctor( pathCopy ),
820 //If forward is zero, PathRotationFunctor will always return the unit quaternion
821 if( forward != Vector3::ZERO )
824 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
825 Dali::Actor::Property::ORIENTATION,
826 Property::INVALID_COMPONENT_INDEX,
827 new PathRotationFunctor( pathCopy, forward ),
833 void Animation::Show(Actor& actor, float delaySeconds)
835 ExtendDuration( TimePeriod(delaySeconds, 0) );
837 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
838 Dali::Actor::Property::VISIBLE,
839 Property::INVALID_COMPONENT_INDEX,
840 new AnimateToBoolean(SHOW_VALUE),
842 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
845 void Animation::Hide(Actor& actor, float delaySeconds)
847 ExtendDuration( TimePeriod(delaySeconds, 0) );
849 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
850 Dali::Actor::Property::VISIBLE,
851 Property::INVALID_COMPONENT_INDEX,
852 new AnimateToBoolean(HIDE_VALUE),
854 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
857 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
860 Animation* animation = dynamic_cast<Animation*>( object );
864 if( 0 == actionName.compare( ACTION_PLAY ) )
866 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
868 animation->SetDuration( value->Get<float>() );
874 else if( 0 == actionName.compare( ACTION_STOP ) )
879 else if( 0 == actionName.compare( ACTION_PAUSE ) )
889 void Animation::SetCurrentProgress(float progress)
891 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
893 // mAnimation is being used in a separate thread; queue a message to set the current progress
894 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
898 float Animation::GetCurrentProgress()
902 return mAnimation->GetCurrentProgress();
908 void Animation::ExtendDuration( const TimePeriod& timePeriod )
910 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
912 if( duration > mDurationSeconds )
914 SetDuration( duration );
918 void Animation::SetSpeedFactor( float factor )
922 mSpeedFactor = factor;
923 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
927 float Animation::GetSpeedFactor() const
932 void Animation::SetPlayRange( const Vector2& range)
934 //Make sure the range specified is between 0.0 and 1.0
935 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
937 Vector2 orderedRange( range );
938 //If the range is not in order swap values
939 if( range.x > range.y )
941 orderedRange = Vector2(range.y, range.x);
944 // Cache for public getters
945 mPlayRange = orderedRange;
947 // mAnimation is being used in a separate thread; queue a message to set play range
948 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
952 Vector2 Animation::GetPlayRange() const
958 } // namespace Internal