2 * Copyright (c) 2023 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-scene3d/public-api/loader/animation-definition.h>
21 namespace Dali::Scene3D::Loader
23 const float AnimationDefinition::DEFAULT_DURATION_SECONDS = 1.f;
24 const float AnimationDefinition::MIN_DURATION_SECONDS = 1e-2f;
26 Animation::EndAction AnimationDefinition::StopForModification(Animation& anim)
28 const auto endAction = anim.GetEndAction();
29 anim.SetEndAction(Animation::DISCARD);
34 AnimationDefinition::AnimationDefinition() = default;
36 AnimationDefinition::AnimationDefinition(AnimationDefinition&& other)
37 : mName(std::move(other.mName)),
38 mDuration(other.mDuration),
39 mLoopCount(other.mLoopCount),
40 mDisconnectAction(other.mDisconnectAction),
41 mEndAction(other.mEndAction),
42 mSpeedFactor(other.mSpeedFactor),
43 mPlayRange(other.mPlayRange),
44 mProperties(std::move(other.mProperties))
48 AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
50 AnimationDefinition tmp(std::move(other));
51 mName = std::move(tmp.mName);
52 mDuration = tmp.mDuration;
53 mLoopCount = tmp.mLoopCount;
54 mDisconnectAction = tmp.mDisconnectAction;
55 mEndAction = tmp.mEndAction;
56 mSpeedFactor = tmp.mSpeedFactor;
57 mPlayRange = tmp.mPlayRange;
58 mProperties.swap(tmp.mProperties);
62 void AnimationDefinition::Animate(Animation& animation, AnimatedProperty::GetActor getActor)
64 DALI_ASSERT_ALWAYS(animation);
65 for(auto& property : mProperties)
67 property.Animate(animation, getActor);
71 Animation AnimationDefinition::ReAnimate(AnimatedProperty::GetActor getActor)
73 // Create and configure new animation.
74 Animation animation = Animation::New(mDuration);
75 animation.SetLoopCount(mLoopCount);
76 animation.SetDisconnectAction(mDisconnectAction);
77 animation.SetEndAction(mEndAction);
79 animation.SetSpeedFactor(mSpeedFactor);
80 animation.SetPlayRange(mPlayRange);
82 Animate(animation, getActor);
86 void AnimationDefinition::SetName(const std::string& name)
91 const std::string& AnimationDefinition::GetName() const
96 void AnimationDefinition::SetDuration(float duration)
101 float AnimationDefinition::GetDuration() const
106 void AnimationDefinition::SetLoopCount(int32_t loopCount)
108 mLoopCount = loopCount;
111 int AnimationDefinition::GetLoopCount() const
116 void AnimationDefinition::SetDisconnectAction(Animation::EndAction disconnectAction)
118 mDisconnectAction = disconnectAction;
121 Animation::EndAction AnimationDefinition::GetDisconnectAction() const
123 return mDisconnectAction;
126 void AnimationDefinition::SetEndAction(Animation::EndAction endAction)
128 mEndAction = endAction;
131 Animation::EndAction AnimationDefinition::GetEndAction() const
136 void AnimationDefinition::SetSpeedFactor(float speedFactor)
138 mSpeedFactor = speedFactor;
141 float AnimationDefinition::GetSpeedFactor() const
146 void AnimationDefinition::SetPlayRange(const Vector2& playRange)
148 mPlayRange = playRange;
151 Vector2 AnimationDefinition::GetPlayRange() const
156 void AnimationDefinition::ReserveSize(uint32_t size)
158 mProperties.reserve(size);
161 uint32_t AnimationDefinition::GetPropertyCount()
163 return mProperties.size();
166 void AnimationDefinition::SetProperty(uint32_t index, AnimatedProperty&& property)
168 if(mProperties.size() <= index)
170 mProperties.resize(index + 1);
172 mProperties[index] = std::move(property);
175 const AnimatedProperty& AnimationDefinition::GetPropertyAt(uint32_t index)
177 return mProperties[index];
180 } // namespace Dali::Scene3D::Loader