Merge "Added animation and constraint support for UNSIGNED_INTEGER property type...
[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::INTEGER:
52       mKeyFrames = Internal::KeyFrameInteger::New();
53       break;
54     case Property::UNSIGNED_INTEGER:
55       mKeyFrames = Internal::KeyFrameUnsignedInteger::New();
56       break;
57     case Property::FLOAT:
58       mKeyFrames = Internal::KeyFrameNumber::New();
59       break;
60     case Property::VECTOR2:
61       mKeyFrames = Internal::KeyFrameVector2::New();
62       break;
63     case Property::VECTOR3:
64       mKeyFrames = Internal::KeyFrameVector3::New();
65       break;
66     case Property::VECTOR4:
67       mKeyFrames = Internal::KeyFrameVector4::New();
68       break;
69     case Property::ROTATION:
70       mKeyFrames = Internal::KeyFrameQuaternion::New();
71       break;
72     default:
73       DALI_ASSERT_DEBUG(!"Type not supported");
74       break;
75   }
76 }
77
78 Property::Type KeyFrames::GetType() const
79 {
80   return mType;
81 }
82
83 void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
84 {
85   if(mType == Property::NONE)
86   {
87     CreateKeyFramesSpec(value.GetType());
88   }
89
90   // Once we have created a type, can only add values of the same type
91   DALI_ASSERT_ALWAYS( mType == value.GetType() && "Can only add values of the same type to a KeyFrame" );
92
93   DALI_ASSERT_DEBUG(mKeyFrames);
94
95   switch(mType)
96   {
97     case Property::BOOLEAN:
98     {
99       Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(mKeyFrames.Get());
100       kf->AddKeyFrame(time, value.Get<bool>(), alpha);
101       break;
102     }
103     case Property::INTEGER:
104     {
105       Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(mKeyFrames.Get());
106       kf->AddKeyFrame(time, value.Get<int>(), alpha);
107       break;
108     }
109     case Property::UNSIGNED_INTEGER:
110     {
111       Internal::KeyFrameUnsignedInteger* kf = static_cast<Internal::KeyFrameUnsignedInteger*>(mKeyFrames.Get());
112       kf->AddKeyFrame(time, value.Get<unsigned int>(), alpha);
113       break;
114     }
115     case Property::FLOAT:
116     {
117       Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(mKeyFrames.Get());
118       kf->AddKeyFrame(time, value.Get<float>(), alpha);
119       break;
120     }
121     case Property::VECTOR2:
122     {
123       Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(mKeyFrames.Get());
124       kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
125       break;
126     }
127     case Property::VECTOR3:
128     {
129       Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(mKeyFrames.Get());
130       kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
131       break;
132     }
133     case Property::VECTOR4:
134     {
135       Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(mKeyFrames.Get());
136       kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
137       break;
138     }
139     case Property::ROTATION:
140     {
141       Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(mKeyFrames.Get());
142       kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
143       break;
144     }
145     default:
146       DALI_ASSERT_DEBUG(!"Type not supported");
147       break;
148   }
149 }
150
151 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
152 {
153   return mKeyFrames.Get();
154 }
155
156 } // Internal
157 } // Dali