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