2 * Copyright (c) 2017 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>
26 KeyFrames* KeyFrames::New()
28 return new KeyFrames();
31 KeyFrames::KeyFrames()
32 : mType(Property::NONE),
37 KeyFrames::~KeyFrames()
42 void KeyFrames::CreateKeyFramesSpec(Property::Type type)
45 // Now we have a type, can create specific implementation
48 case Property::BOOLEAN:
50 mKeyFrames = Internal::KeyFrameBoolean::New();
53 case Property::INTEGER:
55 mKeyFrames = Internal::KeyFrameInteger::New();
60 mKeyFrames = Internal::KeyFrameNumber::New();
63 case Property::VECTOR2:
65 mKeyFrames = Internal::KeyFrameVector2::New();
68 case Property::VECTOR3:
70 mKeyFrames = Internal::KeyFrameVector3::New();
73 case Property::VECTOR4:
75 mKeyFrames = Internal::KeyFrameVector4::New();
78 case Property::ROTATION:
80 mKeyFrames = Internal::KeyFrameQuaternion::New();
85 DALI_ABORT( "Type not animateable" );
91 Property::Type KeyFrames::GetType() const
96 void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
98 if(mType == Property::NONE)
100 CreateKeyFramesSpec(value.GetType());
103 // Once we have created a type, can only add values of the same type
104 DALI_ASSERT_ALWAYS( mType == value.GetType() && "Can only add values of the same type to a KeyFrame" );
106 DALI_ASSERT_DEBUG(mKeyFrames);
110 case Property::BOOLEAN:
112 Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(mKeyFrames.Get());
113 kf->AddKeyFrame(time, value.Get<bool>(), alpha);
116 case Property::INTEGER:
118 Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(mKeyFrames.Get());
119 kf->AddKeyFrame(time, value.Get<int>(), alpha);
122 case Property::FLOAT:
124 Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(mKeyFrames.Get());
125 kf->AddKeyFrame(time, value.Get<float>(), alpha);
128 case Property::VECTOR2:
130 Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(mKeyFrames.Get());
131 kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
134 case Property::VECTOR3:
136 Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(mKeyFrames.Get());
137 kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
140 case Property::VECTOR4:
142 Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(mKeyFrames.Get());
143 kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
146 case Property::ROTATION:
148 Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(mKeyFrames.Get());
149 kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
153 DALI_ASSERT_DEBUG(!"Type not supported");
158 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
160 return mKeyFrames.Get();
163 Property::Value KeyFrames::GetLastKeyFrameValue() const
165 Property::Value value;
167 unsigned int noOfKeyFrames = mKeyFrames->GetNumberOfKeyFrames();
170 mKeyFrames->GetKeyFrameAsValue( noOfKeyFrames - 1, value );