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