}
Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
-: mAnimation( NULL ),
- mEventThreadServices( eventThreadServices ),
+: mEventThreadServices( eventThreadServices ),
mPlaylist( playlist ),
- mFinishedSignal(),
- mConnectors(),
- mConnectorTargetValues(),
- mPlayRange( Vector2(0.0f,1.0f)),
+ mAnimation( NULL ),
+ mNotificationCount( 0 ),
+ mFinishedCallback( NULL ),
+ mFinishedCallbackObject( NULL ),
mDurationSeconds( durationSeconds ),
mSpeedFactor(1.0f),
- mNotificationCount( 0 ),
mLoopCount(1),
mCurrentLoop(0),
+ mPlayRange( Vector2(0.0f,1.0f)),
mEndAction( endAction ),
mDisconnectAction( disconnectAction ),
mDefaultAlpha( defaultAlpha ),
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 )
+ 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 ++)
{
- AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
-
- Object* object = connector->GetObject();
- if( object )
+ // Use index to check if the current connector is next in the mConnectorTargetValues container, meaning targetValues have been pushed in AnimateXXFunction
+ if ( connectorTargetValuesIndex < numberOfConnectorTargetValues )
{
- object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->propertyChangeType );
+ 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
+
+ AnimatorConnectorBase* connector = mConnectors[ connectorIndex ];
+
+ Object* object = connector->GetObject();
+ if( object )
+ {
+ object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), connectorPair.targetValue );
+ }
+ }
}
}
}
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.propertyChangeType = Object::PropertyChange::ADJUST_VALUE_BY;
- mConnectorTargetValues.push_back( connectorPair );
-
switch ( targetType )
{
case Property::BOOLEAN:
ConnectorTargetValues connectorPair;
connectorPair.targetValue = destinationValue;
connectorPair.connectorIndex = mConnectors.Count();
- connectorPair.timePeriod = period;
- connectorPair.propertyChangeType = Object::PropertyChange::SET;
mConnectorTargetValues.push_back( connectorPair );
switch ( destinationType )
ExtendDuration( period );
- // 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.propertyChangeType = Object::PropertyChange::SET;
- mConnectorTargetValues.push_back( connectorPair );
-
switch(keyFrames.GetType())
{
case Dali::Property::BOOLEAN:
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 )
return connected;
}
+void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
+{
+ mFinishedCallback = callback;
+ mFinishedCallbackObject = object;
+}
+
void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
{
DALI_ASSERT_DEBUG( NULL != connector );
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