Use modern construct 'using' instead of typedef.
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / key-frame-channel.h
index 4713435..3116903 100644 (file)
@@ -1,25 +1,27 @@
-#ifndef __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
-#define __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
-
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+#ifndef DALI_INTERNAL_KEY_FRAME_CHANNEL_H
+#define DALI_INTERNAL_KEY_FRAME_CHANNEL_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // 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
 {
@@ -59,7 +61,7 @@ template <typename V>
 class KeyFrameChannel : public KeyFrameChannelBase
 {
 public:
-  typedef std::vector<ProgressValue<V> > ProgressValues;
+  using ProgressValues = std::vector<ProgressValue<V> >;
 
   KeyFrameChannel(KeyFrameChannelId channel_id, ProgressValues& values )
   : KeyFrameChannelBase(channel_id),
@@ -74,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,
@@ -101,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(
@@ -138,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();
 
@@ -154,21 +155,50 @@ 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;
 }
 
-typedef KeyFrameChannel<float>      KeyFrameChannelNumber;
-typedef KeyFrameChannel<Vector2>    KeyFrameChannelVector2;
-typedef KeyFrameChannel<Vector3>    KeyFrameChannelVector3;
-typedef KeyFrameChannel<Vector4>    KeyFrameChannelVector4;
-typedef KeyFrameChannel<Quaternion> KeyFrameChannelQuaternion;
-typedef KeyFrameChannel<AngleAxis>  KeyFrameChannelAngleAxis;
-
+using KeyFrameChannelNumber     = KeyFrameChannel<float>;
+using KeyFrameChannelVector2    = KeyFrameChannel<Vector2>;
+using KeyFrameChannelVector3    = KeyFrameChannel<Vector3>;
+using KeyFrameChannelVector4    = KeyFrameChannel<Vector4>;
+using KeyFrameChannelQuaternion = KeyFrameChannel<Quaternion>;
+using KeyFrameChannelAngleAxis  = KeyFrameChannel<AngleAxis>;
 
 } // Internal
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
+#endif // DALI_INTERNAL_KEY_FRAME_CHANNEL_H