b41b8d5cad4b076a860d020f69007d49894ee2b7
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / animation-definition.cpp
1 /*
2  * Copyright (c) 2020 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
24 const float AnimationDefinition::DEFAULT_DURATION_SECONDS = 1.f;
25 const float AnimationDefinition::MIN_DURATION_SECONDS = 1e-2f;
26
27 Animation::EndAction AnimationDefinition::StopForModification(Animation& anim)
28 {
29   const auto endAction = anim.GetEndAction();
30   anim.SetEndAction(Animation::DISCARD);
31   anim.Stop();
32   return endAction;
33 }
34
35 AnimationDefinition::AnimationDefinition()
36 {}
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 void AnimationDefinition::Animate(Animation& animation, AnimatedProperty::GetActor getActor)
50 {
51   DALI_ASSERT_ALWAYS(animation);
52   for (auto& ap : mProperties)
53   {
54     ap.Animate(animation, getActor);
55   }
56 }
57
58 Animation AnimationDefinition::ReAnimate(AnimatedProperty::GetActor getActor)
59 {
60   // Create and configure new animation.
61   Animation a = Animation::New(mDuration);
62   a.SetLoopCount(mLoopCount);
63   a.SetDisconnectAction(mDisconnectAction);
64   a.SetEndAction(mEndAction);
65
66   a.SetSpeedFactor(mSpeedFactor);
67   a.SetPlayRange(mPlayRange);
68
69   Animate(a, getActor);
70   return a;
71 }
72
73 AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
74 {
75   AnimationDefinition tmp(std::move(other));
76   mName = std::move(tmp.mName);
77   mDuration = tmp.mDuration;
78   mLoopCount = tmp.mLoopCount;
79   mDisconnectAction = tmp.mDisconnectAction;
80   mEndAction = tmp.mEndAction;
81   mSpeedFactor = tmp.mSpeedFactor;
82   mPlayRange = tmp.mPlayRange;
83   mProperties.swap(tmp.mProperties);
84   return *this;
85 }
86
87 }
88 }