Refactor SceneGraphProperty handling code in event side to make RegisterProperty...
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / scene-graph-animator.h
index b8da716..ae18f06 100644 (file)
  */
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/common/owner-container.h>
-#include <dali/internal/event/animation/key-frames-impl.h>
-#include <dali/internal/event/animation/path-impl.h>
-#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/common/property-base.h>
 #include <dali/public-api/animation/alpha-function.h>
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/animation/time-period.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/radian.h>
+#include <dali/devel-api/common/owner-container.h>
+#include <dali/internal/event/animation/key-frames-impl.h>
+#include <dali/internal/event/animation/path-impl.h>
+#include <dali/internal/update/nodes/node.h>
+#include <dali/internal/update/common/property-base.h>
 #include <dali/internal/update/animation/property-accessor.h>
 #include <dali/integration-api/debug.h>
 
@@ -94,7 +94,7 @@ public:
     mLoopCount(1),
     mAlphaFunction(AlphaFunction::DEFAULT),
     mDisconnectAction(Dali::Animation::BakeFinal),
-    mActive(false),
+    mAnimationPlaying(false),
     mEnabled(true),
     mConnectedToSceneGraph(false),
     mAutoReverseEnabled( false )
@@ -153,7 +153,7 @@ public:
     mSpeedFactor = factor;
   }
 
-  void SetLoopCount(int loopCount)
+  void SetLoopCount(int32_t loopCount)
   {
     mLoopCount = loopCount;
   }
@@ -329,7 +329,7 @@ public:
         float upperBound(1.0f);
         float currentT(0.5f);
         float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
-        while( fabs( progress - currentX ) > tolerance )
+        while( fabsf( progress - currentX ) > tolerance )
         {
           if( progress > currentX )
           {
@@ -376,16 +376,7 @@ public:
    */
   void SetActive( bool active )
   {
-    mActive = active;
-  }
-
-  /**
-   * Retrieve whether the animator has been set to active or not.
-   * @return The active state.
-   */
-  bool GetActive() const
-  {
-    return mActive;
+    mAnimationPlaying = active;
   }
 
   /**
@@ -442,12 +433,12 @@ protected:
   float mIntervalDelaySeconds;
   float mSpeedFactor;
 
-  int mLoopCount;
+  int32_t mLoopCount;
 
   AlphaFunction mAlphaFunction;
 
   Dali::Animation::EndAction mDisconnectAction;     ///< EndAction to apply when target object gets disconnected from the stage.
-  bool mActive:1;                                   ///< Animator is "active" while it's running.
+  bool mAnimationPlaying:1;                         ///< whether disconnect has been applied 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;
@@ -525,13 +516,12 @@ public:
   virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
   {
     // If we are active, then bake the value if required
-    if ( mActive && mDisconnectAction != Dali::Animation::Discard )
+    if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::Discard )
     {
       // Bake to target-value if BakeFinal, otherwise bake current value
       Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
     }
 
-    mActive = false;
     mEnabled = false;
   }
 
@@ -558,7 +548,8 @@ public:
 
     const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
 
-    const PropertyType result = (*mAnimatorFunction)( alpha, current );
+    // need to cast the return value in case property is integer
+    const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
     if ( bake )
     {
       mPropertyAccessor.Bake( bufferIndex, result );
@@ -684,13 +675,12 @@ public:
   virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
   {
     // If we are active, then bake the value if required
-    if ( mActive && mDisconnectAction != Dali::Animation::Discard )
+    if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::Discard )
     {
       // Bake to target-value if BakeFinal, otherwise bake current value
       Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
     }
 
-    mActive = false;
     mEnabled = false;
   }
 
@@ -717,8 +707,8 @@ public:
 
     const T& current = mPropertyAccessor.Get( bufferIndex );
 
-    const T result = (*mAnimatorFunction)( alpha, current );
-
+    // need to cast the return value in case property is integer
+    T result = static_cast<T>( (*mAnimatorFunction)( alpha, current ) );
 
     if ( bake )
     {
@@ -796,14 +786,9 @@ struct AnimatorFunctionBase
     return property;
   }
 
-  virtual float operator()(float progress, const int& property)
+  virtual float operator()(float progress, const int32_t& property)
   {
-    return property;
-  }
-
-  virtual float operator()(float progress, const unsigned int& property)
-  {
-    return property;
+    return static_cast<float>( property );
   }
 
   virtual float operator()(float progress, const float& property)
@@ -842,12 +827,13 @@ struct AnimateByInteger : public AnimatorFunctionBase
   }
 
   using AnimatorFunctionBase::operator();
-  float operator()(float alpha, const int& property)
+  float operator()(float alpha, const int32_t& property)
   {
-    return int(property + mRelative * alpha + 0.5f );
+    // integers need to be correctly rounded
+    return roundf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha );
   }
 
-  int mRelative;
+  int32_t mRelative;
 };
 
 struct AnimateToInteger : public AnimatorFunctionBase
@@ -858,12 +844,13 @@ struct AnimateToInteger : public AnimatorFunctionBase
   }
 
   using AnimatorFunctionBase::operator();
-  float operator()(float alpha, const int& property)
+  float operator()(float alpha, const int32_t& property)
   {
-    return int(property + ((mTarget - property) * alpha) + 0.5f);
+    // integers need to be correctly rounded
+    return roundf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) );
   }
 
-  int mTarget;
+  int32_t mTarget;
 };
 
 struct AnimateByFloat : public AnimatorFunctionBase
@@ -1134,13 +1121,13 @@ struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
   }
 
   using AnimatorFunctionBase::operator();
-  float operator()(float progress, const int& property)
+  float operator()(float progress, const int32_t& property)
   {
     if(mKeyFrames->IsActive(progress))
     {
-      return mKeyFrames->GetValue(progress, mInterpolation);
+      return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
     }
-    return property;
+    return static_cast<float>( property );
   }
 
   KeyFrameIntegerPtr mKeyFrames;