Merge "Add BuildPickingRay to devel api" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / animation / linear-constrainer.h
1 #ifndef DALI_LINEAR_CONSTRAINER_H
2 #define DALI_LINEAR_CONSTRAINER_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 <cfloat> //For FLT_MAX
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/handle.h>
26 #include <dali/public-api/object/property-index-ranges.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_animation
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 class LinearConstrainer;
38 }
39
40 /**
41  * @brief LinearConstrainer applies constraints to objects, given a linear map.
42  *
43  * A linear map is defined by a set of value-progress pairs.
44  * Progress must be normalized between [0,1]. If no progress is defined, the values
45  * are considered to be equally spaced along the X axis.
46  *
47  * Basically, a linear constrainer allows constraining a property to another property
48  * with the changes mapped over a certain range. For example, if you want to change the
49  * opacity of an actor depending on its position along the X-axis, so that it's fully
50  * transparent on the edges and fully opaque in the center. To do this, an array with
51  * values, 0.0f, 1.0f, 0.0f, is created, which means that there are 3 control points.
52  * You can add as many control points as you want, but they will be linearly spaced.
53  * Then you can apply the linear constrainer by using the alpha of the actor as the
54  * target and the source as the actor's position.
55  * @SINCE_1_0.0
56  */
57 class DALI_CORE_API LinearConstrainer : public Handle
58 {
59 public:
60   /**
61    * @brief Enumeration for the instance of properties belonging to the LinearConstrainer class.
62    * @SINCE_1_0.0
63    */
64   struct Property
65   {
66     /**
67      * @brief Enumeration for the instance of properties belonging to the LinearConstrainer class.
68      * @SINCE_1_0.0
69      */
70     enum
71     {
72       VALUE = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "value" type Array of float @SINCE_1_0.0
73       PROGRESS,                                    ///< name "progress" type Array of float @SINCE_1_0.0
74     };
75   };
76
77   /**
78    * @brief Creates an initialized LinearConstrainer handle.
79    *
80    * @SINCE_1_0.0
81    * @return A handle to a newly allocated Dali resource
82    */
83   static LinearConstrainer New();
84
85   /**
86    * @brief Downcasts a handle to LinearConstrainer handle.
87    *
88    * If handle points to a LinearConstrainer object, the downcast produces valid handle.
89    * If not, the returned handle is left uninitialized.
90    * @SINCE_1_0.0
91    * @param[in] handle Handle to an object
92    * @return Handle to a LinearConstrainer object or an uninitialized handle
93    */
94   static LinearConstrainer DownCast(BaseHandle handle);
95
96   /**
97    * @brief Creates an uninitialized LinearConstrainer handle.
98    *
99    * This can be initialized with @ref LinearConstrainer::New
100    * Calling member functions with an uninitialized LinearConstrainer handle is not allowed.
101    * @SINCE_1_0.0
102    */
103   LinearConstrainer();
104
105   /**
106    * @brief Destructor.
107    *
108    * This is non-virtual since derived Handle types must not contain data or virtual methods.
109    * @SINCE_1_0.0
110    */
111   ~LinearConstrainer();
112
113   /**
114    * @brief This copy constructor is required for (smart) pointer semantics.
115    *
116    * @SINCE_1_0.0
117    * @param[in] handle A reference to the copied handle
118    */
119   LinearConstrainer(const LinearConstrainer& handle);
120
121   /**
122    * @brief This assignment operator is required for (smart) pointer semantics.
123    *
124    * @SINCE_1_0.0
125    * @param[in] rhs A reference to the copied handle
126    * @return A reference to this
127    */
128   LinearConstrainer& operator=(const LinearConstrainer& rhs);
129
130   /**
131    * @brief Move constructor.
132    *
133    * @SINCE_1_9.22
134    * @param[in] rhs A reference to the moved handle
135    */
136   LinearConstrainer(LinearConstrainer&& rhs) noexcept;
137
138   /**
139    * @brief Move assignment operator.
140    *
141    * @SINCE_1_9.22
142    * @param[in] rhs A reference to the moved handle
143    * @return A reference to this
144    */
145   LinearConstrainer& operator=(LinearConstrainer&& rhs) noexcept;
146
147   /**
148    * @brief Applies the linear constraint to the target property.
149    *
150    * @SINCE_1_0.0
151    * @param[in] target Property to be constrained
152    * @param[in] source Property used as a parameter for the linear map
153    * @param[in] range The range of values in the source property which will be mapped to [0,1]
154    * @param[in] wrap Wrapping domain. Source property will be wrapped in the domain [wrap.x,wrap.y] before mapping to [0,1]. See cfloat.h for FLT_MAX
155    */
156   void Apply(Dali::Property target, Dali::Property source, const Vector2& range, const Vector2& wrap = Vector2(-FLT_MAX, FLT_MAX));
157
158   /**
159    * @brief Removes the linear constraint in the target object.
160    *
161    * @SINCE_1_0.0
162    * @param[in] target A handle to an object constrained by the LinearConstrainer
163    */
164   void Remove(Dali::Handle& target);
165
166 public: // Not intended for application developers
167   /// @cond internal
168   /**
169    * @brief This constructor is used by LinearConstrainer::New() methods.
170    *
171    * @SINCE_1_0.0
172    * @param[in] internal A pointer to an internal LinearConstrainer resource
173    */
174   explicit DALI_INTERNAL LinearConstrainer(Internal::LinearConstrainer* internal);
175   /// @endcond
176 };
177
178 /**
179  * @}
180  */
181 } // namespace Dali
182
183 #endif // DALI_LINEAR_CONSTRAINER_H