Add KeyFrames APIs
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / key-frames-impl.h
index 1f21625..919fedf 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_KEY_FRAMES_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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 <memory>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/internal/event/animation/key-frame-channel.h>
+#include <dali/public-api/animation/alpha-function.h>
 #include <dali/public-api/animation/key-frames.h>
+#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/base-object.h>
-#include <dali/public-api/animation/alpha-function.h>
-#include <dali/internal/event/animation/key-frame-channel.h>
 
 namespace Dali
 {
@@ -45,7 +45,6 @@ public:
   static KeyFrames* New();
 
 private:
-
   /**
    * Create a specialization from the given type, and store it to the mSpec
    * member variable
@@ -83,6 +82,16 @@ public:
    */
   Dali::Property::Value GetLastKeyFrameValue() const;
 
+  /**
+   * @copydoc Dali::DevelKeyFrames::GetKeyFrameCount()
+   */
+  std::size_t GetKeyFrameCount() const;
+
+  /**
+   * @copydoc Dali::DevelKeyFrames::GetKeyFrame()
+   */
+  void GetKeyFrame(std::size_t index, float& time, Property::Value& value) const;
+
 private:
   Dali::Property::Type          mType{Property::NONE}; // Type of the specialization
   std::unique_ptr<KeyFrameSpec> mKeyFrames;            // Pointer to the specialized key frame object
@@ -102,9 +111,10 @@ public:
   /**
    * Get the key frame value as a Property::Value.
    * @param[in] index The index of the key frame to fetch
+   * @param[out] time The progress of the given key frame
    * @param[out] value The value of the given key frame
    */
-  virtual void GetKeyFrameAsValue( std::size_t index, Property::Value& value ) = 0;
+  virtual void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const = 0;
 };
 
 /**
@@ -154,9 +164,11 @@ public:
   /**
    * @copydoc KeyFrameSpec::GetKeyFrameAsValue()
    */
-  void GetKeyFrameAsValue( std::size_t index, Property::Value& value ) override
+  void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const override
   {
-    value = mChannel.mValues[index].mValue;
+    const auto& element = mChannel.mValues[index];
+    time                = element.mProgress;
+    value               = element.mValue;
   }
 
   /**
@@ -195,25 +207,23 @@ auto GetSpecialization(const Internal::KeyFrames& keyFrames)
   return static_cast<DeriveClass>(keyFrames.GetKeyFramesBase());
 }
 
-} // Internal
-
+} // namespace Internal
 
 // Get impl of handle
 inline Internal::KeyFrames& GetImplementation(Dali::KeyFrames& keyFrames)
 {
-  DALI_ASSERT_ALWAYS( keyFrames && "KeyFrames handle is empty" );
+  DALI_ASSERT_ALWAYS(keyFrames && "KeyFrames handle is empty");
   Dali::RefObject& object = keyFrames.GetBaseObject();
   return static_cast<Internal::KeyFrames&>(object);
 }
 
 inline const Internal::KeyFrames& GetImplementation(const Dali::KeyFrames& keyFrames)
 {
-  DALI_ASSERT_ALWAYS( keyFrames && "KeyFrames handle is empty" );
+  DALI_ASSERT_ALWAYS(keyFrames && "KeyFrames handle is empty");
   const Dali::RefObject& object = keyFrames.GetBaseObject();
   return static_cast<const Internal::KeyFrames&>(object);
 }
 
-
-} // Dali
+} // namespace Dali
 
 #endif // DALI_INTERNAL_KEY_FRAMES_H