[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / devel-api / animation / animation-data.h
1 #ifndef DALI_ANIMATION_DATA_H
2 #define DALI_ANIMATION_DATA_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/animation/alpha-function.h>
27 #include <dali/public-api/animation/animation.h>
28 #include <dali/public-api/common/dali-vector.h>
29 #include <dali/public-api/object/property-value.h>
30
31 namespace Dali
32 {
33 /**
34  * @brief This object stores description data that can be used to generate an Animation.
35  * This data can be produced from passing JSON.
36  *
37  * This then allows the same description data to be used to repeatedly create an animation multiple times.
38  */
39 class DALI_CORE_API AnimationData
40 {
41 public:
42   AnimationData();
43
44   ~AnimationData();
45
46   /**
47    * @brief AnimationDataElement Describes one part of an animation.
48    */
49   struct AnimationDataElement
50   {
51     std::string                    actor;
52     std::string                    property;
53     Property::Value                value;
54     AlphaFunction::BuiltinFunction alphaFunction;
55     float                          timePeriodDelay;
56     float                          timePeriodDuration;
57
58     AnimationDataElement()
59     : alphaFunction(AlphaFunction::DEFAULT),
60       timePeriodDelay(0.0f),
61       timePeriodDuration(1.0f)
62     {
63     }
64   };
65
66   /**
67    * @brief AnimationData holds the required data required to define an
68    * animation to be performed on an actor or actors.
69    */
70   using AnimationDataList = Dali::Vector<AnimationDataElement*>;
71
72   /**
73    * @brief Adds one AnimationDataElement to the list to describe one animation.
74    * @param[in] animationDataElement A pre-populated struct to add
75    * @note This class takes ownership of animationDataElement
76    */
77   void Add(AnimationDataElement* animationDataElement);
78
79   /**
80    * @brief Creates a Dali::Animation from this AnimationData object.
81    * The AnimationData object can describe multiple individual property animations.
82    * Each one will be added to a created animation.
83    *
84    * If there is no animation data defined, an invalid Dali::Animation handle is returned.
85    * @param[in] targetActor The actor to target the property animations to.
86    * @param[in] duration The duration of the animation to create.
87    * @return    A ready-to-go Dali::Animation, or an invalid handle if there was no data.
88    */
89   Dali::Animation CreateAnimation(Dali::Actor targetActor, float duration);
90
91   /**
92    * @brief Empties this AnimationData object (and frees all memory).
93    */
94   void Clear();
95
96 private:
97   AnimationDataList mAnimationDataList; ///< A vector of individual property animations from which to generate a Dali::Animation.
98 };
99
100 } // namespace Dali
101
102 #endif // DALI_ANIMATION_DATA_H