[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / animated-property.h
1 #ifndef DALI_SCENE3D_LOADER_ANIMATED_PROPERTY_H
2 #define DALI_SCENE3D_LOADER_ANIMATED_PROPERTY_H
3 /*
4  * Copyright (c) 2023 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 // EXTERNAL INCLUDES
21 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/animation/animation.h>
23 #include <dali/public-api/object/property.h>
24 #include <functional>
25 #include <memory>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene3d/public-api/api.h>
29 #include <dali-scene3d/public-api/loader/index.h>
30
31 namespace Dali::Scene3D::Loader
32 {
33 /**
34  * @brief Intermediate representation for a property that's given to a Animation to animate.
35  *
36  * Since there is no getting an animated property back from the Animation (i.e. past AnimateBetween/By/To()),
37  * changing properties (e.g. from the SDK) requires the whole Animation object to be recreated with all of
38  * its properties (incl. modifications).
39  * @SINCE_2_0.7
40  */
41 struct DALI_SCENE3D_API AnimatedProperty
42 {
43 public: // METHODS
44   /**
45    * @brief Function to obtain an Actor based on its property. Its processing will ignore empty handles returned by it.
46    * @SINCE_2_0.7
47    */
48   using GetActor = std::function<Actor(const AnimatedProperty&)>;
49
50   /**
51    * @brief Get the property object of the given actor.
52    * @SINCE_2_0.7
53    * @return The Property object (of the given @a actor) whose value is being animated.
54    */
55   Property GetProperty(Actor& actor) const
56   {
57     auto idx = actor.GetPropertyIndex(mPropertyName);
58     return Property(actor, idx);
59   }
60
61   /**
62    * @brief The type of the Property (of the given @a actor) that is being animated.
63    * @SINCE_2_0.7
64    */
65   Property::Type GetPropertyType(Actor& actor) const
66   {
67     auto idx = actor.GetPropertyIndex(mPropertyName);
68     return actor.GetPropertyType(idx);
69   }
70
71   /**
72    * @brief Registers the animation of this property against the given @a anim.
73    *
74    * @a getActor will be used to obtain the Actor named by this property.
75    * Failing to find the actor purely means that this property will not be
76    * animated.
77    * @SINCE_2_0.7
78    */
79   void Animate(Animation& anim, GetActor getActor) const;
80
81 public: // DATA
82   struct Value
83   {
84     Property::Value mValue;
85     bool            mIsRelative;
86   };
87
88   Index       mNodeIndex = INVALID_INDEX;
89   std::string mNodeName;
90   std::string mPropertyName;
91
92   KeyFrames              mKeyFrames;
93   std::unique_ptr<Value> mValue;
94
95   AlphaFunction mAlphaFunction = AlphaFunction::DEFAULT;
96   TimePeriod    mTimePeriod    = TimePeriod(0.f);
97 };
98
99 } // namespace Dali::Scene3D::Loader
100
101 #endif //DALI_SCENE3D_LOADER_ANIMATED_PROPERTY_H