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),
132 mProgressReachedMarker( 0.0f )
136 void Animation::Initialize()
138 // Connect to the animation playlist
139 mPlaylist.AnimationCreated( *this );
146 Animation::~Animation()
148 // Guard to allow handle destruction after Core has been destroyed
149 if ( Stage::IsInstalled() )
151 // Disconnect from the animation playlist
152 mPlaylist.AnimationDestroyed( *this );
154 DestroySceneObject();
160 void Animation::CreateSceneObject()
162 DALI_ASSERT_DEBUG( mAnimation == NULL );
164 // Create a new animation, Keep a const pointer to the animation.
165 mAnimation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction );
166 OwnerPointer< SceneGraph::Animation > transferOwnership( const_cast< SceneGraph::Animation* >( mAnimation ) );
167 AddAnimationMessage( mEventThreadServices.GetUpdateManager(), transferOwnership );
170 void Animation::DestroySceneObject()
172 if ( mAnimation != NULL )
174 // Remove animation using a message to the update manager
175 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
180 void Animation::SetDuration(float seconds)
184 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
188 // Cache for public getters
189 mDurationSeconds = seconds;
191 // mAnimation is being used in a separate thread; queue a message to set the value
192 SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
195 void Animation::SetProgressNotification( float progress )
197 // mAnimation is being used in a separate thread; queue a message to set the value
198 mProgressReachedMarker = progress;
201 float Animation::GetProgressNotification()
203 return mProgressReachedMarker;
206 float Animation::GetDuration() const
208 // This is not animatable; the cached value is up-to-date.
209 return mDurationSeconds;
212 void Animation::SetLooping(bool on)
214 SetLoopCount( on ? 0 : 1 );
217 void Animation::SetLoopCount(int count)
219 // Cache for public getters
222 // mAnimation is being used in a separate thread; queue a message to set the value
223 SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
226 int Animation::GetLoopCount()
231 int Animation::GetCurrentLoop()
236 bool Animation::IsLooping() const
238 return mLoopCount != 1;
241 void Animation::SetEndAction(EndAction action)
243 // Cache for public getters
246 // mAnimation is being used in a separate thread; queue a message to set the value
247 SetEndActionMessage( mEventThreadServices, *mAnimation, action );
250 Dali::Animation::EndAction Animation::GetEndAction() const
252 // This is not animatable; the cached value is up-to-date.
256 void Animation::SetDisconnectAction(EndAction action)
258 // Cache for public getters
259 mDisconnectAction = action;
261 // mAnimation is being used in a separate thread; queue a message to set the value
262 SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
265 Dali::Animation::EndAction Animation::GetDisconnectAction() const
267 // This is not animatable; the cached value is up-to-date.
268 return mDisconnectAction;
271 void Animation::Play()
273 // Update the current playlist
274 mPlaylist.OnPlay( *this );
276 mState = Dali::Animation::PLAYING;
280 SendFinalProgressNotificationMessage();
282 // mAnimation is being used in a separate thread; queue a Play message
283 PlayAnimationMessage( mEventThreadServices, *mAnimation );
286 void Animation::PlayFrom( float progress )
288 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
290 // Update the current playlist
291 mPlaylist.OnPlay( *this );
293 mState = Dali::Animation::PLAYING;
297 SendFinalProgressNotificationMessage();
299 // mAnimation is being used in a separate thread; queue a Play message
300 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
304 void Animation::Pause()
306 mState = Dali::Animation::PAUSED;
308 // mAnimation is being used in a separate thread; queue a Pause message
309 PauseAnimationMessage( mEventThreadServices, *mAnimation );
312 Dali::Animation::State Animation::GetState() const
317 void Animation::Stop()
319 mState = Dali::Animation::STOPPED;
321 // mAnimation is being used in a separate thread; queue a Stop message
322 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
325 void Animation::Clear()
327 DALI_ASSERT_DEBUG(mAnimation);
329 // Remove all the connectors
332 // Reset the connector target values
333 mConnectorTargetValues.clear();
335 // Replace the old scene-object with a new one
336 DestroySceneObject();
339 // Reset the notification count, since the new scene-object has never been played
340 mNotificationCount = 0;
342 // Update the current playlist
343 mPlaylist.OnClear( *this );
346 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
348 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
351 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
353 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
356 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
358 AnimateBy(target, relativeValue, mDefaultAlpha, period);
361 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
363 Object& object = GetImplementation(target.object);
364 const Property::Type targetType = object.GetPropertyType(target.propertyIndex);
365 const Property::Type destinationType = relativeValue.GetType();
367 if ( object.GetPropertyComponentIndex( target.propertyIndex ) != Property::INVALID_COMPONENT_INDEX )
369 DALI_ASSERT_ALWAYS(Property::FLOAT == destinationType && "Animated value and Property type don't match");
373 DALI_ASSERT_ALWAYS(targetType == destinationType && "Animated value and Property type don't match");
376 ExtendDuration(period);
378 // Store data to later notify the object that its property is being animated
379 ConnectorTargetValues connectorPair;
380 connectorPair.targetValue = relativeValue;
381 connectorPair.connectorIndex = mConnectors.Count();
382 connectorPair.timePeriod = period;
383 connectorPair.animatorType = Animation::BY;
384 mConnectorTargetValues.push_back( connectorPair );
386 switch ( targetType )
388 case Property::BOOLEAN:
390 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
391 target.propertyIndex,
392 target.componentIndex,
393 new AnimateByBoolean(relativeValue.Get<bool>()),
399 case Property::INTEGER:
401 AddAnimatorConnector( AnimatorConnector<int>::New( object,
402 target.propertyIndex,
403 target.componentIndex,
404 new AnimateByInteger(relativeValue.Get<int>()),
410 case Property::FLOAT:
412 AddAnimatorConnector( AnimatorConnector<float>::New( object,
413 target.propertyIndex,
414 target.componentIndex,
415 new AnimateByFloat(relativeValue.Get<float>()),
421 case Property::VECTOR2:
423 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
424 target.propertyIndex,
425 target.componentIndex,
426 new AnimateByVector2(relativeValue.Get<Vector2>()),
432 case Property::VECTOR3:
434 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
435 target.propertyIndex,
436 target.componentIndex,
437 new AnimateByVector3(relativeValue.Get<Vector3>()),
443 case Property::VECTOR4:
445 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
446 target.propertyIndex,
447 target.componentIndex,
448 new AnimateByVector4(relativeValue.Get<Vector4>()),
454 case Property::ROTATION:
456 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
458 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
459 target.propertyIndex,
460 target.componentIndex,
461 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
469 // non animatable types handled already
474 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
476 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
479 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
481 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
484 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
486 AnimateTo(target, destinationValue, mDefaultAlpha, period);
489 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
491 Object& object = GetImplementation(target.object);
493 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
496 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
498 Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
499 if( componentIndex != Property::INVALID_COMPONENT_INDEX )
501 if( ( targetType == Property::VECTOR2 ) ||
502 ( targetType == Property::VECTOR3 ) ||
503 ( targetType == Property::VECTOR4 ) )
505 targetType = Property::FLOAT;
508 const Property::Type destinationType = destinationValue.GetType();
509 DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
511 ExtendDuration( period );
513 // Store data to later notify the object that its property is being animated
514 ConnectorTargetValues connectorPair;
515 connectorPair.targetValue = destinationValue;
516 connectorPair.connectorIndex = mConnectors.Count();
517 connectorPair.timePeriod = period;
518 connectorPair.animatorType = Animation::TO;
519 mConnectorTargetValues.push_back( connectorPair );
521 switch ( destinationType )
523 case Property::BOOLEAN:
525 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
528 new AnimateToBoolean( destinationValue.Get<bool>() ),
534 case Property::INTEGER:
536 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
539 new AnimateToInteger( destinationValue.Get<int>() ),
545 case Property::FLOAT:
547 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
550 new AnimateToFloat( destinationValue.Get<float>() ),
556 case Property::VECTOR2:
558 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
561 new AnimateToVector2( destinationValue.Get<Vector2>() ),
567 case Property::VECTOR3:
569 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
572 new AnimateToVector3( destinationValue.Get<Vector3>() ),
578 case Property::VECTOR4:
580 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
583 new AnimateToVector4( destinationValue.Get<Vector4>() ),
589 case Property::ROTATION:
591 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
594 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
602 // non animatable types handled already
607 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
609 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
612 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
614 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
617 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
619 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
622 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
624 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
627 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
629 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
632 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
634 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
637 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
639 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
642 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
644 Object& object = GetImplementation( target.object );
646 ExtendDuration( period );
648 // Store data to later notify the object that its property is being animated
649 ConnectorTargetValues connectorPair;
650 connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
651 connectorPair.connectorIndex = mConnectors.Count();
652 connectorPair.timePeriod = period;
653 connectorPair.animatorType = BETWEEN;
654 mConnectorTargetValues.push_back( connectorPair );
656 switch(keyFrames.GetType())
658 case Dali::Property::BOOLEAN:
660 const KeyFrameBoolean* kf;
661 GetSpecialization(keyFrames, kf);
662 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
663 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
664 target.propertyIndex,
665 target.componentIndex,
666 new KeyFrameBooleanFunctor(kfCopy),
672 case Dali::Property::INTEGER:
674 const KeyFrameInteger* kf;
675 GetSpecialization(keyFrames, kf);
676 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
677 AddAnimatorConnector( AnimatorConnector<int>::New( object,
678 target.propertyIndex,
679 target.componentIndex,
680 new KeyFrameIntegerFunctor(kfCopy,interpolation),
686 case Dali::Property::FLOAT:
688 const KeyFrameNumber* kf;
689 GetSpecialization(keyFrames, kf);
690 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
691 AddAnimatorConnector( AnimatorConnector<float>::New( object,
692 target.propertyIndex,
693 target.componentIndex,
694 new KeyFrameNumberFunctor(kfCopy,interpolation),
700 case Dali::Property::VECTOR2:
702 const KeyFrameVector2* kf;
703 GetSpecialization(keyFrames, kf);
704 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
705 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
706 target.propertyIndex,
707 target.componentIndex,
708 new KeyFrameVector2Functor(kfCopy,interpolation),
714 case Dali::Property::VECTOR3:
716 const KeyFrameVector3* kf;
717 GetSpecialization(keyFrames, kf);
718 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
719 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
720 target.propertyIndex,
721 target.componentIndex,
722 new KeyFrameVector3Functor(kfCopy,interpolation),
728 case Dali::Property::VECTOR4:
730 const KeyFrameVector4* kf;
731 GetSpecialization(keyFrames, kf);
732 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
733 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
734 target.propertyIndex,
735 target.componentIndex,
736 new KeyFrameVector4Functor(kfCopy,interpolation),
742 case Dali::Property::ROTATION:
744 const KeyFrameQuaternion* kf;
745 GetSpecialization(keyFrames, kf);
746 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
747 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
748 target.propertyIndex,
749 target.componentIndex,
750 new KeyFrameQuaternionFunctor(kfCopy),
758 // non animatable types handled by keyframes
763 bool Animation::HasFinished()
765 bool hasFinished(false);
766 const int playedCount(mAnimation->GetPlayedCount());
768 // If the play count has been incremented, then another notification is required
769 mCurrentLoop = mAnimation->GetCurrentLoop();
771 if (playedCount > mNotificationCount)
773 // Note that only one signal is emitted, if the animation has been played repeatedly
774 mNotificationCount = playedCount;
778 mState = Dali::Animation::STOPPED;
784 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
786 return mFinishedSignal;
789 Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal()
791 return mProgressReachedSignal;
794 void Animation::EmitSignalFinish()
796 if ( !mFinishedSignal.Empty() )
798 Dali::Animation handle( this );
799 mFinishedSignal.Emit( handle );
803 void Animation::EmitSignalProgressReached()
805 if ( !mProgressReachedSignal.Empty() )
807 Dali::Animation handle( this );
808 mProgressReachedSignal.Emit( handle );
812 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
814 bool connected( true );
815 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
817 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
819 animation->FinishedSignal().Connect( tracker, functor );
823 // signalName does not match any signal
830 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
832 DALI_ASSERT_DEBUG( NULL != connector );
834 connector->SetParent(*this);
836 mConnectors.PushBack( connector );
839 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
841 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
844 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
846 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
849 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
851 Animate( actor, path, forward, mDefaultAlpha, period );
854 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
856 ExtendDuration( period );
858 PathPtr pathCopy = Path::Clone(path);
861 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
862 Dali::Actor::Property::POSITION,
863 Property::INVALID_COMPONENT_INDEX,
864 new PathPositionFunctor( pathCopy ),
868 //If forward is zero, PathRotationFunctor will always return the unit quaternion
869 if( forward != Vector3::ZERO )
872 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
873 Dali::Actor::Property::ORIENTATION,
874 Property::INVALID_COMPONENT_INDEX,
875 new PathRotationFunctor( pathCopy, forward ),
881 void Animation::Show(Actor& actor, float delaySeconds)
883 ExtendDuration( TimePeriod(delaySeconds, 0) );
885 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
886 Dali::Actor::Property::VISIBLE,
887 Property::INVALID_COMPONENT_INDEX,
888 new AnimateToBoolean(SHOW_VALUE),
890 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
893 void Animation::Hide(Actor& actor, float delaySeconds)
895 ExtendDuration( TimePeriod(delaySeconds, 0) );
897 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
898 Dali::Actor::Property::VISIBLE,
899 Property::INVALID_COMPONENT_INDEX,
900 new AnimateToBoolean(HIDE_VALUE),
902 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
905 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
908 Animation* animation = dynamic_cast<Animation*>( object );
912 if( 0 == actionName.compare( ACTION_PLAY ) )
914 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
916 animation->SetDuration( value->Get<float>() );
922 else if( 0 == actionName.compare( ACTION_STOP ) )
927 else if( 0 == actionName.compare( ACTION_PAUSE ) )
937 void Animation::SetCurrentProgress(float progress)
939 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
941 // mAnimation is being used in a separate thread; queue a message to set the current progress
942 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
946 float Animation::GetCurrentProgress()
950 return mAnimation->GetCurrentProgress();
956 void Animation::ExtendDuration( const TimePeriod& timePeriod )
958 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
960 if( duration > mDurationSeconds )
962 SetDuration( duration );
966 void Animation::SetSpeedFactor( float factor )
970 mSpeedFactor = factor;
971 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
975 float Animation::GetSpeedFactor() const
980 void Animation::SetPlayRange( const Vector2& range)
982 //Make sure the range specified is between 0.0 and 1.0
983 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
985 Vector2 orderedRange( range );
986 //If the range is not in order swap values
987 if( range.x > range.y )
989 orderedRange = Vector2(range.y, range.x);
992 // Cache for public getters
993 mPlayRange = orderedRange;
995 // mAnimation is being used in a separate thread; queue a message to set play range
996 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
1000 Vector2 Animation::GetPlayRange() const
1005 bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
1007 return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
1010 void Animation::NotifyObjects()
1012 if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
1014 // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
1015 std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
1017 // Loop through all connector target values sorted by increasing end time
1018 ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
1019 const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
1020 for( ; iter != endIter; ++iter )
1022 AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
1024 Object* object = connector->GetObject();
1027 object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType );
1034 void Animation::SendFinalProgressNotificationMessage()
1036 if ( mProgressReachedMarker > 0.0f )
1038 float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker;
1039 SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds );
1043 } // namespace Internal