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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/internal/event/animation/progress-value.h>
30 class KeyFrameChannelBase
33 enum KeyFrameChannelId
35 Translate, Rotate, Scale,
38 KeyFrameChannelBase(KeyFrameChannelId channel_id)
39 : mChannelId(channel_id)
43 virtual ~KeyFrameChannelBase()
47 KeyFrameChannelId GetId() const
52 virtual bool IsActive(float progress) = 0;
55 KeyFrameChannelId mChannelId;
60 class KeyFrameChannel : public KeyFrameChannelBase
63 typedef std::vector<ProgressValue<V> > ProgressValues;
65 KeyFrameChannel(KeyFrameChannelId channel_id, ProgressValues& values )
66 : KeyFrameChannelBase(channel_id),
72 virtual ~KeyFrameChannel()
76 bool IsActive (float progress);
78 V GetValue(float progress) const;
80 bool FindInterval(typename ProgressValues::iterator& start,
81 typename ProgressValues::iterator& end,
82 float progress) const;
84 ProgressValues& mValues;
88 bool KeyFrameChannel<V>::IsActive (float progress)
93 ProgressValue<V>& first = mValues.front();
95 if( progress >= first.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;
149 V interpolatedV = firstPV.GetValue();
150 if(progress >= mValues.back().GetProgress() )
152 interpolatedV = mValues.back().GetValue(); // This should probably be last value...
154 else if(FindInterval(start, end, progress))
156 float frameProgress = (progress - start->GetProgress()) / (end->GetProgress() - start->GetProgress());
158 interpolatedV = Interpolate(*start, *end, frameProgress);
161 return interpolatedV;
164 typedef KeyFrameChannel<float> KeyFrameChannelNumber;
165 typedef KeyFrameChannel<Vector2> KeyFrameChannelVector2;
166 typedef KeyFrameChannel<Vector3> KeyFrameChannelVector3;
167 typedef KeyFrameChannel<Vector4> KeyFrameChannelVector4;
168 typedef KeyFrameChannel<Quaternion> KeyFrameChannelQuaternion;
169 typedef KeyFrameChannel<AngleAxis> KeyFrameChannelAngleAxis;
175 #endif // __DALI_INTERNAL_KEY_FRAME_CHANNEL_H__