2 * Copyright (c) 2018 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 void KeyFrames::CreateKeyFramesSpec(Property::Type type)
34 // Now we have a type, can create specific implementation
37 case Property::BOOLEAN:
39 mKeyFrames = std::make_unique<Internal::KeyFrameBoolean>();
42 case Property::INTEGER:
44 mKeyFrames = std::make_unique<Internal::KeyFrameInteger>();
49 mKeyFrames = std::make_unique<Internal::KeyFrameNumber>();
52 case Property::VECTOR2:
54 mKeyFrames = std::make_unique<Internal::KeyFrameVector2>();
57 case Property::VECTOR3:
59 mKeyFrames = std::make_unique<Internal::KeyFrameVector3>();
62 case Property::VECTOR4:
64 mKeyFrames = std::make_unique<Internal::KeyFrameVector4>();
67 case Property::ROTATION:
69 mKeyFrames = std::make_unique<Internal::KeyFrameQuaternion>();
74 DALI_ABORT( "Property type is not animatable" );
80 Property::Type KeyFrames::GetType() const
85 void KeyFrames::Add(float time, const Property::Value& value, AlphaFunction alpha)
87 if(mType == Property::NONE)
89 CreateKeyFramesSpec(value.GetType());
92 // Once we have created a type, can only add values of the same type
93 DALI_ASSERT_ALWAYS( mType == value.GetType() && "Can only add values of the same type to a KeyFrame" );
95 auto keyframes = mKeyFrames.get();
97 DALI_ASSERT_DEBUG(keyframes);
101 case Property::BOOLEAN:
103 Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(keyframes);
104 kf->AddKeyFrame(time, value.Get<bool>(), alpha);
107 case Property::INTEGER:
109 Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(keyframes);
110 kf->AddKeyFrame(time, value.Get<int>(), alpha);
113 case Property::FLOAT:
115 Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(keyframes);
116 kf->AddKeyFrame(time, value.Get<float>(), alpha);
119 case Property::VECTOR2:
121 Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(keyframes);
122 kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
125 case Property::VECTOR3:
127 Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(keyframes);
128 kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
131 case Property::VECTOR4:
133 Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(keyframes);
134 kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
137 case Property::ROTATION:
139 Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(keyframes);
140 kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
144 DALI_ASSERT_DEBUG(!"Type not supported");
149 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
151 return mKeyFrames.get();
154 Property::Value KeyFrames::GetLastKeyFrameValue() const
156 Property::Value value;
158 std::size_t noOfKeyFrames = mKeyFrames->GetNumberOfKeyFrames();
161 mKeyFrames->GetKeyFrameAsValue( noOfKeyFrames - 1, value );