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;
272 // mAnimation is being used in a separate thread; queue a Play message
273 PlayAnimationMessage( mEventThreadServices, *mAnimation );
276 void Animation::PlayFrom( float progress )
278 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
280 // Update the current playlist
281 mPlaylist.OnPlay( *this );
283 mState = Dali::Animation::PLAYING;
287 // mAnimation is being used in a separate thread; queue a Play message
288 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
292 void Animation::Pause()
294 mState = Dali::Animation::PAUSED;
296 // mAnimation is being used in a separate thread; queue a Pause message
297 PauseAnimationMessage( mEventThreadServices, *mAnimation );
300 Dali::Animation::State Animation::GetState() const
305 void Animation::Stop()
307 mState = Dali::Animation::STOPPED;
309 // mAnimation is being used in a separate thread; queue a Stop message
310 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
313 void Animation::Clear()
315 DALI_ASSERT_DEBUG(mAnimation);
317 // Remove all the connectors
320 // Reset the connector target values
321 mConnectorTargetValues.clear();
323 // Replace the old scene-object with a new one
324 DestroySceneObject();
327 // Reset the notification count, since the new scene-object has never been played
328 mNotificationCount = 0;
330 // Update the current playlist
331 mPlaylist.OnClear( *this );
334 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
336 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
339 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
341 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
344 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
346 AnimateBy(target, relativeValue, mDefaultAlpha, period);
349 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
351 Object& object = GetImplementation(target.object);
352 const Property::Type targetType = object.GetPropertyType(target.propertyIndex);
353 const Property::Type destinationType = relativeValue.GetType();
355 if ( object.GetPropertyComponentIndex( target.propertyIndex ) != Property::INVALID_COMPONENT_INDEX )
357 DALI_ASSERT_ALWAYS(Property::FLOAT == destinationType && "Animated value and Property type don't match");
361 DALI_ASSERT_ALWAYS(targetType == destinationType && "Animated value and Property type don't match");
364 ExtendDuration(period);
366 // Store data to later notify the object that its property is being animated
367 ConnectorTargetValues connectorPair;
368 connectorPair.targetValue = relativeValue;
369 connectorPair.connectorIndex = mConnectors.Count();
370 connectorPair.timePeriod = period;
371 connectorPair.animatorType = Animation::BY;
372 mConnectorTargetValues.push_back( connectorPair );
374 switch ( targetType )
376 case Property::BOOLEAN:
378 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
379 target.propertyIndex,
380 target.componentIndex,
381 new AnimateByBoolean(relativeValue.Get<bool>()),
387 case Property::INTEGER:
389 AddAnimatorConnector( AnimatorConnector<int>::New( object,
390 target.propertyIndex,
391 target.componentIndex,
392 new AnimateByInteger(relativeValue.Get<int>()),
398 case Property::FLOAT:
400 AddAnimatorConnector( AnimatorConnector<float>::New( object,
401 target.propertyIndex,
402 target.componentIndex,
403 new AnimateByFloat(relativeValue.Get<float>()),
409 case Property::VECTOR2:
411 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
412 target.propertyIndex,
413 target.componentIndex,
414 new AnimateByVector2(relativeValue.Get<Vector2>()),
420 case Property::VECTOR3:
422 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
423 target.propertyIndex,
424 target.componentIndex,
425 new AnimateByVector3(relativeValue.Get<Vector3>()),
431 case Property::VECTOR4:
433 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
434 target.propertyIndex,
435 target.componentIndex,
436 new AnimateByVector4(relativeValue.Get<Vector4>()),
442 case Property::ROTATION:
444 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
446 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
447 target.propertyIndex,
448 target.componentIndex,
449 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
457 // non animatable types handled already
462 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
464 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
467 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
469 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
472 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
474 AnimateTo(target, destinationValue, mDefaultAlpha, period);
477 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
479 Object& object = GetImplementation(target.object);
481 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
484 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
486 Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
487 if( componentIndex != Property::INVALID_COMPONENT_INDEX )
489 if( ( targetType == Property::VECTOR2 ) ||
490 ( targetType == Property::VECTOR3 ) ||
491 ( targetType == Property::VECTOR4 ) )
493 targetType = Property::FLOAT;
496 const Property::Type destinationType = destinationValue.GetType();
497 DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
499 ExtendDuration( period );
501 // Store data to later notify the object that its property is being animated
502 ConnectorTargetValues connectorPair;
503 connectorPair.targetValue = destinationValue;
504 connectorPair.connectorIndex = mConnectors.Count();
505 connectorPair.timePeriod = period;
506 connectorPair.animatorType = Animation::TO;
507 mConnectorTargetValues.push_back( connectorPair );
509 switch ( destinationType )
511 case Property::BOOLEAN:
513 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
516 new AnimateToBoolean( destinationValue.Get<bool>() ),
522 case Property::INTEGER:
524 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
527 new AnimateToInteger( destinationValue.Get<int>() ),
533 case Property::FLOAT:
535 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
538 new AnimateToFloat( destinationValue.Get<float>() ),
544 case Property::VECTOR2:
546 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
549 new AnimateToVector2( destinationValue.Get<Vector2>() ),
555 case Property::VECTOR3:
557 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
560 new AnimateToVector3( destinationValue.Get<Vector3>() ),
566 case Property::VECTOR4:
568 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
571 new AnimateToVector4( destinationValue.Get<Vector4>() ),
577 case Property::ROTATION:
579 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
582 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
590 // non animatable types handled already
595 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
597 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
600 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
602 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
605 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
607 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
610 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
612 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
615 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
617 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
620 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
622 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
625 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
627 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
630 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
632 Object& object = GetImplementation( target.object );
634 ExtendDuration( period );
636 // Store data to later notify the object that its property is being animated
637 ConnectorTargetValues connectorPair;
638 connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
639 connectorPair.connectorIndex = mConnectors.Count();
640 connectorPair.timePeriod = period;
641 connectorPair.animatorType = BETWEEN;
642 mConnectorTargetValues.push_back( connectorPair );
644 switch(keyFrames.GetType())
646 case Dali::Property::BOOLEAN:
648 const KeyFrameBoolean* kf;
649 GetSpecialization(keyFrames, kf);
650 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
651 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
652 target.propertyIndex,
653 target.componentIndex,
654 new KeyFrameBooleanFunctor(kfCopy),
660 case Dali::Property::INTEGER:
662 const KeyFrameInteger* kf;
663 GetSpecialization(keyFrames, kf);
664 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
665 AddAnimatorConnector( AnimatorConnector<int>::New( object,
666 target.propertyIndex,
667 target.componentIndex,
668 new KeyFrameIntegerFunctor(kfCopy,interpolation),
674 case Dali::Property::FLOAT:
676 const KeyFrameNumber* kf;
677 GetSpecialization(keyFrames, kf);
678 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
679 AddAnimatorConnector( AnimatorConnector<float>::New( object,
680 target.propertyIndex,
681 target.componentIndex,
682 new KeyFrameNumberFunctor(kfCopy,interpolation),
688 case Dali::Property::VECTOR2:
690 const KeyFrameVector2* kf;
691 GetSpecialization(keyFrames, kf);
692 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
693 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
694 target.propertyIndex,
695 target.componentIndex,
696 new KeyFrameVector2Functor(kfCopy,interpolation),
702 case Dali::Property::VECTOR3:
704 const KeyFrameVector3* kf;
705 GetSpecialization(keyFrames, kf);
706 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
707 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
708 target.propertyIndex,
709 target.componentIndex,
710 new KeyFrameVector3Functor(kfCopy,interpolation),
716 case Dali::Property::VECTOR4:
718 const KeyFrameVector4* kf;
719 GetSpecialization(keyFrames, kf);
720 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
721 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
722 target.propertyIndex,
723 target.componentIndex,
724 new KeyFrameVector4Functor(kfCopy,interpolation),
730 case Dali::Property::ROTATION:
732 const KeyFrameQuaternion* kf;
733 GetSpecialization(keyFrames, kf);
734 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
735 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
736 target.propertyIndex,
737 target.componentIndex,
738 new KeyFrameQuaternionFunctor(kfCopy),
746 // non animatable types handled by keyframes
751 bool Animation::HasFinished()
753 bool hasFinished(false);
754 const int playedCount(mAnimation->GetPlayedCount());
756 // If the play count has been incremented, then another notification is required
757 mCurrentLoop = mAnimation->GetCurrentLoop();
759 if (playedCount > mNotificationCount)
761 // Note that only one signal is emitted, if the animation has been played repeatedly
762 mNotificationCount = playedCount;
766 mState = Dali::Animation::STOPPED;
772 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
774 return mFinishedSignal;
777 void Animation::EmitSignalFinish()
779 if ( !mFinishedSignal.Empty() )
781 Dali::Animation handle( this );
782 mFinishedSignal.Emit( handle );
786 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
788 bool connected( true );
789 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
791 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
793 animation->FinishedSignal().Connect( tracker, functor );
797 // signalName does not match any signal
804 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
806 DALI_ASSERT_DEBUG( NULL != connector );
808 connector->SetParent(*this);
810 mConnectors.PushBack( connector );
813 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
815 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
818 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
820 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
823 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
825 Animate( actor, path, forward, mDefaultAlpha, period );
828 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
830 ExtendDuration( period );
832 PathPtr pathCopy = Path::Clone(path);
835 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
836 Dali::Actor::Property::POSITION,
837 Property::INVALID_COMPONENT_INDEX,
838 new PathPositionFunctor( pathCopy ),
842 //If forward is zero, PathRotationFunctor will always return the unit quaternion
843 if( forward != Vector3::ZERO )
846 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
847 Dali::Actor::Property::ORIENTATION,
848 Property::INVALID_COMPONENT_INDEX,
849 new PathRotationFunctor( pathCopy, forward ),
855 void Animation::Show(Actor& actor, float delaySeconds)
857 ExtendDuration( TimePeriod(delaySeconds, 0) );
859 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
860 Dali::Actor::Property::VISIBLE,
861 Property::INVALID_COMPONENT_INDEX,
862 new AnimateToBoolean(SHOW_VALUE),
864 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
867 void Animation::Hide(Actor& actor, float delaySeconds)
869 ExtendDuration( TimePeriod(delaySeconds, 0) );
871 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
872 Dali::Actor::Property::VISIBLE,
873 Property::INVALID_COMPONENT_INDEX,
874 new AnimateToBoolean(HIDE_VALUE),
876 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
879 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
882 Animation* animation = dynamic_cast<Animation*>( object );
886 if( 0 == actionName.compare( ACTION_PLAY ) )
888 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
890 animation->SetDuration( value->Get<float>() );
896 else if( 0 == actionName.compare( ACTION_STOP ) )
901 else if( 0 == actionName.compare( ACTION_PAUSE ) )
911 void Animation::SetCurrentProgress(float progress)
913 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
915 // mAnimation is being used in a separate thread; queue a message to set the current progress
916 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
920 float Animation::GetCurrentProgress()
924 return mAnimation->GetCurrentProgress();
930 void Animation::ExtendDuration( const TimePeriod& timePeriod )
932 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
934 if( duration > mDurationSeconds )
936 SetDuration( duration );
940 void Animation::SetSpeedFactor( float factor )
944 mSpeedFactor = factor;
945 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
949 float Animation::GetSpeedFactor() const
954 void Animation::SetPlayRange( const Vector2& range)
956 //Make sure the range specified is between 0.0 and 1.0
957 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
959 Vector2 orderedRange( range );
960 //If the range is not in order swap values
961 if( range.x > range.y )
963 orderedRange = Vector2(range.y, range.x);
966 // Cache for public getters
967 mPlayRange = orderedRange;
969 // mAnimation is being used in a separate thread; queue a message to set play range
970 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
974 Vector2 Animation::GetPlayRange() const
979 bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
981 return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
984 void Animation::NotifyObjects()
986 if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
988 // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
989 std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
991 // Loop through all connector target values sorted by increasing end time
992 ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
993 const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
994 for( ; iter != endIter; ++iter )
996 AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
998 Object* object = connector->GetObject();
1001 object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType );
1007 } // namespace Internal