Merge "Change dali-scene-loader to dali-scene3d" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / animation-definition.cpp
1 /*
2  * Copyright (c) 2022 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 #include "dali-scene3d/public-api/loader/animation-definition.h"
18
19 namespace Dali
20 {
21 namespace Scene3D
22 {
23 namespace Loader
24 {
25 const float AnimationDefinition::DEFAULT_DURATION_SECONDS = 1.f;
26 const float AnimationDefinition::MIN_DURATION_SECONDS     = 1e-2f;
27
28 Animation::EndAction AnimationDefinition::StopForModification(Animation& anim)
29 {
30   const auto endAction = anim.GetEndAction();
31   anim.SetEndAction(Animation::DISCARD);
32   anim.Stop();
33   return endAction;
34 }
35
36 AnimationDefinition::AnimationDefinition() = default;
37
38 AnimationDefinition::AnimationDefinition(AnimationDefinition&& other)
39 : mName(std::move(other.mName)),
40   mDuration(other.mDuration),
41   mLoopCount(other.mLoopCount),
42   mDisconnectAction(other.mDisconnectAction),
43   mEndAction(other.mEndAction),
44   mSpeedFactor(other.mSpeedFactor),
45   mPlayRange(other.mPlayRange),
46   mProperties(std::move(other.mProperties))
47 {
48 }
49
50 void AnimationDefinition::Animate(Animation& animation, AnimatedProperty::GetActor getActor)
51 {
52   DALI_ASSERT_ALWAYS(animation);
53   for(auto& ap : mProperties)
54   {
55     ap.Animate(animation, getActor);
56   }
57 }
58
59 Animation AnimationDefinition::ReAnimate(AnimatedProperty::GetActor getActor)
60 {
61   // Create and configure new animation.
62   Animation a = Animation::New(mDuration);
63   a.SetLoopCount(mLoopCount);
64   a.SetDisconnectAction(mDisconnectAction);
65   a.SetEndAction(mEndAction);
66
67   a.SetSpeedFactor(mSpeedFactor);
68   a.SetPlayRange(mPlayRange);
69
70   Animate(a, getActor);
71   return a;
72 }
73
74 AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
75 {
76   AnimationDefinition tmp(std::move(other));
77   mName             = std::move(tmp.mName);
78   mDuration         = tmp.mDuration;
79   mLoopCount        = tmp.mLoopCount;
80   mDisconnectAction = tmp.mDisconnectAction;
81   mEndAction        = tmp.mEndAction;
82   mSpeedFactor      = tmp.mSpeedFactor;
83   mPlayRange        = tmp.mPlayRange;
84   mProperties.swap(tmp.mProperties);
85   return *this;
86 }
87
88 } // namespace Loader
89 } // namespace Scene3D
90 } // namespace Dali