Implement Animation PlayAfter() API
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.cpp
index c87941d..b7cc899 100644 (file)
@@ -128,7 +128,9 @@ Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylis
   mEndAction( endAction ),
   mDisconnectAction( disconnectAction ),
   mDefaultAlpha( defaultAlpha ),
-  mState(Dali::Animation::STOPPED)
+  mState(Dali::Animation::STOPPED),
+  mProgressReachedMarker( 0.0f ),
+  mDelaySeconds( 0.0f )
 {
 }
 
@@ -160,14 +162,10 @@ void Animation::CreateSceneObject()
 {
   DALI_ASSERT_DEBUG( mAnimation == NULL );
 
-  // Create a new animation, temporarily owned
-  SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, 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()
@@ -195,6 +193,17 @@ void Animation::SetDuration(float seconds)
   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.
@@ -269,6 +278,8 @@ void Animation::Play()
 
   NotifyObjects();
 
+  SendFinalProgressNotificationMessage();
+
   // mAnimation is being used in a separate thread; queue a Play message
   PlayAnimationMessage( mEventThreadServices, *mAnimation );
 }
@@ -284,11 +295,33 @@ void Animation::PlayFrom( float progress )
 
     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;
@@ -774,6 +807,11 @@ Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
   return mFinishedSignal;
 }
 
+Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal()
+{
+  return mProgressReachedSignal;
+}
+
 void Animation::EmitSignalFinish()
 {
   if ( !mFinishedSignal.Empty() )
@@ -783,6 +821,15 @@ void Animation::EmitSignalFinish()
   }
 }
 
+void Animation::EmitSignalProgressReached()
+{
+  if ( !mProgressReachedSignal.Empty() )
+  {
+    Dali::Animation handle( this );
+    mProgressReachedSignal.Emit( handle );
+  }
+}
+
 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   bool connected( true );
@@ -1004,6 +1051,16 @@ void Animation::NotifyObjects()
   }
 }
 
+
+void Animation::SendFinalProgressNotificationMessage()
+{
+  if ( mProgressReachedMarker > 0.0f )
+  {
+    float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker;
+    SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds );
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali