1 #ifndef __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
2 #define __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/internal/event/animation/progress-value.h>
29 class KeyFrameChannelBase
32 enum KeyFrameChannelId
34 Translate, Rotate, Scale,
37 KeyFrameChannelBase(KeyFrameChannelId channel_id)
38 : mChannelId(channel_id)
42 virtual ~KeyFrameChannelBase()
46 KeyFrameChannelId GetId() const
51 virtual bool IsActive(float progress) = 0;
54 KeyFrameChannelId mChannelId;
59 class KeyFrameChannel : public KeyFrameChannelBase
62 typedef std::vector<ProgressValue<V> > ProgressValues;
64 KeyFrameChannel(KeyFrameChannelId channel_id, ProgressValues& values )
65 : KeyFrameChannelBase(channel_id),
71 virtual ~KeyFrameChannel()
75 bool IsActive (float progress);
77 V GetValue(float progress) const;
79 bool FindInterval(typename ProgressValues::iterator& start,
80 typename ProgressValues::iterator& end,
81 float progress) const;
83 ProgressValues& mValues;
87 bool KeyFrameChannel<V>::IsActive (float progress)
92 ProgressValue<V>& first = mValues.front();
94 if( progress >= first.GetProgress() )
103 * Use a linear search to find the interval containing progress
104 * TODO: Use binary search instead
107 bool KeyFrameChannel<V>::FindInterval(
108 typename ProgressValues::iterator& start,
109 typename ProgressValues::iterator& end,
110 float progress) const
113 typename std::vector<ProgressValue<V> >::iterator iter = mValues.begin();
114 typename std::vector<ProgressValue<V> >::iterator prevIter = iter;
116 while(iter != mValues.end() && iter->GetProgress() <= progress)
122 if(iter == mValues.end())
128 if(prevIter->GetProgress() <= progress
130 iter->GetProgress() > progress)
141 V KeyFrameChannel<V>::GetValue (float progress) const
143 ProgressValue<V>& firstPV = mValues.front();
145 typename std::vector<ProgressValue<V> >::iterator start;
146 typename std::vector<ProgressValue<V> >::iterator end;
148 V interpolatedV = firstPV.GetValue();
149 if(progress >= mValues.back().GetProgress() )
151 interpolatedV = mValues.back().GetValue(); // This should probably be last value...
153 else if(FindInterval(start, end, progress))
155 float frameProgress = (progress - start->GetProgress()) / (end->GetProgress() - start->GetProgress());
157 interpolatedV = Interpolate(*start, *end, frameProgress);
160 return interpolatedV;
163 typedef KeyFrameChannel<float> KeyFrameChannelNumber;
164 typedef KeyFrameChannel<Vector2> KeyFrameChannelVector2;
165 typedef KeyFrameChannel<Vector3> KeyFrameChannelVector3;
166 typedef KeyFrameChannel<Vector4> KeyFrameChannelVector4;
167 typedef KeyFrameChannel<Quaternion> KeyFrameChannelQuaternion;
168 typedef KeyFrameChannel<AngleAxis> KeyFrameChannelAngleAxis;
174 #endif // __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__