Dali 3D User Interface Engine
key-frames-impl.h
Go to the documentation of this file.
1 #ifndef __DALI_INTERNAL_KEY_FRAMES_H__
2 #define __DALI_INTERNAL_KEY_FRAMES_H__
3 
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20 
21 // INTERNAL INCLUDES
28 
29 namespace Dali
30 {
31 namespace Internal
32 {
33 class KeyFrameSpec;
34 class KeyFrames;
36 
37 
42 class KeyFrames : public BaseObject
43 {
44 public:
45  static KeyFrames* New();
46 
50  KeyFrames();
51 
52 protected:
53  virtual ~KeyFrames();
54 
55 private:
59  KeyFrames(const KeyFrames& rhs);
60 
64  KeyFrames& operator=(const KeyFrames& rhs);
65 
71 
72 public:
79  Property::Type GetType() const;
80 
90  void Add(float time, Property::Value value, AlphaFunction alpha);
91 
97 
98 private:
99  Dali::Property::Type mType; // Type of the specialization
100  IntrusivePtr<KeyFrameSpec> mKeyFrames; // Pointer to the specialized key frame object
101 };
102 
103 
111 class KeyFrameSpec : public RefObject
112 {
113 public:
114 
116 
117  virtual unsigned int GetNumberOfKeyFrames() const = 0;
118 
119 protected:
120 
124  virtual ~KeyFrameSpec() {}
125 };
126 
127 
133 template<typename V>
135 {
136 private:
138  typedef std::vector<PV> PVContainer;
139 
140  PVContainer mPVs; // The ProgressValue pairs
141  KeyFrameChannel<V>* mKeyFrames; // The key frame interpolator
142 
143 public:
145  {
146  return new KeyFrameBaseSpec<V>();
147  }
148 
150  {
151  return new KeyFrameBaseSpec<V>(keyFrames);
152  }
153 
158  {
160  }
161 
162 protected:
168  : mPVs(keyFrames.mPVs)
169  {
171  }
172 
174  {
175  if( *this != keyFrames )
176  {
177  mPVs.clear();
178  mPVs = keyFrames.mPVs;
179  delete mKeyFrames;
181  }
182  return *this;
183  }
184 
189  {
190  delete mKeyFrames;
191  mPVs.clear();
192  }
193 
194 public:
202  void AddKeyFrame(float t, V v, AlphaFunction alpha)
203  {
204  mPVs.push_back(PV(t, v));
205  }
206 
211  virtual unsigned int GetNumberOfKeyFrames() const
212  {
213  return mPVs.size();
214  }
215 
222  virtual void GetKeyFrame(unsigned int index, float& time, V& value) const
223  {
224  DALI_ASSERT_ALWAYS( index < mPVs.size() && "KeyFrame index is out of bounds" );
225  time = mPVs[index].mProgress;
226  value = mPVs[index].mValue;
227  }
228 
235  bool IsActive(float progress) const
236  {
237  return mKeyFrames->IsActive(progress);
238  }
239 
245  V GetValue(float progress, Dali::Animation::Interpolation interpolation) const
246  {
247  return mKeyFrames->GetValue(progress, interpolation);
248  }
249 };
250 
258 
266 
267 
268 inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameBoolean*& keyFrameSpec)
269 {
270  keyFrameSpec = static_cast<Internal::KeyFrameBoolean*>(keyFrames.GetKeyFramesBase());
271 }
272 
273 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameBoolean*& keyFrameSpec)
274 {
275  keyFrameSpec = static_cast<const Internal::KeyFrameBoolean*>(keyFrames.GetKeyFramesBase());
276 }
277 
278 inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameNumber*& keyFrameSpec)
279 {
280  keyFrameSpec = static_cast<Internal::KeyFrameNumber*>(keyFrames.GetKeyFramesBase());
281 }
282 
283 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameNumber*& keyFrameSpec)
284 {
285  keyFrameSpec = static_cast<const Internal::KeyFrameNumber*>(keyFrames.GetKeyFramesBase());
286 }
287 
288 inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameInteger*& keyFrameSpec)
289 {
290  keyFrameSpec = static_cast<Internal::KeyFrameInteger*>(keyFrames.GetKeyFramesBase());
291 }
292 
293 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameInteger*& keyFrameSpec)
294 {
295  keyFrameSpec = static_cast<const Internal::KeyFrameInteger*>(keyFrames.GetKeyFramesBase());
296 }
297 
298 inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameVector2*& keyFrameSpec)
299 {
300  keyFrameSpec = static_cast<Internal::KeyFrameVector2*>(keyFrames.GetKeyFramesBase());
301 }
302 
303 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameVector2*& keyFrameSpec)
304 {
305  keyFrameSpec = static_cast<const Internal::KeyFrameVector2*>(keyFrames.GetKeyFramesBase());
306 }
307 
308 inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameVector3*& keyFrameSpec)
309 {
310  keyFrameSpec = static_cast<Internal::KeyFrameVector3*>(keyFrames.GetKeyFramesBase());
311 }
312 
313 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameVector3*& keyFrameSpec)
314 {
315  keyFrameSpec = static_cast<const Internal::KeyFrameVector3*>(keyFrames.GetKeyFramesBase());
316 }
317 
318 inline void GetSpecialization(Internal::KeyFrames& keyFrames, Internal::KeyFrameVector4*& keyFrameSpec)
319 {
320  keyFrameSpec = static_cast<Internal::KeyFrameVector4*>(keyFrames.GetKeyFramesBase());
321 }
322 
323 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameVector4*& keyFrameSpec)
324 {
325  keyFrameSpec = static_cast<const Internal::KeyFrameVector4*>(keyFrames.GetKeyFramesBase());
326 }
327 
329 {
330  keyFrameSpec = static_cast<Internal::KeyFrameQuaternion*>(keyFrames.GetKeyFramesBase());
331 }
332 
333 inline void GetSpecialization(const Internal::KeyFrames& keyFrames, const Internal::KeyFrameQuaternion*& keyFrameSpec)
334 {
335  keyFrameSpec = static_cast<const Internal::KeyFrameQuaternion*>(keyFrames.GetKeyFramesBase());
336 }
337 
338 } // Internal
339 
340 
341 // Get impl of handle
343 {
344  DALI_ASSERT_ALWAYS( keyFrames && "KeyFrames handle is empty" );
345  Dali::RefObject& object = keyFrames.GetBaseObject();
346  return static_cast<Internal::KeyFrames&>(object);
347 }
348 
350 {
351  DALI_ASSERT_ALWAYS( keyFrames && "KeyFrames handle is empty" );
352  const Dali::RefObject& object = keyFrames.GetBaseObject();
353  return static_cast<const Internal::KeyFrames&>(object);
354 }
355 
356 
357 } // Dali
358 
359 #endif //__DALI_INTERNAL_KEY_FRAMES_H__
Dali Docs Home
Read more about Dali