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();
93 ProgressValue<V>& last = mValues.back();
95 if (progress >= first.GetProgress() && progress <= last.GetProgress() )
104 * Use a linear search to find the interval containing progress
105 * TODO: Use binary search instead
108 bool KeyFrameChannel<V>::FindInterval(
109 typename ProgressValues::iterator& start,
110 typename ProgressValues::iterator& end,
111 float progress) const
114 typename std::vector<ProgressValue<V> >::iterator iter = mValues.begin();
115 typename std::vector<ProgressValue<V> >::iterator prevIter = iter;
117 while(iter != mValues.end() && iter->GetProgress() <= progress)
123 if(iter == mValues.end())
129 if(prevIter->GetProgress() <= progress
131 iter->GetProgress() > progress)
142 V KeyFrameChannel<V>::GetValue (float progress) const
144 ProgressValue<V>& firstPV = mValues.front();
146 typename std::vector<ProgressValue<V> >::iterator start;
147 typename std::vector<ProgressValue<V> >::iterator end;
150 if(FindInterval(start, end, progress))
152 float frameProgress = (progress - start->GetProgress()) / (end->GetProgress() - start->GetProgress());
154 interpolatedV = Interpolate(*start, *end, frameProgress);
156 else if(progress <= firstPV.GetProgress())
158 interpolatedV = firstPV.GetValue(); // This should probably be initial value...
162 interpolatedV = mValues.back().GetValue(); // Sticks at end value
165 return interpolatedV;
168 typedef KeyFrameChannel<float> KeyFrameChannelNumber;
169 typedef KeyFrameChannel<Vector2> KeyFrameChannelVector2;
170 typedef KeyFrameChannel<Vector3> KeyFrameChannelVector3;
171 typedef KeyFrameChannel<Vector4> KeyFrameChannelVector4;
172 typedef KeyFrameChannel<Quaternion> KeyFrameChannelQuaternion;
173 typedef KeyFrameChannel<AngleAxis> KeyFrameChannelAngleAxis;
179 #endif // __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__