(Animation) Update object's event-side properties if we stop/pause/clear an animation
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.h
index 16c5555..454b066 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_ANIMATION_H__
-#define __DALI_INTERNAL_ANIMATION_H__
+#ifndef DALI_INTERNAL_ANIMATION_H
+#define DALI_INTERNAL_ANIMATION_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/object/base-object.h>
-#include <dali/internal/event/animation/animator-connector-base.h>
+#include <dali/devel-api/animation/animation-devel.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/event/common/event-thread-services.h>
 
 namespace Dali
 {
@@ -42,8 +43,9 @@ class UpdateManager;
 class Actor;
 class Animation;
 class AnimationPlaylist;
-class ProxyObject;
-class ShaderEffect;
+class AnimatorConnectorBase;
+class Object;
+class Path;
 
 typedef IntrusivePtr<Animation> AnimationPtr;
 typedef std::vector<AnimationPtr> AnimationContainer;
@@ -60,11 +62,16 @@ class Animation : public BaseObject
 {
 public:
 
+  enum Type
+  {
+    TO,      ///< Animating TO the given value
+    BY,      ///< Animating BY the given value
+    BETWEEN  ///< Animating BETWEEN key-frames
+  };
+
   typedef Dali::Animation::EndAction EndAction;
   typedef Dali::Animation::Interpolation Interpolation;
 
-  typedef void (*FinishedCallback)(Object* object);
-
   /**
    * Create a new Animation object.
    * @param[in] durationSeconds The duration of the animation.
@@ -78,6 +85,16 @@ public:
   void SetDuration(float seconds);
 
   /**
+   * @copydoc Dali::DevelAnimation::SetProgressNotification()
+   */
+  void SetProgressNotification( float progress );
+
+  /**
+   * @copydoc Dali::DevelAnimation::GetProgressNotification()
+   */
+  float GetProgressNotification();
+
+  /**
    * @copydoc Dali::Animation::GetDuration()
    */
   float GetDuration() const;
@@ -85,7 +102,22 @@ public:
   /**
    * @copydoc Dali::Animation::SetLooping()
    */
-  void SetLooping(bool looping);
+  void SetLooping(bool on);
+
+  /**
+   * @copydoc Dali::Animation::SetLoopCount()
+   */
+  void SetLoopCount(int32_t count);
+
+  /**
+   * @copydoc Dali::Animation::GetLoopCount()
+   */
+  int32_t GetLoopCount();
+
+  /**
+   * @copydoc Dali::Animation::GetCurrentLoop()
+   */
+  int32_t GetCurrentLoop();
 
   /**
    * @copydoc Dali::Animation::IsLooping()
@@ -139,11 +171,21 @@ public:
   void PlayFrom( float progress );
 
   /**
+   * @copydoc Dali::Animation::PlayAfter()
+   */
+  void PlayAfter( float delaySeconds );
+
+  /**
    * @copydoc Dali::Animation::Pause()
    */
   void Pause();
 
   /**
+   * @copydoc Dali::Animation::GetState()
+   */
+  Dali::Animation::State GetState() const;
+
+  /**
    * @copydoc Dali::Animation::Stop()
    */
   void Stop();
@@ -166,11 +208,21 @@ public:
   Dali::Animation::AnimationSignalType& FinishedSignal();
 
   /**
+   * @copydoc Dali::DevelAnimation::ProgressHasBeenReachedSignal()
+   */
+  Dali::Animation::AnimationSignalType& ProgressReachedSignal();
+
+  /**
    * Emit the Finished signal
    */
   void EmitSignalFinish();
 
   /**
+   * Emit the ProgressReached signal
+   */
+  void EmitSignalProgressReached();
+
+  /**
    * Connects a callback function with the object's signals.
    * @param[in] object The object providing the signal.
    * @param[in] tracker Used to disconnect the signal.
@@ -188,14 +240,7 @@ public:
    * @param[in] attributes The attributes with which to perfrom this action.
    * @return true if action was done
    */
-  static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
-
-  /**
-   * This callback is intended for internal use only, to avoid the overhead of using a signal.
-   * @param[in] callback The callback function to connect.
-   * @param[in] object The internal object requesting the callback, or NULL.
-   */
-  void SetFinishedCallback( FinishedCallback callback, Object* object );
+  static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
@@ -238,17 +283,6 @@ public:
   void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
 
   /**
-   * Animate a property to a destination value.
-   * @param [in] targetObject The target object to animate.
-   * @param [in] targetPropertyIndex The index of the target property.
-   * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
-   * @param [in] destinationValue The destination value.
-   * @param [in] alpha The alpha function to apply.
-   * @param [in] period The effect will occur during this time period.
-   */
-  void AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
-
-  /**
    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
    */
   void AnimateBetween(Property target, const KeyFrames& keyFrames);
@@ -311,111 +345,6 @@ public:
   void Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
 
   /**
-   * @copydoc Dali::Animation::MoveBy(Actor actor, float x, float y, float z)
-   */
-  void MoveBy(Actor& actor, float x, float y, float z);
-
-  /**
-   * @copydoc Dali::Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha)
-   */
-  void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::MoveTo(Actor actor, float x, float y, float z)
-   */
-  void MoveTo(Actor& actor, float x, float y, float z);
-
-  /**
-   * @copydoc Dali::Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha)
-   */
-  void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha,  float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis)
-   */
-  void RotateBy(Actor& actor, Radian angle, const Vector3& axis);
-
-  /**
-   * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)()
-   */
-  void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis)
-   */
-  void RotateTo(Actor& actor, Radian angle, const Vector3& axis);
-
-  /**
-   * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation)
-   */
-  void RotateTo(Actor& actor, const Quaternion& orientation);
-
-  /**
-   * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)
-   */
-  void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation, AlphaFunction alpha)
-   */
-  void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::RotateTo(Actor actor, Quaternion orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)()
-   */
-  void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::ScaleBy(Actor actor, float x, float y, float z)()
-   */
-  void ScaleBy(Actor& actor, float x, float y, float z);
-
-  /**
-   * @copydoc Dali::Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha)
-   */
-  void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::ScaleTo(Actor actor, float x, float y, float z)
-   */
-  void ScaleTo(Actor& actor, float x, float y, float z);
-
-  /**
-   * @copydoc Dali::Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha)
-   */
-  void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
    * @copydoc Dali::Animation::Show()
    */
   void Show(Actor& actor, float delaySeconds);
@@ -426,125 +355,45 @@ public:
   void Hide(Actor& actor, float delaySeconds);
 
   /**
-   * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity)
-   */
-  void OpacityBy(Actor& actor, float opacity);
-
-  /**
-   * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha)
-   */
-  void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)()
-   */
-  void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity)
-   */
-  void OpacityTo(Actor& actor, float opacity);
-
-  /**
-   * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha)
-   */
-  void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color)
-   */
-  void ColorBy(Actor& actor, const Vector4& color);
-
-  /**
-   * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha)
-   */
-  void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color)
-   */
-  void ColorTo(Actor& actor, const Vector4& color);
-
-  /**
-   * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha)
-   */
-  void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::Resize(Actor actor, float width, float height)
-   */
-  void Resize(Actor& actor, float width, float height);
-
-  /**
-   * @copydoc Dali::Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha)
-   */
-  void Resize(Actor& actor, float width, float height, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /**
-   * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size)
-   */
-  void Resize(Actor& actor, const Vector3& size);
-
-  /**
-   * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha)
-   */
-  void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha);
-
-  /**
-   * @copydoc Dali::Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-   */
-  void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds);
-
-  /*
    * @copydoc Dali::Animation::SetCurrentProgress()
    */
   void SetCurrentProgress(float progress);
 
-  /*
+  /**
    * @copydoc Dali::Animation::GetCurrentProgress()
    */
   float GetCurrentProgress();
 
-  /*
+  /**
    * @copydoc Dali::Animation::SetSpeedFactor()
    */
   void SetSpeedFactor( float factor );
 
-  /*
+  /**
    * @copydoc Dali::Animation::GetSpeedFactor()
    */
   float GetSpeedFactor() const;
 
-  /*
+  /**
    * @copydoc Dali::Animation::SetPlayRange()
    */
   void SetPlayRange( const Vector2& range );
 
-  /*
-   * @copydoc Dali::Animation::GetPlayRange
+  /**
+   * @copydoc Dali::Animation::GetPlayRange()
    */
   Vector2 GetPlayRange() const;
 
+  /**
+   * @copydoc Dali::Animation::SetLoopingMode()
+   */
+  void SetLoopingMode( Dali::Animation::LoopingMode loopingMode );
+
+  /**
+   * @copydoc Dali::Animation::GetLoopingMode()
+   */
+  Dali::Animation::LoopingMode GetLoopingMode() const;
+
 public: // For connecting animators to animations
 
   /**
@@ -563,26 +412,26 @@ public: // For connecting animators to animations
   }
 
   /**
-   * Retrieve the UpdateManager associated with this animation.
-   * @return The UpdateManager.
+   * Retrieve the event thread services object
+   * @return The interface for sending messages to the scene graph
    */
-  SceneGraph::UpdateManager& GetUpdateManager()
+  EventThreadServices& GetEventThreadServices()
   {
-    return mUpdateManager;
+    return mEventThreadServices;
   }
 
 protected:
 
   /**
    * Construct a new Animation.
-   * @param[in] updateManager The UpdateManager associated with this animation.
+   * @param[in] eventThreadServices The interface for sending messages to the scene graph
    * @param[in] playlist The list of currently playing animations.
    * @param[in] durationSeconds The duration of the animation in seconds.
    * @param[in] endAction The action to perform when the animation ends.
    * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected.
    * @param[in] defaultAlpha The default alpha function to apply to animators.
    */
-  Animation( SceneGraph::UpdateManager& updateManager,
+  Animation( EventThreadServices& eventThreadServices,
              AnimationPlaylist& playlist,
              float durationSeconds,
              EndAction endAction,
@@ -625,29 +474,81 @@ private:
 
 private:
 
-  SceneGraph::UpdateManager& mUpdateManager;
-  AnimationPlaylist& mPlaylist;
+  struct ConnectorTargetValues
+  {
+    ConnectorTargetValues()
+    : targetValue(),
+      timePeriod( 0.0f ),
+      connectorIndex( 0 ),
+      animatorType( TO )
+    {
+    }
+
+    Property::Value targetValue;
+    TimePeriod timePeriod;
+    std::size_t connectorIndex;
+    Animation::Type animatorType;
+  };
+
+  enum class Notify
+  {
+    USE_CURRENT_VALUE,   ///< Set the current value for the property
+    USE_TARGET_VALUE,    ///< Set the animator's target value for the property
+    FORCE_CURRENT_VALUE, ///< Set the current value for the property even if the end action is to discard
+  };
+
+private:
+
+  /**
+   * Compares the end times of the animators returning true if lhs end time is less than rhs end time.
+   * @param[in] lhs The first comparator
+   * @param[in] rhs The second comparator
+   * @return True if end time of lhs is less, false otherwise.
+   */
+  static bool CompareConnectorEndTimes( const ConnectorTargetValues& lhs, const ConnectorTargetValues& rhs );
+
+  /**
+   * Notifies all the objects whose properties are being animated.
+   * @param[in] notifyValueType Whether we should set the current or target value
+   */
+  void NotifyObjects( Notify notifyValueType );
+
+  /**
+   * Sends message to SceneGraph with final progress value
+   */
+  void SendFinalProgressNotificationMessage();
+
+private:
 
   const SceneGraph::Animation* mAnimation;
 
-  int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
+  EventThreadServices& mEventThreadServices;
+  AnimationPlaylist& mPlaylist;
 
   Dali::Animation::AnimationSignalType mFinishedSignal;
 
-  FinishedCallback mFinishedCallback;
-  Object* mFinishedCallbackObject;
+  Dali::Animation::AnimationSignalType mProgressReachedSignal;
 
+  typedef OwnerContainer< AnimatorConnectorBase* > AnimatorConnectorContainer;
   AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
 
-  // Cached for public getters
+  typedef std::vector< ConnectorTargetValues > ConnectorTargetValuesContainer;
+  ConnectorTargetValuesContainer mConnectorTargetValues; //< Used to store animating property target value information
+
+  Vector2 mPlayRange;
+
   float mDurationSeconds;
   float mSpeedFactor;
-  bool mIsLooping;
-  Vector2 mPlayRange;
+  int32_t mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
+  int32_t mLoopCount;
+  int32_t mCurrentLoop;
   EndAction mEndAction;
   EndAction mDisconnectAction;
   AlphaFunction mDefaultAlpha;
-
+  Dali::Animation::State mState;
+  float mProgressReachedMarker;
+  float mDelaySeconds;
+  bool mAutoReverseEnabled;  ///< Flag to identify that the looping mode is auto reverse.
 };
 
 } // namespace Internal
@@ -674,4 +575,4 @@ inline const Internal::Animation& GetImplementation(const Dali::Animation& anima
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_ANIMATION_H__
+#endif // DALI_INTERNAL_ANIMATION_H