[dali_2.1.1] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / animation-definition.cpp
1 /*
2  * Copyright (c) 2021 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-scene-loader/public-api/animation-definition.h"
18
19 namespace Dali
20 {
21 namespace SceneLoader
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 void AnimationDefinition::Animate(Animation& animation, AnimatedProperty::GetActor getActor)
49 {
50   DALI_ASSERT_ALWAYS(animation);
51   for(auto& ap : mProperties)
52   {
53     ap.Animate(animation, getActor);
54   }
55 }
56
57 Animation AnimationDefinition::ReAnimate(AnimatedProperty::GetActor getActor)
58 {
59   // Create and configure new animation.
60   Animation a = Animation::New(mDuration);
61   a.SetLoopCount(mLoopCount);
62   a.SetDisconnectAction(mDisconnectAction);
63   a.SetEndAction(mEndAction);
64
65   a.SetSpeedFactor(mSpeedFactor);
66   a.SetPlayRange(mPlayRange);
67
68   Animate(a, getActor);
69   return a;
70 }
71
72 AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
73 {
74   AnimationDefinition tmp(std::move(other));
75   mName             = std::move(tmp.mName);
76   mDuration         = tmp.mDuration;
77   mLoopCount        = tmp.mLoopCount;
78   mDisconnectAction = tmp.mDisconnectAction;
79   mEndAction        = tmp.mEndAction;
80   mSpeedFactor      = tmp.mSpeedFactor;
81   mPlayRange        = tmp.mPlayRange;
82   mProperties.swap(tmp.mProperties);
83   return *this;
84 }
85
86 } // namespace SceneLoader
87 } // namespace Dali