2 * Copyright (c) 2017 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/animation/alpha-function.h>
26 #include <dali/public-api/animation/time-period.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/radian.h>
31 #include <dali/internal/event/animation/animation-playlist.h>
32 #include <dali/internal/event/animation/animator-connector.h>
33 #include <dali/internal/event/animation/path-impl.h>
34 #include <dali/internal/event/common/notification-manager.h>
35 #include <dali/internal/event/common/property-helper.h>
36 #include <dali/internal/event/common/stage-impl.h>
37 #include <dali/internal/event/common/thread-local-storage.h>
38 #include <dali/internal/update/animation/scene-graph-animator.h>
39 #include <dali/internal/update/manager/update-manager.h>
41 using Dali::Internal::SceneGraph::UpdateManager;
42 using Dali::Internal::SceneGraph::AnimatorBase;
43 using Dali::Internal::SceneGraph::Shader;
51 static bool SHOW_VALUE = true;
52 static bool HIDE_VALUE = false;
59 const char* const SIGNAL_FINISHED = "finished";
63 const char* const ACTION_PLAY = "play";
64 const char* const ACTION_STOP = "stop";
65 const char* const ACTION_PAUSE = "pause";
69 return Dali::Animation::New(0.f);
72 TypeRegistration mType( typeid( Dali::Animation ), typeid( Dali::BaseHandle ), Create );
74 SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &Animation::DoConnectSignal );
76 TypeAction action1( mType, ACTION_PLAY, &Animation::DoAction );
77 TypeAction action2( mType, ACTION_STOP, &Animation::DoAction );
78 TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction );
80 const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::Bake );
81 const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BakeFinal );
82 const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear );
83 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
88 AnimationPtr Animation::New(float durationSeconds)
90 Stage* stage = Stage::GetCurrent();
94 AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
96 if( durationSeconds < 0.0f )
98 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
99 durationSeconds = 0.0f;
102 AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
104 // Second-phase construction
105 animation->Initialize();
115 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
116 : mAnimation( NULL ),
117 mEventThreadServices( eventThreadServices ),
118 mPlaylist( playlist ),
121 mConnectorTargetValues(),
122 mPlayRange( Vector2(0.0f,1.0f)),
123 mDurationSeconds( durationSeconds ),
125 mNotificationCount( 0 ),
128 mEndAction( endAction ),
129 mDisconnectAction( disconnectAction ),
130 mDefaultAlpha( defaultAlpha ),
131 mState(Dali::Animation::STOPPED)
135 void Animation::Initialize()
137 // Connect to the animation playlist
138 mPlaylist.AnimationCreated( *this );
145 Animation::~Animation()
147 // Guard to allow handle destruction after Core has been destroyed
148 if ( Stage::IsInstalled() )
150 // Disconnect from the animation playlist
151 mPlaylist.AnimationDestroyed( *this );
153 DestroySceneObject();
159 void Animation::CreateSceneObject()
161 DALI_ASSERT_DEBUG( mAnimation == NULL );
163 // Create a new animation, temporarily owned
164 SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction );
166 // Keep a const pointer to the animation.
167 mAnimation = animation;
169 // Transfer animation ownership to the update manager through a message
170 AddAnimationMessage( mEventThreadServices.GetUpdateManager(), animation );
173 void Animation::DestroySceneObject()
175 if ( mAnimation != NULL )
177 // Remove animation using a message to the update manager
178 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
183 void Animation::SetDuration(float seconds)
187 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
191 // Cache for public getters
192 mDurationSeconds = seconds;
194 // mAnimation is being used in a separate thread; queue a message to set the value
195 SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
198 float Animation::GetDuration() const
200 // This is not animatable; the cached value is up-to-date.
201 return mDurationSeconds;
204 void Animation::SetLooping(bool on)
206 SetLoopCount( on ? 0 : 1 );
209 void Animation::SetLoopCount(int count)
211 // Cache for public getters
214 // mAnimation is being used in a separate thread; queue a message to set the value
215 SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
218 int Animation::GetLoopCount()
223 int Animation::GetCurrentLoop()
228 bool Animation::IsLooping() const
230 return mLoopCount != 1;
233 void Animation::SetEndAction(EndAction action)
235 // Cache for public getters
238 // mAnimation is being used in a separate thread; queue a message to set the value
239 SetEndActionMessage( mEventThreadServices, *mAnimation, action );
242 Dali::Animation::EndAction Animation::GetEndAction() const
244 // This is not animatable; the cached value is up-to-date.
248 void Animation::SetDisconnectAction(EndAction action)
250 // Cache for public getters
251 mDisconnectAction = action;
253 // mAnimation is being used in a separate thread; queue a message to set the value
254 SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
257 Dali::Animation::EndAction Animation::GetDisconnectAction() const
259 // This is not animatable; the cached value is up-to-date.
260 return mDisconnectAction;
263 void Animation::Play()
265 // Update the current playlist
266 mPlaylist.OnPlay( *this );
268 mState = Dali::Animation::PLAYING;
270 if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
272 // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
273 std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
275 // Loop through all connector target values sorted by increasing end time
276 ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
277 const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
278 for( ; iter != endIter; ++iter )
280 AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
282 Object* object = connector->GetObject();
285 object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType );
290 // mAnimation is being used in a separate thread; queue a Play message
291 PlayAnimationMessage( mEventThreadServices, *mAnimation );
294 void Animation::PlayFrom( float progress )
296 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
298 // Update the current playlist
299 mPlaylist.OnPlay( *this );
301 mState = Dali::Animation::PLAYING;
303 // mAnimation is being used in a separate thread; queue a Play message
304 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
308 void Animation::Pause()
310 mState = Dali::Animation::PAUSED;
312 // mAnimation is being used in a separate thread; queue a Pause message
313 PauseAnimationMessage( mEventThreadServices, *mAnimation );
316 Dali::Animation::State Animation::GetState() const
321 void Animation::Stop()
323 mState = Dali::Animation::STOPPED;
325 // mAnimation is being used in a separate thread; queue a Stop message
326 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
329 void Animation::Clear()
331 DALI_ASSERT_DEBUG(mAnimation);
333 // Remove all the connectors
336 // Reset the connector target values
337 mConnectorTargetValues.clear();
339 // Replace the old scene-object with a new one
340 DestroySceneObject();
343 // Reset the notification count, since the new scene-object has never been played
344 mNotificationCount = 0;
346 // Update the current playlist
347 mPlaylist.OnClear( *this );
350 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
352 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
355 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
357 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
360 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
362 AnimateBy(target, relativeValue, mDefaultAlpha, period);
365 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
367 Object& object = GetImplementation(target.object);
368 const Property::Type targetType = object.GetPropertyType(target.propertyIndex);
369 const Property::Type destinationType = relativeValue.GetType();
371 if ( object.GetPropertyComponentIndex( target.propertyIndex ) != Property::INVALID_COMPONENT_INDEX )
373 DALI_ASSERT_ALWAYS(Property::FLOAT == destinationType && "Animated value and Property type don't match");
377 DALI_ASSERT_ALWAYS(targetType == destinationType && "Animated value and Property type don't match");
380 ExtendDuration(period);
382 // Store data to later notify the object that its property is being animated
383 ConnectorTargetValues connectorPair;
384 connectorPair.targetValue = relativeValue;
385 connectorPair.connectorIndex = mConnectors.Count();
386 connectorPair.timePeriod = period;
387 connectorPair.animatorType = Animation::BY;
388 mConnectorTargetValues.push_back( connectorPair );
390 switch ( targetType )
392 case Property::BOOLEAN:
394 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
395 target.propertyIndex,
396 target.componentIndex,
397 new AnimateByBoolean(relativeValue.Get<bool>()),
403 case Property::INTEGER:
405 AddAnimatorConnector( AnimatorConnector<int>::New( object,
406 target.propertyIndex,
407 target.componentIndex,
408 new AnimateByInteger(relativeValue.Get<int>()),
414 case Property::FLOAT:
416 AddAnimatorConnector( AnimatorConnector<float>::New( object,
417 target.propertyIndex,
418 target.componentIndex,
419 new AnimateByFloat(relativeValue.Get<float>()),
425 case Property::VECTOR2:
427 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
428 target.propertyIndex,
429 target.componentIndex,
430 new AnimateByVector2(relativeValue.Get<Vector2>()),
436 case Property::VECTOR3:
438 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
439 target.propertyIndex,
440 target.componentIndex,
441 new AnimateByVector3(relativeValue.Get<Vector3>()),
447 case Property::VECTOR4:
449 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
450 target.propertyIndex,
451 target.componentIndex,
452 new AnimateByVector4(relativeValue.Get<Vector4>()),
458 case Property::ROTATION:
460 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
462 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
463 target.propertyIndex,
464 target.componentIndex,
465 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
473 // non animatable types handled already
478 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
480 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
483 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
485 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
488 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
490 AnimateTo(target, destinationValue, mDefaultAlpha, period);
493 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
495 Object& object = GetImplementation(target.object);
497 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
500 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
502 Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
503 if( componentIndex != Property::INVALID_COMPONENT_INDEX )
505 if( ( targetType == Property::VECTOR2 ) ||
506 ( targetType == Property::VECTOR3 ) ||
507 ( targetType == Property::VECTOR4 ) )
509 targetType = Property::FLOAT;
512 const Property::Type destinationType = destinationValue.GetType();
513 DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
515 ExtendDuration( period );
517 // Store data to later notify the object that its property is being animated
518 ConnectorTargetValues connectorPair;
519 connectorPair.targetValue = destinationValue;
520 connectorPair.connectorIndex = mConnectors.Count();
521 connectorPair.timePeriod = period;
522 connectorPair.animatorType = Animation::TO;
523 mConnectorTargetValues.push_back( connectorPair );
525 switch ( destinationType )
527 case Property::BOOLEAN:
529 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
532 new AnimateToBoolean( destinationValue.Get<bool>() ),
538 case Property::INTEGER:
540 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
543 new AnimateToInteger( destinationValue.Get<int>() ),
549 case Property::FLOAT:
551 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
554 new AnimateToFloat( destinationValue.Get<float>() ),
560 case Property::VECTOR2:
562 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
565 new AnimateToVector2( destinationValue.Get<Vector2>() ),
571 case Property::VECTOR3:
573 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
576 new AnimateToVector3( destinationValue.Get<Vector3>() ),
582 case Property::VECTOR4:
584 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
587 new AnimateToVector4( destinationValue.Get<Vector4>() ),
593 case Property::ROTATION:
595 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
598 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
606 // non animatable types handled already
611 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
613 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
616 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
618 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
621 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
623 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
626 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
628 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
631 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
633 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
636 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
638 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
641 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
643 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
646 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
648 Object& object = GetImplementation( target.object );
650 ExtendDuration( period );
652 switch(keyFrames.GetType())
654 case Dali::Property::BOOLEAN:
656 const KeyFrameBoolean* kf;
657 GetSpecialization(keyFrames, kf);
658 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
659 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
660 target.propertyIndex,
661 target.componentIndex,
662 new KeyFrameBooleanFunctor(kfCopy),
668 case Dali::Property::INTEGER:
670 const KeyFrameInteger* kf;
671 GetSpecialization(keyFrames, kf);
672 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
673 AddAnimatorConnector( AnimatorConnector<int>::New( object,
674 target.propertyIndex,
675 target.componentIndex,
676 new KeyFrameIntegerFunctor(kfCopy,interpolation),
682 case Dali::Property::FLOAT:
684 const KeyFrameNumber* kf;
685 GetSpecialization(keyFrames, kf);
686 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
687 AddAnimatorConnector( AnimatorConnector<float>::New( object,
688 target.propertyIndex,
689 target.componentIndex,
690 new KeyFrameNumberFunctor(kfCopy,interpolation),
696 case Dali::Property::VECTOR2:
698 const KeyFrameVector2* kf;
699 GetSpecialization(keyFrames, kf);
700 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
701 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
702 target.propertyIndex,
703 target.componentIndex,
704 new KeyFrameVector2Functor(kfCopy,interpolation),
710 case Dali::Property::VECTOR3:
712 const KeyFrameVector3* kf;
713 GetSpecialization(keyFrames, kf);
714 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
715 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
716 target.propertyIndex,
717 target.componentIndex,
718 new KeyFrameVector3Functor(kfCopy,interpolation),
724 case Dali::Property::VECTOR4:
726 const KeyFrameVector4* kf;
727 GetSpecialization(keyFrames, kf);
728 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
729 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
730 target.propertyIndex,
731 target.componentIndex,
732 new KeyFrameVector4Functor(kfCopy,interpolation),
738 case Dali::Property::ROTATION:
740 const KeyFrameQuaternion* kf;
741 GetSpecialization(keyFrames, kf);
742 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
743 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
744 target.propertyIndex,
745 target.componentIndex,
746 new KeyFrameQuaternionFunctor(kfCopy),
754 // non animatable types handled by keyframes
759 bool Animation::HasFinished()
761 bool hasFinished(false);
762 const int playedCount(mAnimation->GetPlayedCount());
764 // If the play count has been incremented, then another notification is required
765 mCurrentLoop = mAnimation->GetCurrentLoop();
767 if (playedCount > mNotificationCount)
769 // Note that only one signal is emitted, if the animation has been played repeatedly
770 mNotificationCount = playedCount;
774 mState = Dali::Animation::STOPPED;
780 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
782 return mFinishedSignal;
785 void Animation::EmitSignalFinish()
787 if ( !mFinishedSignal.Empty() )
789 Dali::Animation handle( this );
790 mFinishedSignal.Emit( handle );
794 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
796 bool connected( true );
797 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
799 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
801 animation->FinishedSignal().Connect( tracker, functor );
805 // signalName does not match any signal
812 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
814 DALI_ASSERT_DEBUG( NULL != connector );
816 connector->SetParent(*this);
818 mConnectors.PushBack( connector );
821 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
823 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
826 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
828 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
831 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
833 Animate( actor, path, forward, mDefaultAlpha, period );
836 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
838 ExtendDuration( period );
840 PathPtr pathCopy = Path::Clone(path);
843 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
844 Dali::Actor::Property::POSITION,
845 Property::INVALID_COMPONENT_INDEX,
846 new PathPositionFunctor( pathCopy ),
850 //If forward is zero, PathRotationFunctor will always return the unit quaternion
851 if( forward != Vector3::ZERO )
854 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
855 Dali::Actor::Property::ORIENTATION,
856 Property::INVALID_COMPONENT_INDEX,
857 new PathRotationFunctor( pathCopy, forward ),
863 void Animation::Show(Actor& actor, float delaySeconds)
865 ExtendDuration( TimePeriod(delaySeconds, 0) );
867 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
868 Dali::Actor::Property::VISIBLE,
869 Property::INVALID_COMPONENT_INDEX,
870 new AnimateToBoolean(SHOW_VALUE),
872 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
875 void Animation::Hide(Actor& actor, float delaySeconds)
877 ExtendDuration( TimePeriod(delaySeconds, 0) );
879 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
880 Dali::Actor::Property::VISIBLE,
881 Property::INVALID_COMPONENT_INDEX,
882 new AnimateToBoolean(HIDE_VALUE),
884 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
887 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
890 Animation* animation = dynamic_cast<Animation*>( object );
894 if( 0 == actionName.compare( ACTION_PLAY ) )
896 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
898 animation->SetDuration( value->Get<float>() );
904 else if( 0 == actionName.compare( ACTION_STOP ) )
909 else if( 0 == actionName.compare( ACTION_PAUSE ) )
919 void Animation::SetCurrentProgress(float progress)
921 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
923 // mAnimation is being used in a separate thread; queue a message to set the current progress
924 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
928 float Animation::GetCurrentProgress()
932 return mAnimation->GetCurrentProgress();
938 void Animation::ExtendDuration( const TimePeriod& timePeriod )
940 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
942 if( duration > mDurationSeconds )
944 SetDuration( duration );
948 void Animation::SetSpeedFactor( float factor )
952 mSpeedFactor = factor;
953 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
957 float Animation::GetSpeedFactor() const
962 void Animation::SetPlayRange( const Vector2& range)
964 //Make sure the range specified is between 0.0 and 1.0
965 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
967 Vector2 orderedRange( range );
968 //If the range is not in order swap values
969 if( range.x > range.y )
971 orderedRange = Vector2(range.y, range.x);
974 // Cache for public getters
975 mPlayRange = orderedRange;
977 // mAnimation is being used in a separate thread; queue a message to set play range
978 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
982 Vector2 Animation::GetPlayRange() const
987 bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
989 return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
992 } // namespace Internal