[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / animation-definition.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-scene3d/public-api/loader/animation-definition.h>
20
21 namespace Dali::Scene3D::Loader
22 {
23 const float AnimationDefinition::DEFAULT_DURATION_SECONDS = 1.f;
24 const float AnimationDefinition::MIN_DURATION_SECONDS     = 1e-2f;
25
26 Animation::EndAction AnimationDefinition::StopForModification(Animation& anim)
27 {
28   const auto endAction = anim.GetEndAction();
29   anim.SetEndAction(Animation::DISCARD);
30   anim.Stop();
31   return endAction;
32 }
33
34 AnimationDefinition::AnimationDefinition() = default;
35
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))
45 {
46 }
47
48 AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
49 {
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);
59   return *this;
60 }
61
62 void AnimationDefinition::Animate(Animation& animation, AnimatedProperty::GetActor getActor)
63 {
64   DALI_ASSERT_ALWAYS(animation);
65   for(auto& property : mProperties)
66   {
67     property.Animate(animation, getActor);
68   }
69 }
70
71 Animation AnimationDefinition::ReAnimate(AnimatedProperty::GetActor getActor)
72 {
73   // Create and configure new animation.
74   Animation animation = Animation::New(mDuration);
75   animation.SetLoopCount(mLoopCount);
76   animation.SetDisconnectAction(mDisconnectAction);
77   animation.SetEndAction(mEndAction);
78
79   animation.SetSpeedFactor(mSpeedFactor);
80   animation.SetPlayRange(mPlayRange);
81
82   Animate(animation, getActor);
83   return animation;
84 }
85
86 void AnimationDefinition::SetName(const std::string& name)
87 {
88   mName = name;
89 }
90
91 const std::string& AnimationDefinition::GetName() const
92 {
93   return mName;
94 }
95
96 void AnimationDefinition::SetDuration(float duration)
97 {
98   mDuration = duration;
99 }
100
101 float AnimationDefinition::GetDuration() const
102 {
103   return mDuration;
104 }
105
106 void AnimationDefinition::SetLoopCount(int32_t loopCount)
107 {
108   mLoopCount = loopCount;
109 }
110
111 int AnimationDefinition::GetLoopCount() const
112 {
113   return mLoopCount;
114 }
115
116 void AnimationDefinition::SetDisconnectAction(Animation::EndAction disconnectAction)
117 {
118   mDisconnectAction = disconnectAction;
119 }
120
121 Animation::EndAction AnimationDefinition::GetDisconnectAction() const
122 {
123   return mDisconnectAction;
124 }
125
126 void AnimationDefinition::SetEndAction(Animation::EndAction endAction)
127 {
128   mEndAction = endAction;
129 }
130
131 Animation::EndAction AnimationDefinition::GetEndAction() const
132 {
133   return mEndAction;
134 }
135
136 void AnimationDefinition::SetSpeedFactor(float speedFactor)
137 {
138   mSpeedFactor = speedFactor;
139 }
140
141 float AnimationDefinition::GetSpeedFactor() const
142 {
143   return mSpeedFactor;
144 }
145
146 void AnimationDefinition::SetPlayRange(const Vector2& playRange)
147 {
148   mPlayRange = playRange;
149 }
150
151 Vector2 AnimationDefinition::GetPlayRange() const
152 {
153   return mPlayRange;
154 }
155
156 void AnimationDefinition::ReserveSize(uint32_t size)
157 {
158   mProperties.reserve(size);
159 }
160
161 uint32_t AnimationDefinition::GetPropertyCount() const
162 {
163   return static_cast<uint32_t>(mProperties.size());
164 }
165
166 void AnimationDefinition::SetProperty(uint32_t index, AnimatedProperty&& property)
167 {
168   if(mProperties.size() <= index)
169   {
170     mProperties.resize(index + 1);
171   }
172   mProperties[index] = std::move(property);
173 }
174
175 AnimatedProperty& AnimationDefinition::GetPropertyAt(uint32_t index)
176 {
177   return mProperties[index];
178 }
179
180 const AnimatedProperty& AnimationDefinition::GetPropertyAt(uint32_t index) const
181 {
182   return mProperties[index];
183 }
184
185 } // namespace Dali::Scene3D::Loader