Merge "use modern construct '= default' for special functions." into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.h
index cc4ec12..6d715fe 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) 2017 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.
@@ -23,6 +23,7 @@
 #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/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/common/event-thread-services.h>
@@ -46,11 +47,11 @@ class AnimatorConnectorBase;
 class Object;
 class Path;
 
-typedef IntrusivePtr<Animation> AnimationPtr;
-typedef std::vector<AnimationPtr> AnimationContainer;
+using AnimationPtr       = IntrusivePtr<Animation>;
+using AnimationContainer = std::vector<AnimationPtr>;
 
-typedef AnimationContainer::iterator AnimationIter;
-typedef AnimationContainer::const_iterator AnimationConstIter;
+using AnimationIter      = AnimationContainer::iterator;
+using AnimationConstIter = AnimationContainer::const_iterator;
 
 /**
  * Animation is a proxy for a SceneGraph::Animation object.
@@ -60,16 +61,15 @@ typedef AnimationContainer::const_iterator AnimationConstIter;
 class Animation : public BaseObject
 {
 public:
-
-  enum Type
+  enum Type : uint8_t
   {
-    TO,      ///< Animating TO the given value
-    BY,      ///< Animating BY the given value
-    BETWEEN  ///< Animating BETWEEN key-frames
+    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;
+  using EndAction     = Dali::Animation::EndAction;
+  using Interpolation = Dali::Animation::Interpolation;
 
   /**
    * Create a new Animation object.
@@ -84,6 +84,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;
@@ -96,17 +106,17 @@ public:
   /**
    * @copydoc Dali::Animation::SetLoopCount()
    */
-  void SetLoopCount(int count);
+  void SetLoopCount(int32_t count);
 
   /**
    * @copydoc Dali::Animation::GetLoopCount()
    */
-  int GetLoopCount();
+  int32_t GetLoopCount();
 
   /**
    * @copydoc Dali::Animation::GetCurrentLoop()
    */
-  int GetCurrentLoop();
+  int32_t GetCurrentLoop();
 
   /**
    * @copydoc Dali::Animation::IsLooping()
@@ -160,6 +170,11 @@ public:
   void PlayFrom( float progress );
 
   /**
+   * @copydoc Dali::Animation::PlayAfter()
+   */
+  void PlayAfter( float delaySeconds );
+
+  /**
    * @copydoc Dali::Animation::Pause()
    */
   void Pause();
@@ -192,11 +207,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.
@@ -219,53 +244,42 @@ public:
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue);
+  void AnimateBy(Property& target, Property::Value relativeValue);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
+  void AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
+  void AnimateBy(Property& target, Property::Value relativeValue, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
+  void AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue);
+  void AnimateTo(Property& target, Property::Value destinationValue);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
+  void AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
+  void AnimateTo(Property& target, Property::Value destinationValue, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
    */
-  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(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
+  void AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
@@ -339,36 +353,46 @@ public:
    */
   void Hide(Actor& actor, float delaySeconds);
 
-  /*
+  /**
    * @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
 
   /**
@@ -431,7 +455,7 @@ protected:
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */
-  virtual ~Animation();
+  ~Animation() override;
 
 private:
 
@@ -451,18 +475,27 @@ private:
 
   struct ConnectorTargetValues
   {
-    ConnectorTargetValues()
-    : targetValue(),
-      timePeriod( 0.0f ),
-      connectorIndex( 0 ),
-      animatorType( TO )
+    ConnectorTargetValues() = default;
+
+    ConnectorTargetValues(Property::Value value, TimePeriod time, std::size_t index, Animation::Type type)
+    : targetValue(std::move(value)),
+      timePeriod(time),
+      connectorIndex(index),
+      animatorType(type)
     {
     }
 
     Property::Value targetValue;
-    TimePeriod timePeriod;
-    unsigned int connectorIndex;
-    Animation::Type animatorType;
+    TimePeriod      timePeriod{0.f};
+    std::size_t     connectorIndex{0};
+    Animation::Type animatorType{TO};
+  };
+
+  enum class Notify : uint8_t
+  {
+    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:
@@ -475,32 +508,45 @@ private:
    */
   static bool CompareConnectorEndTimes( const ConnectorTargetValues& lhs, const ConnectorTargetValues& rhs );
 
-private:
-
-  const SceneGraph::Animation* mAnimation;
-
-  EventThreadServices& mEventThreadServices;
-  AnimationPlaylist& mPlaylist;
-
-  Dali::Animation::AnimationSignalType mFinishedSignal;
+  /**
+   * 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 );
 
-  typedef OwnerContainer< AnimatorConnectorBase* > AnimatorConnectorContainer;
-  AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
+  /**
+   * Sends message to SceneGraph with final progress value
+   */
+  void SendFinalProgressNotificationMessage();
 
-  typedef std::vector< ConnectorTargetValues > ConnectorTargetValuesContainer;
-  ConnectorTargetValuesContainer mConnectorTargetValues; //< Used to store animating property target value information
+private:
+  using AnimatorConnectorContainer     = OwnerContainer<AnimatorConnectorBase*>;
+  using ConnectorTargetValuesContainer = std::vector<ConnectorTargetValues>;
 
-  Vector2 mPlayRange;
+  const SceneGraph::Animation* mAnimation{ nullptr };
 
-  float mDurationSeconds;
-  float mSpeedFactor;
-  int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
-  int mLoopCount;
-  int mCurrentLoop;
-  EndAction mEndAction;
-  EndAction mDisconnectAction;
-  AlphaFunction mDefaultAlpha;
-  Dali::Animation::State mState;
+  EventThreadServices& mEventThreadServices;
+  AnimationPlaylist&   mPlaylist;
+
+  Dali::Animation::AnimationSignalType mFinishedSignal{};
+  Dali::Animation::AnimationSignalType mProgressReachedSignal{};
+
+  AnimatorConnectorContainer     mConnectors{};            ///< Owned by the Animation
+  ConnectorTargetValuesContainer mConnectorTargetValues{}; //< Used to store animating property target value information
+
+  AlphaFunction          mDefaultAlpha;
+  Vector2                mPlayRange{0.0f, 1.0f};
+  float                  mDurationSeconds;
+  float                  mSpeedFactor{1.0f};
+  int32_t                mNotificationCount{0}; ///< Keep track of how many Finished signals have been emitted.
+  int32_t                mLoopCount{1};
+  int32_t                mCurrentLoop{0};
+  float                  mProgressReachedMarker{0.0f};
+  float                  mDelaySeconds{0.0f};
+  EndAction              mEndAction;
+  EndAction              mDisconnectAction;
+  Dali::Animation::State mState{Dali::Animation::STOPPED};
+  bool                   mAutoReverseEnabled{false}; ///< Flag to identify that the looping mode is auto reverse.
 };
 
 } // namespace Internal
@@ -527,4 +573,4 @@ inline const Internal::Animation& GetImplementation(const Dali::Animation& anima
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_ANIMATION_H__
+#endif // DALI_INTERNAL_ANIMATION_H