[dali_1.2.40] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.cpp
index c27f31b..2191e2a 100644 (file)
@@ -112,17 +112,18 @@ 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),
+  mNotificationCount( 0 ),
   mLoopCount(1),
   mCurrentLoop(0),
-  mPlayRange( Vector2(0.0f,1.0f)),
   mEndAction( endAction ),
   mDisconnectAction( disconnectAction ),
   mDefaultAlpha( defaultAlpha ),
@@ -267,33 +268,20 @@ void Animation::Play()
 
   if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
   {
-    unsigned int connectorTargetValuesIndex( 0 );
-    unsigned int numberOfConnectorTargetValues = mConnectorTargetValues.size();
-
-    /*
-     * Loop through all Animator connectors, if connector index matches the current index stored in mConnectorTargetValues container then
-     * should apply target values for this index to the object.
-     */
-    for ( unsigned int connectorIndex = 0; connectorIndex < mConnectors.Count(); connectorIndex ++)
-    {
-      // Use index to check if the current connector is next in the mConnectorTargetValues container, meaning targetValues have been pushed in AnimateXXFunction
-      if ( connectorTargetValuesIndex < numberOfConnectorTargetValues )
-      {
-        ConnectorTargetValues& connectorPair = mConnectorTargetValues[ connectorTargetValuesIndex ];
-
-        if ( connectorPair.connectorIndex == connectorIndex )
-        {
-          // Current connector index matches next in the stored connectors with target values so apply target value.
-          connectorTargetValuesIndex++; // Found a match for connector so increment index to next one
+    // 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 );
 
-          AnimatorConnectorBase* connector = mConnectors[ connectorIndex ];
+    // 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(), connectorPair.targetValue );
-          }
-        }
+      Object* object = connector->GetObject();
+      if( object )
+      {
+        object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue );
       }
     }
   }
@@ -513,6 +501,7 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn
   ConnectorTargetValues connectorPair;
   connectorPair.targetValue = destinationValue;
   connectorPair.connectorIndex = mConnectors.Count();
+  connectorPair.timePeriod = period;
   mConnectorTargetValues.push_back( connectorPair );
 
   switch ( destinationType )
@@ -782,12 +771,6 @@ 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 )
-  {
-    mFinishedCallback( mFinishedCallbackObject );
-  }
 }
 
 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
@@ -808,12 +791,6 @@ bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface*
   return connected;
 }
 
-void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
-{
-  mFinishedCallback = callback;
-  mFinishedCallbackObject = object;
-}
-
 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
 {
   DALI_ASSERT_DEBUG( NULL != connector );
@@ -989,6 +966,10 @@ Vector2 Animation::GetPlayRange() const
   return mPlayRange;
 }
 
+bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
+{
+  return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
+}
 
 } // namespace Internal