2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/animation/animation-impl.h>
20 #include <dali/public-api/object/property-map.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/animation/alpha-function.h>
27 #include <dali/public-api/animation/time-period.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/math/vector2.h>
31 #include <dali/public-api/math/radian.h>
32 #include <dali/internal/event/actors/actor-impl.h>
33 #include <dali/internal/event/animation/animation-playlist.h>
34 #include <dali/internal/event/animation/animator-connector.h>
35 #include <dali/internal/event/common/notification-manager.h>
36 #include <dali/internal/event/common/property-helper.h>
37 #include <dali/internal/event/common/stage-impl.h>
38 #include <dali/internal/event/common/thread-local-storage.h>
39 #include <dali/internal/event/effects/shader-effect-impl.h>
40 #include <dali/internal/update/manager/update-manager.h>
42 using Dali::Internal::SceneGraph::UpdateManager;
43 using Dali::Internal::SceneGraph::AnimatorBase;
44 using Dali::Internal::SceneGraph::Shader;
52 static bool SHOW_VALUE = true;
53 static bool HIDE_VALUE = false;
60 const char* const SIGNAL_FINISHED = "finished";
64 const char* const ACTION_PLAY = "play";
65 const char* const ACTION_STOP = "stop";
66 const char* const ACTION_PAUSE = "pause";
70 return Dali::Animation::New(0.f);
73 TypeRegistration mType( typeid( Dali::Animation ), typeid( Dali::BaseHandle ), Create );
75 SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &Animation::DoConnectSignal );
77 TypeAction action1( mType, ACTION_PLAY, &Animation::DoAction );
78 TypeAction action2( mType, ACTION_STOP, &Animation::DoAction );
79 TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction );
81 const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::Bake );
82 const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BakeFinal );
83 const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear );
84 const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
89 AnimationPtr Animation::New(float durationSeconds)
91 Stage* stage = Stage::GetCurrent();
95 AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
97 if( durationSeconds < 0.0f )
99 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
100 durationSeconds = 0.0f;
103 AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
105 // Second-phase construction
106 animation->Initialize();
116 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
117 : mEventThreadServices( eventThreadServices ),
118 mPlaylist( playlist ),
120 mNotificationCount( 0 ),
121 mFinishedCallback( NULL ),
122 mFinishedCallbackObject( NULL ),
123 mDurationSeconds( durationSeconds ),
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 = dynamic_cast<Object&>( GetImplementation(target.object) );
346 ExtendDuration( period );
348 switch ( relativeValue.GetType() )
350 case Property::BOOLEAN:
352 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
353 target.propertyIndex,
354 target.componentIndex,
355 new AnimateByBoolean(relativeValue.Get<bool>()),
361 case Property::INTEGER:
363 AddAnimatorConnector( AnimatorConnector<int>::New( object,
364 target.propertyIndex,
365 target.componentIndex,
366 new AnimateByInteger(relativeValue.Get<int>()),
372 case Property::FLOAT:
374 AddAnimatorConnector( AnimatorConnector<float>::New( object,
375 target.propertyIndex,
376 target.componentIndex,
377 new AnimateByFloat(relativeValue.Get<float>()),
383 case Property::VECTOR2:
385 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
386 target.propertyIndex,
387 target.componentIndex,
388 new AnimateByVector2(relativeValue.Get<Vector2>()),
394 case Property::VECTOR3:
396 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
397 target.propertyIndex,
398 target.componentIndex,
399 new AnimateByVector3(relativeValue.Get<Vector3>()),
405 case Property::VECTOR4:
407 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
408 target.propertyIndex,
409 target.componentIndex,
410 new AnimateByVector4(relativeValue.Get<Vector4>()),
416 case Property::ROTATION:
418 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
420 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
421 target.propertyIndex,
422 target.componentIndex,
423 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
430 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
435 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
437 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
440 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
442 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
445 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
447 AnimateTo(target, destinationValue, mDefaultAlpha, period);
450 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
452 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
454 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
457 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
459 Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
460 if(componentIndex != Property::INVALID_COMPONENT_INDEX)
462 if( type == Property::VECTOR2
463 || type == Property::VECTOR3
464 || type == Property::VECTOR4 )
466 type = Property::FLOAT;
469 DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
471 ExtendDuration( period );
473 switch (destinationValue.GetType())
475 case Property::BOOLEAN:
477 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
480 new AnimateToBoolean( destinationValue.Get<bool>() ),
486 case Property::INTEGER:
488 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
491 new AnimateToInteger( destinationValue.Get<int>() ),
497 case Property::FLOAT:
499 if ( ( Dali::Actor::Property::SIZE_WIDTH == targetPropertyIndex ) ||
500 ( Dali::Actor::Property::SIZE_HEIGHT == targetPropertyIndex ) ||
501 ( Dali::Actor::Property::SIZE_DEPTH == targetPropertyIndex ) )
503 // Test whether this is actually an Actor
504 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
507 // Notify the actor that its size is being animated
508 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
511 else if ( ( Dali::Actor::Property::POSITION_X == targetPropertyIndex ) ||
512 ( Dali::Actor::Property::POSITION_Y == targetPropertyIndex ) ||
513 ( Dali::Actor::Property::POSITION_Z == targetPropertyIndex ) )
515 // Test whether this is actually an Actor
516 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
519 // Notify the actor that its position is being animated
520 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<float>(), targetPropertyIndex );
524 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
527 new AnimateToFloat( destinationValue.Get<float>() ),
533 case Property::VECTOR2:
535 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
538 new AnimateToVector2( destinationValue.Get<Vector2>() ),
544 case Property::VECTOR3:
546 if ( Dali::Actor::Property::SIZE == targetPropertyIndex )
548 // Test whether this is actually an Actor
549 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
552 // Notify the actor that its size is being animated
553 maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
556 else if ( Dali::Actor::Property::POSITION == targetPropertyIndex )
558 // Test whether this is actually an Actor
559 Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
562 // Notify the actor that its position is being animated
563 maybeActor->NotifyPositionAnimation( *this, destinationValue.Get<Vector3>() );
567 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
570 new AnimateToVector3( destinationValue.Get<Vector3>() ),
576 case Property::VECTOR4:
578 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
581 new AnimateToVector4( destinationValue.Get<Vector4>() ),
587 case Property::ROTATION:
589 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
592 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
599 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
604 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
606 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
609 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
611 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
614 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
616 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
619 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
621 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
624 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
626 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
629 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
631 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
634 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
636 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
639 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
641 Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
643 ExtendDuration( period );
645 switch(keyFrames.GetType())
647 case Dali::Property::BOOLEAN:
649 const KeyFrameBoolean* kf;
650 GetSpecialization(keyFrames, kf);
651 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
652 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
653 target.propertyIndex,
654 target.componentIndex,
655 new KeyFrameBooleanFunctor(kfCopy),
661 case Dali::Property::INTEGER:
663 const KeyFrameInteger* kf;
664 GetSpecialization(keyFrames, kf);
665 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
666 AddAnimatorConnector( AnimatorConnector<int>::New( object,
667 target.propertyIndex,
668 target.componentIndex,
669 new KeyFrameIntegerFunctor(kfCopy,interpolation),
675 case Dali::Property::FLOAT:
677 const KeyFrameNumber* kf;
678 GetSpecialization(keyFrames, kf);
679 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
680 AddAnimatorConnector( AnimatorConnector<float>::New( object,
681 target.propertyIndex,
682 target.componentIndex,
683 new KeyFrameNumberFunctor(kfCopy,interpolation),
689 case Dali::Property::VECTOR2:
691 const KeyFrameVector2* kf;
692 GetSpecialization(keyFrames, kf);
693 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
694 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
695 target.propertyIndex,
696 target.componentIndex,
697 new KeyFrameVector2Functor(kfCopy,interpolation),
703 case Dali::Property::VECTOR3:
705 const KeyFrameVector3* kf;
706 GetSpecialization(keyFrames, kf);
707 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
708 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
709 target.propertyIndex,
710 target.componentIndex,
711 new KeyFrameVector3Functor(kfCopy,interpolation),
717 case Dali::Property::VECTOR4:
719 const KeyFrameVector4* kf;
720 GetSpecialization(keyFrames, kf);
721 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
722 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
723 target.propertyIndex,
724 target.componentIndex,
725 new KeyFrameVector4Functor(kfCopy,interpolation),
731 case Dali::Property::ROTATION:
733 const KeyFrameQuaternion* kf;
734 GetSpecialization(keyFrames, kf);
735 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
736 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
737 target.propertyIndex,
738 target.componentIndex,
739 new KeyFrameQuaternionFunctor(kfCopy),
745 default: // not all property types are animateable
750 bool Animation::HasFinished()
752 bool hasFinished(false);
753 const int playedCount(mAnimation->GetPlayedCount());
755 // If the play count has been incremented, then another notification is required
756 mCurrentLoop = mAnimation->GetCurrentLoop();
758 if (playedCount > mNotificationCount)
760 // Note that only one signal is emitted, if the animation has been played repeatedly
761 mNotificationCount = playedCount;
765 mState = Dali::Animation::STOPPED;
771 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
773 return mFinishedSignal;
776 void Animation::EmitSignalFinish()
778 if ( !mFinishedSignal.Empty() )
780 Dali::Animation handle( this );
781 mFinishedSignal.Emit( handle );
784 // This callback is used internally, to avoid the overhead of using a signal.
785 if ( mFinishedCallback )
787 mFinishedCallback( mFinishedCallbackObject );
791 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
793 bool connected( true );
794 Animation* animation = dynamic_cast<Animation*>(object);
796 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
798 animation->FinishedSignal().Connect( tracker, functor );
802 // signalName does not match any signal
809 void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
811 mFinishedCallback = callback;
812 mFinishedCallbackObject = object;
815 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
817 DALI_ASSERT_DEBUG( NULL != connector );
819 connector->SetParent(*this);
821 mConnectors.PushBack( connector );
824 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
826 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
829 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
831 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
834 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
836 Animate( actor, path, forward, mDefaultAlpha, period );
839 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
841 ExtendDuration( period );
843 PathPtr pathCopy = Path::Clone(path);
846 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
847 Dali::Actor::Property::POSITION,
848 Property::INVALID_COMPONENT_INDEX,
849 new PathPositionFunctor( pathCopy ),
853 //If forward is zero, PathRotationFunctor will always return the unit quaternion
854 if( forward != Vector3::ZERO )
857 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
858 Dali::Actor::Property::ORIENTATION,
859 Property::INVALID_COMPONENT_INDEX,
860 new PathRotationFunctor( pathCopy, forward ),
866 void Animation::Show(Actor& actor, float delaySeconds)
868 ExtendDuration( TimePeriod(delaySeconds, 0) );
870 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
871 Dali::Actor::Property::VISIBLE,
872 Property::INVALID_COMPONENT_INDEX,
873 new AnimateToBoolean(SHOW_VALUE),
875 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
878 void Animation::Hide(Actor& actor, float delaySeconds)
880 ExtendDuration( TimePeriod(delaySeconds, 0) );
882 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
883 Dali::Actor::Property::VISIBLE,
884 Property::INVALID_COMPONENT_INDEX,
885 new AnimateToBoolean(HIDE_VALUE),
887 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
890 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
893 Animation* animation = dynamic_cast<Animation*>( object );
897 if( 0 == actionName.compare( ACTION_PLAY ) )
899 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
901 animation->SetDuration( value->Get<float>() );
907 else if( 0 == actionName.compare( ACTION_STOP ) )
912 else if( 0 == actionName.compare( ACTION_PAUSE ) )
922 void Animation::SetCurrentProgress(float progress)
924 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
926 // mAnimation is being used in a separate thread; queue a message to set the current progress
927 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
931 float Animation::GetCurrentProgress()
935 return mAnimation->GetCurrentProgress();
941 void Animation::ExtendDuration( const TimePeriod& timePeriod )
943 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
945 if( duration > mDurationSeconds )
947 SetDuration( duration );
951 void Animation::SetSpeedFactor( float factor )
955 mSpeedFactor = factor;
956 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
960 float Animation::GetSpeedFactor() const
965 void Animation::SetPlayRange( const Vector2& range)
967 //Make sure the range specified is between 0.0 and 1.0
968 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
970 Vector2 orderedRange( range );
971 //If the range is not in order swap values
972 if( range.x > range.y )
974 orderedRange = Vector2(range.y, range.x);
977 // Cache for public getters
978 mPlayRange = orderedRange;
980 // mAnimation is being used in a separate thread; queue a message to set play range
981 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
985 Vector2 Animation::GetPlayRange() const
991 } // namespace Internal