Fix LoopingMode::AUTO_REVERSE behavior when LoopCount is 1
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / scene-graph-animator.h
index d1cac15..aff2b2c 100644 (file)
@@ -32,7 +32,7 @@
 #include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/radian.h>
 #include <dali/internal/update/animation/property-accessor.h>
-
+#include <dali/integration-api/debug.h>
 
 namespace Dali
 {
@@ -70,11 +70,14 @@ public:
   AnimatorBase()
   : mDurationSeconds(1.0f),
     mIntervalDelaySeconds(0.0f),
+    mSpeedFactor(1.0f),
+    mLoopCount(1),
     mAlphaFunction(AlphaFunction::DEFAULT),
     mDisconnectAction(Dali::Animation::BakeFinal),
     mActive(false),
     mEnabled(true),
-    mConnectedToSceneGraph(false)
+    mConnectedToSceneGraph(false),
+    mAutoReverseEnabled( false )
   {
   }
 
@@ -111,6 +114,40 @@ public:
     return mDurationSeconds;
   }
 
+  void SetSpeedFactor( float factor )
+  {
+    mSpeedFactor = factor;
+  }
+
+  void SetLoopCount(int loopCount)
+  {
+    mLoopCount = loopCount;
+  }
+
+  float SetProgress( float progress )
+  {
+    float value = 0.0f;
+
+    if( mAutoReverseEnabled )
+    {
+      if( mSpeedFactor > 0.0f )
+      {
+        value = 1.0f - 2.0f * std::abs( progress - 0.5f );
+      }
+      // Reverse mode
+      else if( mSpeedFactor < 0.0f )
+      {
+        value = 2.0f * std::abs( progress - 0.5f );
+      }
+    }
+    else
+    {
+      value = progress;
+    }
+
+    return value;
+  }
+
   /**
    * Set the delay before the animator should take effect.
    * The default is zero i.e. no delay.
@@ -148,7 +185,7 @@ public:
     return mAlphaFunction;
   }
 
-  /*
+  /**
    * Applies the alpha function to the specified progress
    * @param[in] Current progress
    * @return The progress after the alpha function has been aplied
@@ -317,7 +354,7 @@ public:
     return mActive;
   }
 
-  /*
+  /**
    * Retrive wheter the animator's target object is valid and on the stage.
    * @return The enabled state.
    */
@@ -325,6 +362,16 @@ public:
   {
     return mEnabled;
   }
+
+  /**
+   * @brief Sets the looping mode.
+   * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
+   */
+  void SetLoopingMode( bool loopingMode )
+  {
+    mAutoReverseEnabled = loopingMode;
+  }
+
   /**
    * Returns wheter the target object of the animator is still valid
    * or has been destroyed.
@@ -358,6 +405,9 @@ protected:
 
   float mDurationSeconds;
   float mIntervalDelaySeconds;
+  float mSpeedFactor;
+
+  int mLoopCount;
 
   AlphaFunction mAlphaFunction;
 
@@ -365,6 +415,7 @@ protected:
   bool mActive:1;                                   ///< Animator is "active" while it's running.
   bool mEnabled:1;                                  ///< Animator is "enabled" while its target object is valid and on the stage.
   bool mConnectedToSceneGraph:1;                    ///< True if ConnectToSceneGraph() has been called in update-thread.
+  bool mAutoReverseEnabled:1;
 };
 
 /**
@@ -462,7 +513,13 @@ public:
    */
   virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
   {
-    float alpha = ApplyAlphaFunction(progress);
+    if( mLoopCount >= 0 )
+    {
+      // Update the progress value
+      progress = SetProgress( progress );
+    }
+
+    float alpha = ApplyAlphaFunction( progress );
 
     const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
 
@@ -615,7 +672,13 @@ public:
    */
   virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
   {
-    float alpha = ApplyAlphaFunction(progress);
+    if( mLoopCount >= 0 )
+    {
+      // Update the progress value
+      progress = SetProgress( progress );
+    }
+
+    float alpha = ApplyAlphaFunction( progress );
 
     const T& current = mPropertyAccessor.Get( bufferIndex );