2 * Copyright (c) 2021 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>
25 KeyFrames* KeyFrames::New()
27 return new KeyFrames();
30 void KeyFrames::CreateKeyFramesSpec(Property::Type type)
33 // Now we have a type, can create specific implementation
36 case Property::BOOLEAN:
38 mKeyFrames = std::make_unique<Internal::KeyFrameBoolean>();
41 case Property::INTEGER:
43 mKeyFrames = std::make_unique<Internal::KeyFrameInteger>();
48 mKeyFrames = std::make_unique<Internal::KeyFrameNumber>();
51 case Property::VECTOR2:
53 mKeyFrames = std::make_unique<Internal::KeyFrameVector2>();
56 case Property::VECTOR3:
58 mKeyFrames = std::make_unique<Internal::KeyFrameVector3>();
61 case Property::VECTOR4:
63 mKeyFrames = std::make_unique<Internal::KeyFrameVector4>();
66 case Property::ROTATION:
68 mKeyFrames = std::make_unique<Internal::KeyFrameQuaternion>();
73 DALI_ABORT("Property type is not animatable");
79 Property::Type KeyFrames::GetType() const
84 void KeyFrames::Add(float time, const Property::Value& value, AlphaFunction alpha)
86 if(mType == Property::NONE)
88 CreateKeyFramesSpec(value.GetType());
91 // Once we have created a type, can only add values of the same type
92 DALI_ASSERT_ALWAYS(mType == value.GetType() && "Can only add values of the same type to a KeyFrame");
94 auto keyframes = mKeyFrames.get();
96 DALI_ASSERT_DEBUG(keyframes);
100 case Property::BOOLEAN:
102 Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(keyframes);
103 kf->AddKeyFrame(time, value.Get<bool>(), alpha);
106 case Property::INTEGER:
108 Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(keyframes);
109 kf->AddKeyFrame(time, value.Get<int>(), alpha);
112 case Property::FLOAT:
114 Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(keyframes);
115 kf->AddKeyFrame(time, value.Get<float>(), alpha);
118 case Property::VECTOR2:
120 Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(keyframes);
121 kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
124 case Property::VECTOR3:
126 Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(keyframes);
127 kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
130 case Property::VECTOR4:
132 Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(keyframes);
133 kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
136 case Property::ROTATION:
138 Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(keyframes);
139 kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
143 DALI_ASSERT_DEBUG(!"Type not supported");
148 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
150 return mKeyFrames.get();
153 Property::Value KeyFrames::GetLastKeyFrameValue() const
155 Property::Value value;
157 std::size_t noOfKeyFrames = mKeyFrames->GetNumberOfKeyFrames();
160 mKeyFrames->GetKeyFrameAsValue(noOfKeyFrames - 1, value);
166 } // namespace Internal