Merge "Updated patch coverage script." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / animated-property.h
1 #ifndef DALI_SCENE_LOADER_ANIMATED_PROPERTY_H
2 #define DALI_SCENE_LOADER_ANIMATED_PROPERTY_H
3 /*
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include "dali-scene-loader/public-api/api.h"
22
23 // EXTERNAL INCLUDES
24 #include "dali/public-api/actors/actor.h"
25 #include "dali/public-api/animation/animation.h"
26 #include "dali/public-api/object/property.h"
27 #include <memory>
28 #include <functional>
29
30 namespace Dali
31 {
32 namespace SceneLoader
33 {
34
35 /**
36  * @brief Intermediate representation for a property that's given to
37  *  a Animation to animate. Since there is no getting an
38  *  animated property back from the Animation (i.e. past AnimateBetween/By/To()),
39  *  changing properties (e.g. from the SDK) requires the whole Animation
40  *  object to be recreated with all of its properties (incl. modifications).
41  */
42 struct DALI_SCENE_LOADER_API AnimatedProperty
43 {
44 public: // METHODS
45   /**
46    * @brief Function to obtain an Actor based on its name. Its processing will
47    *  ignore empty handles returned by it.
48    */
49   using GetActor = std::function<Actor(const std::string&)>;
50
51   /**
52    * @return The Property object (of the given @a actor) whose value is being animated.
53    */
54   Property GetProperty(Actor& actor)
55   {
56     auto idx = actor.GetPropertyIndex(mPropertyName);
57     return Property(actor, idx);
58   }
59
60   /**
61    * @brief The type of the Property (of the given @a actor) that is being animated.
62    */
63   Property::Type GetPropertyType(Actor& actor)
64   {
65     auto idx = actor.GetPropertyIndex(mPropertyName);
66     return actor.GetPropertyType(idx);
67   }
68
69   /**
70    * @brief Registers the animation of this property against the given @a anim.
71    *  @a getActor will be used to obtain the Actor named by this property.
72    *  Failing to find the actor purely means that this property will not be
73    *  animated.
74    */
75   void Animate(Animation& anim, GetActor getActor);
76
77 public: // DATA
78   struct Value
79   {
80     Property::Value mValue;
81     bool mIsRelative;
82   };
83
84   std::string mNodeName;
85   std::string mPropertyName;
86
87   KeyFrames mKeyFrames;
88   std::unique_ptr<Value> mValue;
89
90   AlphaFunction mAlphaFunction = AlphaFunction::DEFAULT;
91   TimePeriod mTimePeriod = TimePeriod(0.f);
92 };
93
94 }
95 }
96
97 #endif //DALI_SCENE_LOADER_ANIMATED_PROPERTY_H