2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/animation/key-frames-impl.h>
29 /// Helper to retrieve the value of the final key frame
30 template< typename PropertyType, typename KeyFrameType >
31 inline void GetLastKeyFrameValueInternal( const IntrusivePtr< KeyFrameSpec >& keyFrames, Property::Value& value )
33 KeyFrameType* kf = static_cast< KeyFrameType* >( keyFrames.Get() );
35 PropertyType actualValue;
36 kf->GetKeyFrame( kf->GetNumberOfKeyFrames() - 1, time, actualValue );
40 } // unnamed namespace
42 KeyFrames* KeyFrames::New()
44 return new KeyFrames();
47 KeyFrames::KeyFrames()
48 : mType(Property::NONE),
53 KeyFrames::~KeyFrames()
58 void KeyFrames::CreateKeyFramesSpec(Property::Type type)
61 // Now we have a type, can create specific implementation
64 case Property::BOOLEAN:
66 mKeyFrames = Internal::KeyFrameBoolean::New();
69 case Property::INTEGER:
71 mKeyFrames = Internal::KeyFrameInteger::New();
76 mKeyFrames = Internal::KeyFrameNumber::New();
79 case Property::VECTOR2:
81 mKeyFrames = Internal::KeyFrameVector2::New();
84 case Property::VECTOR3:
86 mKeyFrames = Internal::KeyFrameVector3::New();
89 case Property::VECTOR4:
91 mKeyFrames = Internal::KeyFrameVector4::New();
94 case Property::ROTATION:
96 mKeyFrames = Internal::KeyFrameQuaternion::New();
101 DALI_ABORT( "Type not animateable" );
107 Property::Type KeyFrames::GetType() const
112 void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
114 if(mType == Property::NONE)
116 CreateKeyFramesSpec(value.GetType());
119 // Once we have created a type, can only add values of the same type
120 DALI_ASSERT_ALWAYS( mType == value.GetType() && "Can only add values of the same type to a KeyFrame" );
122 DALI_ASSERT_DEBUG(mKeyFrames);
126 case Property::BOOLEAN:
128 Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(mKeyFrames.Get());
129 kf->AddKeyFrame(time, value.Get<bool>(), alpha);
132 case Property::INTEGER:
134 Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(mKeyFrames.Get());
135 kf->AddKeyFrame(time, value.Get<int>(), alpha);
138 case Property::FLOAT:
140 Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(mKeyFrames.Get());
141 kf->AddKeyFrame(time, value.Get<float>(), alpha);
144 case Property::VECTOR2:
146 Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(mKeyFrames.Get());
147 kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
150 case Property::VECTOR3:
152 Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(mKeyFrames.Get());
153 kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
156 case Property::VECTOR4:
158 Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(mKeyFrames.Get());
159 kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
162 case Property::ROTATION:
164 Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(mKeyFrames.Get());
165 kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
169 DALI_ASSERT_DEBUG(!"Type not supported");
174 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
176 return mKeyFrames.Get();
179 Property::Value KeyFrames::GetLastKeyFrameValue() const
181 Property::Value value;
185 case Property::BOOLEAN:
187 GetLastKeyFrameValueInternal< bool, KeyFrameBoolean >( mKeyFrames, value );
190 case Property::INTEGER:
192 GetLastKeyFrameValueInternal< int, KeyFrameInteger >( mKeyFrames, value );
195 case Property::FLOAT:
197 GetLastKeyFrameValueInternal< float, KeyFrameNumber >( mKeyFrames, value );
200 case Property::VECTOR2:
202 GetLastKeyFrameValueInternal< Vector2, KeyFrameVector2 >( mKeyFrames, value );
205 case Property::VECTOR3:
207 GetLastKeyFrameValueInternal< Vector3, KeyFrameVector3 >( mKeyFrames, value );
210 case Property::VECTOR4:
212 GetLastKeyFrameValueInternal< Vector4, KeyFrameVector4 >( mKeyFrames, value );
215 case Property::ROTATION:
217 GetLastKeyFrameValueInternal< Quaternion, KeyFrameQuaternion >( mKeyFrames, value );
221 DALI_ASSERT_DEBUG(!"Type not supported");