X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fanimation%2Fanimation-impl.cpp;h=876ec296d6a37087bd971ee91bb1fb8396081eb8;hb=d8944bba8449a3c5bce03041eccccf2eba4a7ae3;hp=d5c26b73ccbd65fc647bf84a4f2ff84f1313bf2e;hpb=9390d7e1f94dfd2011ae6a463f1af6cecb80770a;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/animation/animation-impl.cpp b/dali/internal/event/animation/animation-impl.cpp index d5c26b7..876ec29 100644 --- a/dali/internal/event/animation/animation-impl.cpp +++ b/dali/internal/event/animation/animation-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,26 +17,25 @@ // CLASS HEADER #include +#include // EXTERNAL INCLUDES -#include // for strcmp // INTERNAL INCLUDES -#include -#include +#include #include #include #include #include #include -#include #include #include +#include #include #include #include #include -#include +#include #include using Dali::Internal::SceneGraph::UpdateManager; @@ -81,17 +80,74 @@ TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction ); const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::Bake ); const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BakeFinal ); const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear ); +const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT ); -} // anon namespace +/** + * Helper to tell if a property is animatable (if we have animators for it) + * + * @param type type to check + * @return true if animatable + */ +inline bool IsAnimatable( Property::Type type ) +{ + bool animatable = false; + switch( type ) + { + case Property::BOOLEAN : + case Property::FLOAT : + case Property::INTEGER : + case Property::VECTOR2 : + case Property::VECTOR3 : + case Property::VECTOR4 : + case Property::ROTATION : + { + animatable = true; + break; + } + case Property::MATRIX : // matrix is allowed as a scene graph property but there's no animators for it + case Property::MATRIX3 : // matrix3 is allowed as a scene graph property but there's no animators for it + case Property::NONE : + case Property::RECTANGLE : + case Property::STRING : + case Property::ARRAY : + case Property::MAP : + case Property::EXTENTS : + { + break; + } + } + return animatable; +} + +/** + * Helper to validate animation input values + * + * @param propertyType type of the property that is being animated + * @param destinationType type of the target + * @param period time period of the animation + */ +void ValidateParameters( Property::Type propertyType, Property::Type destinationType, const TimePeriod& period ) +{ + // destination value has to be animatable + DALI_ASSERT_ALWAYS( IsAnimatable( propertyType ) && "Property type is not animatable" ); + DALI_ASSERT_ALWAYS( IsAnimatable( destinationType ) && "Target value is not animatable" ); + DALI_ASSERT_ALWAYS( propertyType == destinationType && "Property and target types don't match" ); + DALI_ASSERT_ALWAYS( period.durationSeconds >= 0 && "Duration must be >=0" ); +} + +} // anonymous namespace AnimationPtr Animation::New(float durationSeconds) { - Stage* stage = Stage::GetCurrent(); - - AnimationPlaylist& playlist = stage->GetAnimationPlaylist(); + if( durationSeconds < 0.0f ) + { + DALI_LOG_WARNING("duration should be greater than 0.0f.\n"); + durationSeconds = 0.0f; + } - AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, Dali::AlphaFunctions::Linear ); + ThreadLocalStorage& tls = ThreadLocalStorage::Get(); + AnimationPtr animation = new Animation( tls.GetEventThreadServices(), tls.GetAnimationPlaylist(), durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION ); // Second-phase construction animation->Initialize(); @@ -100,19 +156,25 @@ AnimationPtr Animation::New(float durationSeconds) } Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha ) -: mEventThreadServices( eventThreadServices ), +: mAnimation( NULL ), + mEventThreadServices( eventThreadServices ), mPlaylist( playlist ), - mAnimation( NULL ), - mNotificationCount( 0 ), - mFinishedCallback( NULL ), - mFinishedCallbackObject( NULL ), + mFinishedSignal(), + mConnectors(), + mConnectorTargetValues(), + mPlayRange( Vector2(0.0f,1.0f)), mDurationSeconds( durationSeconds ), mSpeedFactor(1.0f), - mIsLooping( false ), - mPlayRange( Vector2(0.0f,1.0f)), + mNotificationCount( 0 ), + mLoopCount(1), + mCurrentLoop(0), mEndAction( endAction ), mDisconnectAction( disconnectAction ), - mDefaultAlpha( defaultAlpha ) + mDefaultAlpha( defaultAlpha ), + mState(Dali::Animation::STOPPED), + mProgressReachedMarker( 0.0f ), + mDelaySeconds( 0.0f ), + mAutoReverseEnabled( false ) { } @@ -144,14 +206,10 @@ void Animation::CreateSceneObject() { DALI_ASSERT_DEBUG( mAnimation == NULL ); - // Create a new animation, temporarily owned - SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mIsLooping, mEndAction, mDisconnectAction ); - - // Keep a const pointer to the animation. - mAnimation = animation; - - // Transfer animation ownership to the update manager through a message - AddAnimationMessage( mEventThreadServices.GetUpdateManager(), animation ); + // Create a new animation, Keep a const pointer to the animation. + mAnimation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction ); + OwnerPointer< SceneGraph::Animation > transferOwnership( const_cast< SceneGraph::Animation* >( mAnimation ) ); + AddAnimationMessage( mEventThreadServices.GetUpdateManager(), transferOwnership ); } void Animation::DestroySceneObject() @@ -166,32 +224,62 @@ void Animation::DestroySceneObject() void Animation::SetDuration(float seconds) { - // Cache for public getters + if( seconds < 0.0f ) + { + DALI_LOG_WARNING("duration should be greater than 0.0f.\n"); + seconds = 0.0f; + } + mDurationSeconds = seconds; // mAnimation is being used in a separate thread; queue a message to set the value SetDurationMessage( mEventThreadServices, *mAnimation, seconds ); } +void Animation::SetProgressNotification( float progress ) +{ + // mAnimation is being used in a separate thread; queue a message to set the value + mProgressReachedMarker = progress; +} + +float Animation::GetProgressNotification() +{ + return mProgressReachedMarker; +} + float Animation::GetDuration() const { // This is not animatable; the cached value is up-to-date. return mDurationSeconds; } -void Animation::SetLooping(bool looping) +void Animation::SetLooping(bool on) +{ + SetLoopCount( on ? 0 : 1 ); +} + +void Animation::SetLoopCount(int32_t count) { // Cache for public getters - mIsLooping = looping; + mLoopCount = count; // mAnimation is being used in a separate thread; queue a message to set the value - SetLoopingMessage( mEventThreadServices, *mAnimation, looping ); + SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount ); +} + +int32_t Animation::GetLoopCount() +{ + return mLoopCount; +} + +int32_t Animation::GetCurrentLoop() +{ + return mCurrentLoop; } bool Animation::IsLooping() const { - // This is not animatable; the cached value is up-to-date. - return mIsLooping; + return mLoopCount != 1; } void Animation::SetEndAction(EndAction action) @@ -229,6 +317,12 @@ void Animation::Play() // Update the current playlist mPlaylist.OnPlay( *this ); + mState = Dali::Animation::PLAYING; + + NotifyObjects(); + + SendFinalProgressNotificationMessage(); + // mAnimation is being used in a separate thread; queue a Play message PlayAnimationMessage( mEventThreadServices, *mAnimation ); } @@ -240,19 +334,54 @@ void Animation::PlayFrom( float progress ) // Update the current playlist mPlaylist.OnPlay( *this ); + mState = Dali::Animation::PLAYING; + + NotifyObjects(); + + SendFinalProgressNotificationMessage(); + // mAnimation is being used in a separate thread; queue a Play message PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress ); } } +void Animation::PlayAfter( float delaySeconds ) +{ + // The negative delay means play immediately. + delaySeconds = std::max( 0.f, delaySeconds ); + + mDelaySeconds = delaySeconds; + + // Update the current playlist + mPlaylist.OnPlay( *this ); + + mState = Dali::Animation::PLAYING; + + NotifyObjects(); + + SendFinalProgressNotificationMessage(); + + // mAnimation is being used in a separate thread; queue a message to set the value + PlayAfterMessage( mEventThreadServices, *mAnimation, delaySeconds ); +} + void Animation::Pause() { + mState = Dali::Animation::PAUSED; + // mAnimation is being used in a separate thread; queue a Pause message PauseAnimationMessage( mEventThreadServices, *mAnimation ); } +Dali::Animation::State Animation::GetState() const +{ + return mState; +} + void Animation::Stop() { + mState = Dali::Animation::STOPPED; + // mAnimation is being used in a separate thread; queue a Stop message StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation ); } @@ -264,6 +393,9 @@ void Animation::Clear() // Remove all the connectors mConnectors.Clear(); + // Reset the connector target values + mConnectorTargetValues.clear(); + // Replace the old scene-object with a new one DestroySceneObject(); CreateSceneObject(); @@ -275,28 +407,43 @@ void Animation::Clear() mPlaylist.OnClear( *this ); } -void Animation::AnimateBy(Property& target, Property::Value& relativeValue) +void Animation::AnimateBy( Property& target, Property::Value& relativeValue ) { - AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds); + AnimateBy( target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds) ); } -void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha) +void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha ) { - AnimateBy(target, relativeValue, alpha, mDurationSeconds); + AnimateBy( target, relativeValue, alpha, TimePeriod(mDurationSeconds) ); } -void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period) +void Animation::AnimateBy( Property& target, Property::Value& relativeValue, TimePeriod period ) { - AnimateBy(target, relativeValue, AlphaFunctions::Default, period); + AnimateBy( target, relativeValue, mDefaultAlpha, period ); } -void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period) +void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period ) { - Object& object = dynamic_cast( GetImplementation(target.object) ); - - ExtendDuration( period ); - - switch ( relativeValue.GetType() ) + Object& object = GetImplementation(target.object); + const Property::Type propertyType = object.GetPropertyType( target.propertyIndex ); + const Property::Type destinationType = relativeValue.GetType(); + + // validate animation parameters, if component index is set then use float as checked type + ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT, + destinationType, period ); + + ExtendDuration(period); + + // Store data to later notify the object that its property is being animated + ConnectorTargetValues connectorPair; + connectorPair.targetValue = relativeValue; + connectorPair.connectorIndex = mConnectors.Count(); + connectorPair.timePeriod = period; + connectorPair.animatorType = Animation::BY; + mConnectorTargetValues.push_back( connectorPair ); + + // using destination type so component animation gets correct type + switch ( destinationType ) { case Property::BOOLEAN: { @@ -309,6 +456,17 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph break; } + case Property::INTEGER: + { + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, + new AnimateByInteger(relativeValue.Get()), + alpha, + period ) ); + break; + } + case Property::FLOAT: { AddAnimatorConnector( AnimatorConnector::New( object, @@ -320,17 +478,6 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph break; } - case Property::INTEGER: - { - AddAnimatorConnector( AnimatorConnector::New( object, - target.propertyIndex, - target.componentIndex, - new AnimateByInteger(relativeValue.Get()), - alpha, - period ) ); - break; - } - case Property::VECTOR2: { AddAnimatorConnector( AnimatorConnector::New( object, @@ -378,89 +525,88 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph } default: - DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here - break; + { + // non animatable types handled already + } } } -void Animation::AnimateTo(Property& target, Property::Value& destinationValue) +void Animation::AnimateTo( Property& target, Property::Value& destinationValue ) { - AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds); + AnimateTo( target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds) ); } -void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha) +void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha ) { - AnimateTo(target, destinationValue, alpha, mDurationSeconds); + AnimateTo( target, destinationValue, alpha, TimePeriod(mDurationSeconds)); } -void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period) +void Animation::AnimateTo( Property& target, Property::Value& destinationValue, TimePeriod period ) { - AnimateTo(target, destinationValue, AlphaFunctions::Default, period); + AnimateTo( target, destinationValue, mDefaultAlpha, period ); } -void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period) +void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period ) { - Object& object = dynamic_cast( GetImplementation(target.object) ); + Object& object = GetImplementation( target.object ); + const Property::Type propertyType = object.GetPropertyType( target.propertyIndex ); + const Property::Type destinationType = destinationValue.GetType(); - AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period ); -} - -void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period) -{ - Property::Type type = targetObject.GetPropertyType(targetPropertyIndex); - if(componentIndex != Property::INVALID_COMPONENT_INDEX) - { - if( type == Property::VECTOR2 - || type == Property::VECTOR3 - || type == Property::VECTOR4 ) - { - type = Property::FLOAT; - } - } - DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" ); + // validate animation parameters, if component index is set then use float as checked type + ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT, + destinationType, period ); ExtendDuration( period ); - switch (destinationValue.GetType()) + // Store data to later notify the object that its property is being animated + ConnectorTargetValues connectorPair; + connectorPair.targetValue = destinationValue; + connectorPair.connectorIndex = mConnectors.Count(); + connectorPair.timePeriod = period; + connectorPair.animatorType = Animation::TO; + mConnectorTargetValues.push_back( connectorPair ); + + // using destination type so component animation gets correct type + switch ( destinationType ) { case Property::BOOLEAN: { - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, new AnimateToBoolean( destinationValue.Get() ), alpha, period ) ); break; } - case Property::FLOAT: + case Property::INTEGER: { - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, - new AnimateToFloat( destinationValue.Get() ), - alpha, - period ) ); + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, + new AnimateToInteger( destinationValue.Get() ), + alpha, + period ) ); break; } - case Property::INTEGER: + case Property::FLOAT: { - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, - new AnimateToInteger( destinationValue.Get() ), - alpha, - period ) ); + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, + new AnimateToFloat( destinationValue.Get() ), + alpha, + period ) ); break; } case Property::VECTOR2: { - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, new AnimateToVector2( destinationValue.Get() ), alpha, period ) ); @@ -469,20 +615,9 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn case Property::VECTOR3: { - if ( Dali::Actor::Property::SIZE == targetPropertyIndex ) - { - // Test whether this is actually an Actor - Actor* maybeActor = dynamic_cast( &targetObject ); - if ( maybeActor ) - { - // Notify the actor that its size is being animated - maybeActor->NotifySizeAnimation( *this, destinationValue.Get() ); - } - } - - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, new AnimateToVector3( destinationValue.Get() ), alpha, period ) ); @@ -491,9 +626,9 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn case Property::VECTOR4: { - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, new AnimateToVector4( destinationValue.Get() ), alpha, period ) ); @@ -502,9 +637,9 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn case Property::ROTATION: { - AddAnimatorConnector( AnimatorConnector::New( targetObject, - targetPropertyIndex, - componentIndex, + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, new RotateToQuaternion( destinationValue.Get() ), alpha, period ) ); @@ -512,53 +647,69 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn } default: - DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here - break; + { + // non animatable types handled already + } } } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames ) { - AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds, DEFAULT_INTERPOLATION ); + AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation ) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, Interpolation interpolation ) { - AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds, interpolation ); + AnimateBetween( target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period ) { - AnimateBetween(target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION); + AnimateBetween( target, keyFrames, mDefaultAlpha, period, DEFAULT_INTERPOLATION ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation ) { - AnimateBetween(target, keyFrames, mDefaultAlpha, period, interpolation); + AnimateBetween( target, keyFrames, mDefaultAlpha, period, interpolation ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha ) { - AnimateBetween(target, keyFrames, alpha, mDurationSeconds, DEFAULT_INTERPOLATION); + AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation ) { - AnimateBetween(target, keyFrames, alpha, mDurationSeconds, interpolation); + AnimateBetween( target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period ) { - AnimateBetween(target, keyFrames, alpha, period, DEFAULT_INTERPOLATION); + AnimateBetween( target, keyFrames, alpha, period, DEFAULT_INTERPOLATION ); } -void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation) +void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation ) { - Object& object = dynamic_cast( GetImplementation(target.object) ); + Object& object = GetImplementation( target.object ); + const Property::Type propertyType = object.GetPropertyType( target.propertyIndex ); + const Property::Type destinationType = keyFrames.GetType(); + + // validate animation parameters, if component index is set then use float as checked type + ValidateParameters( (target.componentIndex == Property::INVALID_COMPONENT_INDEX) ? propertyType : Property::FLOAT, + destinationType, period ); ExtendDuration( period ); - switch(keyFrames.GetType()) + // Store data to later notify the object that its property is being animated + ConnectorTargetValues connectorPair; + connectorPair.targetValue = keyFrames.GetLastKeyFrameValue(); + connectorPair.connectorIndex = mConnectors.Count(); + connectorPair.timePeriod = period; + connectorPair.animatorType = BETWEEN; + mConnectorTargetValues.push_back( connectorPair ); + + // using destination type so component animation gets correct type + switch( destinationType ) { case Dali::Property::BOOLEAN: { @@ -574,6 +725,20 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph break; } + case Dali::Property::INTEGER: + { + const KeyFrameInteger* kf; + GetSpecialization(keyFrames, kf); + KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf); + AddAnimatorConnector( AnimatorConnector::New( object, + target.propertyIndex, + target.componentIndex, + new KeyFrameIntegerFunctor(kfCopy,interpolation), + alpha, + period ) ); + break; + } + case Dali::Property::FLOAT: { const KeyFrameNumber* kf; @@ -588,20 +753,6 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph break; } - case Dali::Property::INTEGER: - { - const KeyFrameInteger* kf; - GetSpecialization(keyFrames, kf); - KeyFrameIntegerPtr kfCopy = KeyFrameInteger::Clone(*kf); - AddAnimatorConnector( AnimatorConnector::New( object, - target.propertyIndex, - target.componentIndex, - new KeyFrameIntegerFunctor(kfCopy,interpolation), - alpha, - period ) ); - break; - } - case Dali::Property::VECTOR2: { const KeyFrameVector2* kf; @@ -658,23 +809,29 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph break; } - default: // not all property types are animateable - break; + default: + { + // non animatable types handled by keyframes + } } } bool Animation::HasFinished() { bool hasFinished(false); - const int playCount(mAnimation->GetPlayCount()); + const int32_t playedCount(mAnimation->GetPlayedCount()); // If the play count has been incremented, then another notification is required - if (playCount > mNotificationCount) + mCurrentLoop = mAnimation->GetCurrentLoop(); + + if (playedCount > mNotificationCount) { // Note that only one signal is emitted, if the animation has been played repeatedly - mNotificationCount = playCount; + mNotificationCount = playedCount; hasFinished = true; + + mState = Dali::Animation::STOPPED; } return hasFinished; @@ -685,6 +842,11 @@ Dali::Animation::AnimationSignalType& Animation::FinishedSignal() return mFinishedSignal; } +Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal() +{ + return mProgressReachedSignal; +} + void Animation::EmitSignalFinish() { if ( !mFinishedSignal.Empty() ) @@ -692,38 +854,31 @@ void Animation::EmitSignalFinish() Dali::Animation handle( this ); mFinishedSignal.Emit( handle ); } +} - // This callback is used internally, to avoid the overhead of using a signal. - if ( mFinishedCallback ) +void Animation::EmitSignalProgressReached() +{ + if ( !mProgressReachedSignal.Empty() ) { - mFinishedCallback( mFinishedCallbackObject ); + Dali::Animation handle( this ); + mProgressReachedSignal.Emit( handle ); } } bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { - bool connected( true ); - Animation* animation = dynamic_cast(object); + bool connected( false ); + Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type. - if ( 0 == strcmp( signalName.c_str(), SIGNAL_FINISHED ) ) + if( 0 == signalName.compare( SIGNAL_FINISHED ) ) { animation->FinishedSignal().Connect( tracker, functor ); - } - else - { - // signalName does not match any signal - connected = false; + connected = true; } return connected; } -void Animation::SetFinishedCallback( FinishedCallback callback, Object* object ) -{ - mFinishedCallback = callback; - mFinishedCallbackObject = object; -} - void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector ) { DALI_ASSERT_DEBUG( NULL != connector ); @@ -735,12 +890,12 @@ void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector ) void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward ) { - Animate( actor, path, forward, mDefaultAlpha, TimePeriod(0.0f,GetDuration()) ); + Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) ); } void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha ) { - Animate( actor, path, forward, alpha, TimePeriod(0.0f,GetDuration()) ); + Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) ); } void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period ) @@ -783,7 +938,7 @@ void Animation::Show(Actor& actor, float delaySeconds) Dali::Actor::Property::VISIBLE, Property::INVALID_COMPONENT_INDEX, new AnimateToBoolean(SHOW_VALUE), - AlphaFunctions::Default, + mDefaultAlpha, TimePeriod(delaySeconds, 0.0f/*immediate*/) ) ); } @@ -795,33 +950,33 @@ void Animation::Hide(Actor& actor, float delaySeconds) Dali::Actor::Property::VISIBLE, Property::INVALID_COMPONENT_INDEX, new AnimateToBoolean(HIDE_VALUE), - AlphaFunctions::Default, + mDefaultAlpha, TimePeriod(delaySeconds, 0.0f/*immediate*/) ) ); } -bool Animation::DoAction( BaseObject* object, const std::string& actionName, const std::vector& attributes ) +bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) { bool done = false; Animation* animation = dynamic_cast( object ); if( animation ) { - if( 0 == strcmp( actionName.c_str(), ACTION_PLAY ) ) + if( 0 == actionName.compare( ACTION_PLAY ) ) { - if( attributes.size() > 0 ) + if( Property::Value* value = attributes.Find("duration", Property::FLOAT) ) { - animation->SetDuration( attributes[0].Get() ); + animation->SetDuration( value->Get() ); } animation->Play(); done = true; } - else if( 0 == strcmp( actionName.c_str(), ACTION_STOP ) ) + else if( 0 == actionName.compare( ACTION_STOP ) ) { animation->Stop(); done = true; } - else if( 0 == strcmp( actionName.c_str(), ACTION_PAUSE ) ) + else if( 0 == actionName.compare( ACTION_PAUSE ) ) { animation->Pause(); done = true; @@ -842,12 +997,13 @@ void Animation::SetCurrentProgress(float progress) float Animation::GetCurrentProgress() { - if( mAnimation ) + float progress = 0.f; + if( mAnimation ) // always exists in practice { - return mAnimation->GetCurrentProgress(); + progress = mAnimation->GetCurrentProgress(); } - return 0.0f; + return progress; } void Animation::ExtendDuration( const TimePeriod& timePeriod ) @@ -899,6 +1055,56 @@ Vector2 Animation::GetPlayRange() const return mPlayRange; } +void Animation::SetLoopingMode( Dali::Animation::LoopingMode loopingMode ) +{ + mAutoReverseEnabled = ( loopingMode == Dali::Animation::LoopingMode::AUTO_REVERSE ); + + // mAnimation is being used in a separate thread; queue a message to set play range + SetLoopingModeMessage( mEventThreadServices, *mAnimation, mAutoReverseEnabled ); +} + +Dali::Animation::LoopingMode Animation::GetLoopingMode() const +{ + return mAutoReverseEnabled ? Dali::Animation::AUTO_REVERSE : Dali::Animation::RESTART; +} + +bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs ) +{ + return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) ); +} + +void Animation::NotifyObjects() +{ + if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values + { + // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved + std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes ); + + // Loop through all connector target values sorted by increasing end time + ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin(); + const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end(); + for( ; iter != endIter; ++iter ) + { + AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ]; + + Object* object = connector->GetObject(); + if( object ) + { + object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType ); + } + } + } +} + + +void Animation::SendFinalProgressNotificationMessage() +{ + if ( mProgressReachedMarker > 0.0f ) + { + float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker; + SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds ); + } +} } // namespace Internal