2 * Copyright (c) 2018 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 ),
133 mDelaySeconds( 0.0f ),
134 mAutoReverseEnabled( false )
138 void Animation::Initialize()
140 // Connect to the animation playlist
141 mPlaylist.AnimationCreated( *this );
148 Animation::~Animation()
150 // Guard to allow handle destruction after Core has been destroyed
151 if ( Stage::IsInstalled() )
153 // Disconnect from the animation playlist
154 mPlaylist.AnimationDestroyed( *this );
156 DestroySceneObject();
162 void Animation::CreateSceneObject()
164 DALI_ASSERT_DEBUG( mAnimation == NULL );
166 // Create a new animation, Keep a const pointer to the animation.
167 mAnimation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction );
168 OwnerPointer< SceneGraph::Animation > transferOwnership( const_cast< SceneGraph::Animation* >( mAnimation ) );
169 AddAnimationMessage( mEventThreadServices.GetUpdateManager(), transferOwnership );
172 void Animation::DestroySceneObject()
174 if ( mAnimation != NULL )
176 // Remove animation using a message to the update manager
177 RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
182 void Animation::SetDuration(float seconds)
186 DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
190 mDurationSeconds = seconds;
192 // mAnimation is being used in a separate thread; queue a message to set the value
193 SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
196 void Animation::SetProgressNotification( float progress )
198 // mAnimation is being used in a separate thread; queue a message to set the value
199 mProgressReachedMarker = progress;
202 float Animation::GetProgressNotification()
204 return mProgressReachedMarker;
207 float Animation::GetDuration() const
209 // This is not animatable; the cached value is up-to-date.
210 return mDurationSeconds;
213 void Animation::SetLooping(bool on)
215 SetLoopCount( on ? 0 : 1 );
218 void Animation::SetLoopCount(int count)
220 // Cache for public getters
223 // mAnimation is being used in a separate thread; queue a message to set the value
224 SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
227 int Animation::GetLoopCount()
232 int Animation::GetCurrentLoop()
237 bool Animation::IsLooping() const
239 return mLoopCount != 1;
242 void Animation::SetEndAction(EndAction action)
244 // Cache for public getters
247 // mAnimation is being used in a separate thread; queue a message to set the value
248 SetEndActionMessage( mEventThreadServices, *mAnimation, action );
251 Dali::Animation::EndAction Animation::GetEndAction() const
253 // This is not animatable; the cached value is up-to-date.
257 void Animation::SetDisconnectAction(EndAction action)
259 // Cache for public getters
260 mDisconnectAction = action;
262 // mAnimation is being used in a separate thread; queue a message to set the value
263 SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
266 Dali::Animation::EndAction Animation::GetDisconnectAction() const
268 // This is not animatable; the cached value is up-to-date.
269 return mDisconnectAction;
272 void Animation::Play()
274 // Update the current playlist
275 mPlaylist.OnPlay( *this );
277 mState = Dali::Animation::PLAYING;
281 SendFinalProgressNotificationMessage();
283 // mAnimation is being used in a separate thread; queue a Play message
284 PlayAnimationMessage( mEventThreadServices, *mAnimation );
287 void Animation::PlayFrom( float progress )
289 if( progress >= mPlayRange.x && progress <= mPlayRange.y )
291 // Update the current playlist
292 mPlaylist.OnPlay( *this );
294 mState = Dali::Animation::PLAYING;
298 SendFinalProgressNotificationMessage();
300 // mAnimation is being used in a separate thread; queue a Play message
301 PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
305 void Animation::PlayAfter( float delaySeconds )
307 // The negative delay means play immediately.
308 delaySeconds = std::max( 0.f, delaySeconds );
310 mDelaySeconds = delaySeconds;
312 // Update the current playlist
313 mPlaylist.OnPlay( *this );
315 mState = Dali::Animation::PLAYING;
319 SendFinalProgressNotificationMessage();
321 // mAnimation is being used in a separate thread; queue a message to set the value
322 PlayAfterMessage( mEventThreadServices, *mAnimation, delaySeconds );
325 void Animation::Pause()
327 mState = Dali::Animation::PAUSED;
329 // mAnimation is being used in a separate thread; queue a Pause message
330 PauseAnimationMessage( mEventThreadServices, *mAnimation );
333 Dali::Animation::State Animation::GetState() const
338 void Animation::Stop()
340 mState = Dali::Animation::STOPPED;
342 // mAnimation is being used in a separate thread; queue a Stop message
343 StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
346 void Animation::Clear()
348 DALI_ASSERT_DEBUG(mAnimation);
350 // Remove all the connectors
353 // Reset the connector target values
354 mConnectorTargetValues.clear();
356 // Replace the old scene-object with a new one
357 DestroySceneObject();
360 // Reset the notification count, since the new scene-object has never been played
361 mNotificationCount = 0;
363 // Update the current playlist
364 mPlaylist.OnClear( *this );
367 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
369 AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
372 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
374 AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
377 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
379 AnimateBy(target, relativeValue, mDefaultAlpha, period);
382 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
384 Object& object = GetImplementation(target.object);
385 const Property::Type targetType = object.GetPropertyType(target.propertyIndex);
386 const Property::Type destinationType = relativeValue.GetType();
388 if ( object.GetPropertyComponentIndex( target.propertyIndex ) != Property::INVALID_COMPONENT_INDEX )
390 DALI_ASSERT_ALWAYS(Property::FLOAT == destinationType && "Animated value and Property type don't match");
394 DALI_ASSERT_ALWAYS(targetType == destinationType && "Animated value and Property type don't match");
397 ExtendDuration(period);
399 // Store data to later notify the object that its property is being animated
400 ConnectorTargetValues connectorPair;
401 connectorPair.targetValue = relativeValue;
402 connectorPair.connectorIndex = mConnectors.Count();
403 connectorPair.timePeriod = period;
404 connectorPair.animatorType = Animation::BY;
405 mConnectorTargetValues.push_back( connectorPair );
407 switch ( targetType )
409 case Property::BOOLEAN:
411 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
412 target.propertyIndex,
413 target.componentIndex,
414 new AnimateByBoolean(relativeValue.Get<bool>()),
420 case Property::INTEGER:
422 AddAnimatorConnector( AnimatorConnector<int>::New( object,
423 target.propertyIndex,
424 target.componentIndex,
425 new AnimateByInteger(relativeValue.Get<int>()),
431 case Property::FLOAT:
433 AddAnimatorConnector( AnimatorConnector<float>::New( object,
434 target.propertyIndex,
435 target.componentIndex,
436 new AnimateByFloat(relativeValue.Get<float>()),
442 case Property::VECTOR2:
444 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
445 target.propertyIndex,
446 target.componentIndex,
447 new AnimateByVector2(relativeValue.Get<Vector2>()),
453 case Property::VECTOR3:
455 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
456 target.propertyIndex,
457 target.componentIndex,
458 new AnimateByVector3(relativeValue.Get<Vector3>()),
464 case Property::VECTOR4:
466 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
467 target.propertyIndex,
468 target.componentIndex,
469 new AnimateByVector4(relativeValue.Get<Vector4>()),
475 case Property::ROTATION:
477 AngleAxis angleAxis = relativeValue.Get<AngleAxis>();
479 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
480 target.propertyIndex,
481 target.componentIndex,
482 new RotateByAngleAxis(angleAxis.angle, angleAxis.axis),
490 // non animatable types handled already
495 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
497 AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
500 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
502 AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
505 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
507 AnimateTo(target, destinationValue, mDefaultAlpha, period);
510 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
512 Object& object = GetImplementation(target.object);
514 AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
517 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
519 Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
520 if( componentIndex != Property::INVALID_COMPONENT_INDEX )
522 if( ( targetType == Property::VECTOR2 ) ||
523 ( targetType == Property::VECTOR3 ) ||
524 ( targetType == Property::VECTOR4 ) )
526 targetType = Property::FLOAT;
529 const Property::Type destinationType = destinationValue.GetType();
530 DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
532 ExtendDuration( period );
534 // Store data to later notify the object that its property is being animated
535 ConnectorTargetValues connectorPair;
536 connectorPair.targetValue = destinationValue;
537 connectorPair.connectorIndex = mConnectors.Count();
538 connectorPair.timePeriod = period;
539 connectorPair.animatorType = Animation::TO;
540 mConnectorTargetValues.push_back( connectorPair );
542 switch ( destinationType )
544 case Property::BOOLEAN:
546 AddAnimatorConnector( AnimatorConnector<bool>::New( targetObject,
549 new AnimateToBoolean( destinationValue.Get<bool>() ),
555 case Property::INTEGER:
557 AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
560 new AnimateToInteger( destinationValue.Get<int>() ),
566 case Property::FLOAT:
568 AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
571 new AnimateToFloat( destinationValue.Get<float>() ),
577 case Property::VECTOR2:
579 AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
582 new AnimateToVector2( destinationValue.Get<Vector2>() ),
588 case Property::VECTOR3:
590 AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
593 new AnimateToVector3( destinationValue.Get<Vector3>() ),
599 case Property::VECTOR4:
601 AddAnimatorConnector( AnimatorConnector<Vector4>::New( targetObject,
604 new AnimateToVector4( destinationValue.Get<Vector4>() ),
610 case Property::ROTATION:
612 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( targetObject,
615 new RotateToQuaternion( destinationValue.Get<Quaternion>() ),
623 // non animatable types handled already
628 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
630 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
633 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
635 AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
638 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
640 AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION);
643 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation)
645 AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation);
648 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
650 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
653 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
655 AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
658 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
660 AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION);
663 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
665 Object& object = GetImplementation( target.object );
667 ExtendDuration( period );
669 // Store data to later notify the object that its property is being animated
670 ConnectorTargetValues connectorPair;
671 connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
672 connectorPair.connectorIndex = mConnectors.Count();
673 connectorPair.timePeriod = period;
674 connectorPair.animatorType = BETWEEN;
675 mConnectorTargetValues.push_back( connectorPair );
677 switch(keyFrames.GetType())
679 case Dali::Property::BOOLEAN:
681 const KeyFrameBoolean* kf;
682 GetSpecialization(keyFrames, kf);
683 KeyFrameBooleanPtr kfCopy = KeyFrameBoolean::Clone(*kf);
684 AddAnimatorConnector( AnimatorConnector<bool>::New( object,
685 target.propertyIndex,
686 target.componentIndex,
687 new KeyFrameBooleanFunctor(kfCopy),
693 case Dali::Property::INTEGER:
695 const KeyFrameInteger* kf;
696 GetSpecialization(keyFrames, kf);
697 KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf);
698 AddAnimatorConnector( AnimatorConnector<int>::New( object,
699 target.propertyIndex,
700 target.componentIndex,
701 new KeyFrameIntegerFunctor(kfCopy,interpolation),
707 case Dali::Property::FLOAT:
709 const KeyFrameNumber* kf;
710 GetSpecialization(keyFrames, kf);
711 KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
712 AddAnimatorConnector( AnimatorConnector<float>::New( object,
713 target.propertyIndex,
714 target.componentIndex,
715 new KeyFrameNumberFunctor(kfCopy,interpolation),
721 case Dali::Property::VECTOR2:
723 const KeyFrameVector2* kf;
724 GetSpecialization(keyFrames, kf);
725 KeyFrameVector2Ptr kfCopy = KeyFrameVector2::Clone(*kf);
726 AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
727 target.propertyIndex,
728 target.componentIndex,
729 new KeyFrameVector2Functor(kfCopy,interpolation),
735 case Dali::Property::VECTOR3:
737 const KeyFrameVector3* kf;
738 GetSpecialization(keyFrames, kf);
739 KeyFrameVector3Ptr kfCopy = KeyFrameVector3::Clone(*kf);
740 AddAnimatorConnector( AnimatorConnector<Vector3>::New( object,
741 target.propertyIndex,
742 target.componentIndex,
743 new KeyFrameVector3Functor(kfCopy,interpolation),
749 case Dali::Property::VECTOR4:
751 const KeyFrameVector4* kf;
752 GetSpecialization(keyFrames, kf);
753 KeyFrameVector4Ptr kfCopy = KeyFrameVector4::Clone(*kf);
754 AddAnimatorConnector( AnimatorConnector<Vector4>::New( object,
755 target.propertyIndex,
756 target.componentIndex,
757 new KeyFrameVector4Functor(kfCopy,interpolation),
763 case Dali::Property::ROTATION:
765 const KeyFrameQuaternion* kf;
766 GetSpecialization(keyFrames, kf);
767 KeyFrameQuaternionPtr kfCopy = KeyFrameQuaternion::Clone(*kf);
768 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( object,
769 target.propertyIndex,
770 target.componentIndex,
771 new KeyFrameQuaternionFunctor(kfCopy),
779 // non animatable types handled by keyframes
784 bool Animation::HasFinished()
786 bool hasFinished(false);
787 const int playedCount(mAnimation->GetPlayedCount());
789 // If the play count has been incremented, then another notification is required
790 mCurrentLoop = mAnimation->GetCurrentLoop();
792 if (playedCount > mNotificationCount)
794 // Note that only one signal is emitted, if the animation has been played repeatedly
795 mNotificationCount = playedCount;
799 mState = Dali::Animation::STOPPED;
805 Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
807 return mFinishedSignal;
810 Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal()
812 return mProgressReachedSignal;
815 void Animation::EmitSignalFinish()
817 if ( !mFinishedSignal.Empty() )
819 Dali::Animation handle( this );
820 mFinishedSignal.Emit( handle );
824 void Animation::EmitSignalProgressReached()
826 if ( !mProgressReachedSignal.Empty() )
828 Dali::Animation handle( this );
829 mProgressReachedSignal.Emit( handle );
833 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
835 bool connected( true );
836 Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
838 if( 0 == signalName.compare( SIGNAL_FINISHED ) )
840 animation->FinishedSignal().Connect( tracker, functor );
844 // signalName does not match any signal
851 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
853 DALI_ASSERT_DEBUG( NULL != connector );
855 connector->SetParent(*this);
857 mConnectors.PushBack( connector );
860 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
862 Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
865 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
867 Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
870 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
872 Animate( actor, path, forward, mDefaultAlpha, period );
875 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period)
877 ExtendDuration( period );
879 PathPtr pathCopy = Path::Clone(path);
882 AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
883 Dali::Actor::Property::POSITION,
884 Property::INVALID_COMPONENT_INDEX,
885 new PathPositionFunctor( pathCopy ),
889 //If forward is zero, PathRotationFunctor will always return the unit quaternion
890 if( forward != Vector3::ZERO )
893 AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
894 Dali::Actor::Property::ORIENTATION,
895 Property::INVALID_COMPONENT_INDEX,
896 new PathRotationFunctor( pathCopy, forward ),
902 void Animation::Show(Actor& actor, float delaySeconds)
904 ExtendDuration( TimePeriod(delaySeconds, 0) );
906 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
907 Dali::Actor::Property::VISIBLE,
908 Property::INVALID_COMPONENT_INDEX,
909 new AnimateToBoolean(SHOW_VALUE),
911 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
914 void Animation::Hide(Actor& actor, float delaySeconds)
916 ExtendDuration( TimePeriod(delaySeconds, 0) );
918 AddAnimatorConnector( AnimatorConnector<bool>::New( actor,
919 Dali::Actor::Property::VISIBLE,
920 Property::INVALID_COMPONENT_INDEX,
921 new AnimateToBoolean(HIDE_VALUE),
923 TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
926 bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
929 Animation* animation = dynamic_cast<Animation*>( object );
933 if( 0 == actionName.compare( ACTION_PLAY ) )
935 if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
937 animation->SetDuration( value->Get<float>() );
943 else if( 0 == actionName.compare( ACTION_STOP ) )
948 else if( 0 == actionName.compare( ACTION_PAUSE ) )
958 void Animation::SetCurrentProgress(float progress)
960 if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
962 // mAnimation is being used in a separate thread; queue a message to set the current progress
963 SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
967 float Animation::GetCurrentProgress()
971 return mAnimation->GetCurrentProgress();
977 void Animation::ExtendDuration( const TimePeriod& timePeriod )
979 float duration = timePeriod.delaySeconds + timePeriod.durationSeconds;
981 if( duration > mDurationSeconds )
983 SetDuration( duration );
987 void Animation::SetSpeedFactor( float factor )
991 mSpeedFactor = factor;
992 SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
996 float Animation::GetSpeedFactor() const
1001 void Animation::SetPlayRange( const Vector2& range)
1003 //Make sure the range specified is between 0.0 and 1.0
1004 if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f )
1006 Vector2 orderedRange( range );
1007 //If the range is not in order swap values
1008 if( range.x > range.y )
1010 orderedRange = Vector2(range.y, range.x);
1013 // Cache for public getters
1014 mPlayRange = orderedRange;
1016 // mAnimation is being used in a separate thread; queue a message to set play range
1017 SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
1021 Vector2 Animation::GetPlayRange() const
1026 void Animation::SetLoopingMode( Dali::Animation::LoopingMode loopingMode )
1028 mAutoReverseEnabled = ( loopingMode == Dali::Animation::LoopingMode::AUTO_REVERSE );
1030 // mAnimation is being used in a separate thread; queue a message to set play range
1031 SetLoopingModeMessage( mEventThreadServices, *mAnimation, mAutoReverseEnabled );
1034 Dali::Animation::LoopingMode Animation::GetLoopingMode() const
1036 return mAutoReverseEnabled ? Dali::Animation::AUTO_REVERSE : Dali::Animation::RESTART;
1039 bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
1041 return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
1044 void Animation::NotifyObjects()
1046 if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
1048 // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
1049 std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
1051 // Loop through all connector target values sorted by increasing end time
1052 ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
1053 const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
1054 for( ; iter != endIter; ++iter )
1056 AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
1058 Object* object = connector->GetObject();
1061 object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType );
1068 void Animation::SendFinalProgressNotificationMessage()
1070 if ( mProgressReachedMarker > 0.0f )
1072 float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker;
1073 SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds );
1077 } // namespace Internal