License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / key-frames-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/animation/key-frames-impl.h>
20
21 namespace Dali
22 {
23 namespace Internal
24 {
25
26 KeyFrames* KeyFrames::New()
27 {
28   return new KeyFrames();
29 }
30
31 KeyFrames::KeyFrames()
32   : mType(Property::NONE),
33     mKeyFrames(NULL)
34 {
35 }
36
37 KeyFrames::~KeyFrames()
38 {
39 }
40
41
42 void KeyFrames::CreateKeyFramesSpec(Property::Type type)
43 {
44   mType = type;
45   // Now we have a type, can create specific implementation
46   switch(type)
47   {
48     case Property::BOOLEAN:
49       mKeyFrames = Internal::KeyFrameBoolean::New();
50       break;
51     case Property::FLOAT:
52       mKeyFrames = Internal::KeyFrameNumber::New();
53       break;
54     case Property::VECTOR2:
55       mKeyFrames = Internal::KeyFrameVector2::New();
56       break;
57     case Property::VECTOR3:
58       mKeyFrames = Internal::KeyFrameVector3::New();
59       break;
60     case Property::VECTOR4:
61       mKeyFrames = Internal::KeyFrameVector4::New();
62       break;
63     case Property::ROTATION:
64       mKeyFrames = Internal::KeyFrameQuaternion::New();
65       break;
66     default:
67       DALI_ASSERT_DEBUG(!"Type not supported");
68       break;
69   }
70 }
71
72 Property::Type KeyFrames::GetType() const
73 {
74   return mType;
75 }
76
77 void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
78 {
79   if(mType == Property::NONE)
80   {
81     CreateKeyFramesSpec(value.GetType());
82   }
83
84   // Once we have created a type, can only add values of the same type
85   DALI_ASSERT_ALWAYS( mType == value.GetType() && "Can only add values of the same type to a KeyFrame" );
86
87   DALI_ASSERT_DEBUG(mKeyFrames);
88
89   switch(mType)
90   {
91     case Property::BOOLEAN:
92     {
93       Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(mKeyFrames.Get());
94       kf->AddKeyFrame(time, value.Get<bool>(), alpha);
95       break;
96     }
97     case Property::FLOAT:
98     {
99       Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(mKeyFrames.Get());
100       kf->AddKeyFrame(time, value.Get<float>(), alpha);
101       break;
102     }
103     case Property::VECTOR2:
104     {
105       Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(mKeyFrames.Get());
106       kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
107       break;
108     }
109     case Property::VECTOR3:
110     {
111       Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(mKeyFrames.Get());
112       kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
113       break;
114     }
115     case Property::VECTOR4:
116     {
117       Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(mKeyFrames.Get());
118       kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
119       break;
120     }
121     case Property::ROTATION:
122     {
123       Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(mKeyFrames.Get());
124       kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
125       break;
126     }
127     default:
128       DALI_ASSERT_DEBUG(!"Type not supported");
129       break;
130   }
131 }
132
133 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
134 {
135   return mKeyFrames.Get();
136 }
137
138 } // Internal
139 } // Dali
140
141