2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/animation/animation-impl.h>
20 #include <dali/public-api/object/property-map.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/animation/alpha-function.h>
27 #include <dali/public-api/animation/time-period.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/math/vector2.h>
31 #include <dali/public-api/math/radian.h>
32 #include <dali/internal/event/actors/actor-impl.h>
33 #include <dali/internal/event/animation/animation-playlist.h>
34 #include <dali/internal/event/animation/animator-connector.h>
35 #include <dali/internal/event/common/notification-manager.h>
36 #include <dali/internal/event/common/property-helper.h>
37 #include <dali/internal/event/common/stage-impl.h>
38 #include <dali/internal/event/common/thread-local-storage.h>
39 #include <dali/internal/event/effects/shader-effect-impl.h>
40 #include <dali/internal/update/manager/update-manager.h>
42 using Dali::Internal::SceneGraph::UpdateManager;
43 using Dali::Internal::SceneGraph::AnimatorBase;
44 using Dali::Internal::SceneGraph::Shader;
52 static bool SHOW_VALUE = true;
53 static bool HIDE_VALUE = false;
60 const char* const SIGNAL_FINISHED = "finished";
64 const char* const ACTION_PLAY = "play";
65 const char* const ACTION_STOP = "stop";
66 const char* const ACTION_PAUSE = "pause";
70 return Dali::Animation::New(0.f);
73 TypeRegistration mType( typeid( Dali::Animation ), typeid( Dali::BaseHandle ), Create );
75 SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &Animation::DoConnectSignal );
77 TypeAction action1( mType, ACTION_PLAY, &Animation::DoAction );
78 TypeAction action2( mType, ACTION_STOP, &Animation::DoAction );
79 TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction );
81 const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::Bake );
82 const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BakeFinal );
83 const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear );
84 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
89 AnimationPtr Animation::New(float durationSeconds)
91 Stage* stage = Stage::GetCurrent();
95 AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
97 if( durationSeconds < 0.0f )
99 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
100 durationSeconds = 0.0f;
103 AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
105 // Second-phase construction
106 animation->Initialize();
116 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
117 : mEventThreadServices( eventThreadServices ),
118 mPlaylist( playlist ),
120 mNotificationCount( 0 ),
121 mFinishedCallback( NULL ),
122 mFinishedCallbackObject( NULL ),
123 mDurationSeconds( durationSeconds ),
127 mPlayRange( Vector2(0.0f,1.0f)),
128 mEndAction( endAction ),
129 mDisconnectAction( disconnectAction ),
130 mDefaultAlpha( defaultAlpha ),
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 // mAnimation is being used in a separate thread; queue a Play message
271 PlayAnimationMessage( mEventThreadServices, *mAnimation );
274 void Animation::PlayFrom( float progress )
276 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
278 // Update the current playlist
279 mPlaylist.OnPlay( *this );
281 mState = Dali::Animation::PLAYING;
283 // mAnimation is being used in a separate thread; queue a Play message
284 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
288 void Animation::Pause()
290 mState = Dali::Animation::PAUSED;
292 // mAnimation is being used in a separate thread; queue a Pause message
293 PauseAnimationMessage( mEventThreadServices, *mAnimation );
296 Dali::Animation::State Animation::GetState() const
301 void Animation::Stop()
303 mState = Dali::Animation::STOPPED;
305 // mAnimation is being used in a separate thread; queue a Stop message
306 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
309 void Animation::Clear()
311 DALI_ASSERT_DEBUG(mAnimation);
313 // Remove all the connectors
316 // Replace the old scene-object with a new one
317 DestroySceneObject();
320 // Reset the notification count, since the new scene-object has never been played
321 mNotificationCount = 0;
323 // Update the current playlist
324 mPlaylist.OnClear( *this );
327 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
329 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
332 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
334 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
337 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
339 AnimateBy(target, relativeValue, mDefaultAlpha, period);
342 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
344 Object& object = GetImplementation( target.object );
345 const Property::Type targetType = object.GetPropertyType( target.propertyIndex );
346 const Property::Type destinationType = relativeValue.GetType();
347 DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
349 ExtendDuration( period );
351 switch ( targetType )
353 case Property::BOOLEAN:
355 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
356 target.propertyIndex,
357 target.componentIndex,
358 new AnimateByBoolean(relativeValue.Get<bool>()),
364 case Property::INTEGER:
366 AddAnimatorConnector( AnimatorConnector<int>::New( object,
367 target.propertyIndex,
368 target.componentIndex,
369 new AnimateByInteger(relativeValue.Get<int>()),
375 case Property::FLOAT:
377 AddAnimatorConnector( AnimatorConnector<float>::New( object,
378 target.propertyIndex,
379 target.componentIndex,
380 new AnimateByFloat(relativeValue.Get<float>()),
386 case Property::VECTOR2:
388 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
389 target.propertyIndex,
390 target.componentIndex,
391 new AnimateByVector2(relativeValue.Get<Vector2>()),
397 case Property::VECTOR3:
399 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
400 target.propertyIndex,
401 target.componentIndex,
402 new AnimateByVector3(relativeValue.Get<Vector3>()),
408 case Property::VECTOR4:
410 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
411 target.propertyIndex,
412 target.componentIndex,
413 new AnimateByVector4(relativeValue.Get<Vector4>()),
419 case Property::ROTATION:
421 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
423 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
424 target.propertyIndex,
425 target.componentIndex,
426 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
434 // non animatable types handled already
439 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
441 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
444 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
446 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
449 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
451 AnimateTo(target, destinationValue, mDefaultAlpha, period);
454 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
456 Object& object = GetImplementation(target.object);
458 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
461 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
463 Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
464 if( componentIndex != Property::INVALID_COMPONENT_INDEX )
466 if( ( targetType == Property::VECTOR2 ) ||
467 ( targetType == Property::VECTOR3 ) ||
468 ( targetType == Property::VECTOR4 ) )
470 targetType = Property::FLOAT;
473 const Property::Type destinationType = destinationValue.GetType();
474 DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
476 ExtendDuration( period );
478 switch ( destinationType )
480 case Property::BOOLEAN:
482 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
485 new AnimateToBoolean( destinationValue.Get<bool>() ),
491 case Property::INTEGER:
493 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
496 new AnimateToInteger( destinationValue.Get<int>() ),
502 case Property::FLOAT:
504 if ( ( Dali::Actor::Property::SIZE_WIDTH == targetPropertyIndex ) ||
505 ( Dali::Actor::Property::SIZE_HEIGHT == targetPropertyIndex ) ||
506 ( Dali::Actor::Property::SIZE_DEPTH == targetPropertyIndex ) )
508 // Test whether this is actually an Actor
509 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
512 // Notify the actor that its size is being animated
513 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
516 else if ( ( Dali::Actor::Property::POSITION_X == targetPropertyIndex ) ||
517 ( Dali::Actor::Property::POSITION_Y == targetPropertyIndex ) ||
518 ( Dali::Actor::Property::POSITION_Z == targetPropertyIndex ) )
520 // Test whether this is actually an Actor
521 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
524 // Notify the actor that its position is being animated
525 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
529 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
532 new AnimateToFloat( destinationValue.Get<float>() ),
538 case Property::VECTOR2:
540 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
543 new AnimateToVector2( destinationValue.Get<Vector2>() ),
549 case Property::VECTOR3:
551 if ( Dali::Actor::Property::SIZE == targetPropertyIndex )
553 // Test whether this is actually an Actor
554 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
557 // Notify the actor that its size is being animated
558 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
561 else if ( Dali::Actor::Property::POSITION == targetPropertyIndex )
563 // Test whether this is actually an Actor
564 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
567 // Notify the actor that its position is being animated
568 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<Vector3>() );
572 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
575 new AnimateToVector3( destinationValue.Get<Vector3>() ),
581 case Property::VECTOR4:
583 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
586 new AnimateToVector4( destinationValue.Get<Vector4>() ),
592 case Property::ROTATION:
594 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
597 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
605 // non animatable types handled already
610 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
612 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
615 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
617 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
620 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
622 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
625 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
627 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
630 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
632 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
635 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
637 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
640 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
642 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
645 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
647 Object& object = GetImplementation( target.object );
649 ExtendDuration( period );
651 switch(keyFrames.GetType())
653 case Dali::Property::BOOLEAN:
655 const KeyFrameBoolean* kf;
656 GetSpecialization(keyFrames, kf);
657 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
658 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
659 target.propertyIndex,
660 target.componentIndex,
661 new KeyFrameBooleanFunctor(kfCopy),
667 case Dali::Property::INTEGER:
669 const KeyFrameInteger* kf;
670 GetSpecialization(keyFrames, kf);
671 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
672 AddAnimatorConnector( AnimatorConnector<int>::New( object,
673 target.propertyIndex,
674 target.componentIndex,
675 new KeyFrameIntegerFunctor(kfCopy,interpolation),
681 case Dali::Property::FLOAT:
683 const KeyFrameNumber* kf;
684 GetSpecialization(keyFrames, kf);
685 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
686 AddAnimatorConnector( AnimatorConnector<float>::New( object,
687 target.propertyIndex,
688 target.componentIndex,
689 new KeyFrameNumberFunctor(kfCopy,interpolation),
695 case Dali::Property::VECTOR2:
697 const KeyFrameVector2* kf;
698 GetSpecialization(keyFrames, kf);
699 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
700 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
701 target.propertyIndex,
702 target.componentIndex,
703 new KeyFrameVector2Functor(kfCopy,interpolation),
709 case Dali::Property::VECTOR3:
711 const KeyFrameVector3* kf;
712 GetSpecialization(keyFrames, kf);
713 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
714 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
715 target.propertyIndex,
716 target.componentIndex,
717 new KeyFrameVector3Functor(kfCopy,interpolation),
723 case Dali::Property::VECTOR4:
725 const KeyFrameVector4* kf;
726 GetSpecialization(keyFrames, kf);
727 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
728 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
729 target.propertyIndex,
730 target.componentIndex,
731 new KeyFrameVector4Functor(kfCopy,interpolation),
737 case Dali::Property::ROTATION:
739 const KeyFrameQuaternion* kf;
740 GetSpecialization(keyFrames, kf);
741 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
742 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
743 target.propertyIndex,
744 target.componentIndex,
745 new KeyFrameQuaternionFunctor(kfCopy),
753 // non animatable types handled by keyframes
758 bool Animation::HasFinished()
760 bool hasFinished(false);
761 const int playedCount(mAnimation->GetPlayedCount());
763 // If the play count has been incremented, then another notification is required
764 mCurrentLoop = mAnimation->GetCurrentLoop();
766 if (playedCount > mNotificationCount)
768 // Note that only one signal is emitted, if the animation has been played repeatedly
769 mNotificationCount = playedCount;
773 mState = Dali::Animation::STOPPED;
779 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
781 return mFinishedSignal;
784 void Animation::EmitSignalFinish()
786 if ( !mFinishedSignal.Empty() )
788 Dali::Animation handle( this );
789 mFinishedSignal.Emit( handle );
792 // This callback is used internally, to avoid the overhead of using a signal.
793 if ( mFinishedCallback )
795 mFinishedCallback( mFinishedCallbackObject );
799 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
801 bool connected( true );
802 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
804 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
806 animation->FinishedSignal().Connect( tracker, functor );
810 // signalName does not match any signal
817 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
819 mFinishedCallback = callback;
820 mFinishedCallbackObject = object;
823 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
825 DALI_ASSERT_DEBUG( NULL != connector );
827 connector->SetParent(*this);
829 mConnectors.PushBack( connector );
832 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
834 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
837 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
839 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
842 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
844 Animate( actor, path, forward, mDefaultAlpha, period );
847 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
849 ExtendDuration( period );
851 PathPtr pathCopy = Path::Clone(path);
854 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
855 Dali::Actor::Property::POSITION,
856 Property::INVALID_COMPONENT_INDEX,
857 new PathPositionFunctor( pathCopy ),
861 //If forward is zero, PathRotationFunctor will always return the unit quaternion
862 if( forward != Vector3::ZERO )
865 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
866 Dali::Actor::Property::ORIENTATION,
867 Property::INVALID_COMPONENT_INDEX,
868 new PathRotationFunctor( pathCopy, forward ),
874 void Animation::Show(Actor& actor, float delaySeconds)
876 ExtendDuration( TimePeriod(delaySeconds, 0) );
878 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
879 Dali::Actor::Property::VISIBLE,
880 Property::INVALID_COMPONENT_INDEX,
881 new AnimateToBoolean(SHOW_VALUE),
883 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
886 void Animation::Hide(Actor& actor, float delaySeconds)
888 ExtendDuration( TimePeriod(delaySeconds, 0) );
890 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
891 Dali::Actor::Property::VISIBLE,
892 Property::INVALID_COMPONENT_INDEX,
893 new AnimateToBoolean(HIDE_VALUE),
895 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
898 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
901 Animation* animation = dynamic_cast<Animation*>( object );
905 if( 0 == actionName.compare( ACTION_PLAY ) )
907 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
909 animation->SetDuration( value->Get<float>() );
915 else if( 0 == actionName.compare( ACTION_STOP ) )
920 else if( 0 == actionName.compare( ACTION_PAUSE ) )
930 void Animation::SetCurrentProgress(float progress)
932 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
934 // mAnimation is being used in a separate thread; queue a message to set the current progress
935 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
939 float Animation::GetCurrentProgress()
943 return mAnimation->GetCurrentProgress();
949 void Animation::ExtendDuration( const TimePeriod& timePeriod )
951 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
953 if( duration > mDurationSeconds )
955 SetDuration( duration );
959 void Animation::SetSpeedFactor( float factor )
963 mSpeedFactor = factor;
964 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
968 float Animation::GetSpeedFactor() const
973 void Animation::SetPlayRange( const Vector2& range)
975 //Make sure the range specified is between 0.0 and 1.0
976 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
978 Vector2 orderedRange( range );
979 //If the range is not in order swap values
980 if( range.x > range.y )
982 orderedRange = Vector2(range.y, range.x);
985 // Cache for public getters
986 mPlayRange = orderedRange;
988 // mAnimation is being used in a separate thread; queue a message to set play range
989 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
993 Vector2 Animation::GetPlayRange() const
999 } // namespace Internal