Changed Animation API enums to uppercase.
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / key-frame-channel.h
index 8c7b570..378f6a4 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
-#define __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
+#ifndef DALI_INTERNAL_KEY_FRAME_CHANNEL_H
+#define DALI_INTERNAL_KEY_FRAME_CHANNEL_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.
@@ -19,8 +19,9 @@
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/internal/event/animation/progress-value.h>
+#include <dali/public-api/animation/animation.h>
+#include <dali/public-api/common/vector-wrapper.h>
 
 namespace Dali
 {
@@ -75,7 +76,7 @@ public:
 
   bool IsActive (float progress);
 
-  V GetValue(float progress) const;
+  V GetValue(float progress, Dali::Animation::Interpolation interpolation) const;
 
   bool FindInterval(typename ProgressValues::iterator& start,
                     typename ProgressValues::iterator& end,
@@ -102,7 +103,6 @@ bool KeyFrameChannel<V>::IsActive (float progress)
 
 /**
  * Use a linear search to find the interval containing progress
- * TODO: Use binary search instead
  */
 template <class V>
 bool KeyFrameChannel<V>::FindInterval(
@@ -139,7 +139,7 @@ bool KeyFrameChannel<V>::FindInterval(
 }
 
 template <class V>
-V KeyFrameChannel<V>::GetValue (float progress) const
+V KeyFrameChannel<V>::GetValue (float progress, Dali::Animation::Interpolation interpolation) const
 {
   ProgressValue<V>&  firstPV =  mValues.front();
 
@@ -155,7 +155,37 @@ V KeyFrameChannel<V>::GetValue (float progress) const
   {
     float frameProgress = (progress - start->GetProgress()) / (end->GetProgress() - start->GetProgress());
 
-    interpolatedV = Interpolate(*start, *end, frameProgress);
+    if( interpolation == Dali::Animation::LINEAR )
+    {
+      Interpolate(interpolatedV, start->GetValue(), end->GetValue(), frameProgress);
+    }
+    else
+    {
+      //Calculate prev and next values
+      V prev;
+      if( start != mValues.begin() )
+      {
+        prev = (start-1)->GetValue();
+      }
+      else
+      {
+        //Project next value through start point
+        prev = start->GetValue() + (start->GetValue()-(start+1)->GetValue());
+      }
+
+      V next;
+      if( end != mValues.end()-1)
+      {
+        next = (end+1)->GetValue();
+      }
+      else
+      {
+        //Project prev value through end point
+        next = end->GetValue() + (end->GetValue()-(end-1)->GetValue());
+      }
+
+      CubicInterpolate(interpolatedV, prev, start->GetValue(), end->GetValue(), next, frameProgress);
+    }
   }
 
   return interpolatedV;
@@ -172,4 +202,4 @@ typedef KeyFrameChannel<AngleAxis>  KeyFrameChannelAngleAxis;
 } // Internal
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
+#endif // DALI_INTERNAL_KEY_FRAME_CHANNEL_H