[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-core.git] / dali / public-api / animation / alpha-function.h
1 #ifndef __DALI_ALPHA_FUNCTION_H__
2 #define __DALI_ALPHA_FUNCTION_H__
3
4 /*
5  * Copyright (c) 2018 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/constants.h>
24 #include <dali/public-api/math/compile-time-math.h>
25 #include <dali/public-api/math/math-utils.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector4.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_core_animation
33  * @{
34  */
35
36 typedef float (*AlphaFunctionPrototype)(float progress); ///< Prototype of an alpha function @SINCE_1_0.0
37
38   /**
39    * @brief Alpha functions are used in animations to specify the rate of change of the animation parameter over time.
40    *
41    * Understanding an animation as a parametric function over time, the alpha function is applied to the parameter of
42    * the animation before computing the final animation value.
43    * @SINCE_1_0.0
44    */
45 class DALI_CORE_API AlphaFunction
46 {
47 public:
48
49   /**
50    * @brief Enumeration for built-in alpha functions.
51    * @SINCE_1_0.0
52    */
53   enum BuiltinFunction
54   {
55     DEFAULT,            ///< Linear @SINCE_1_0.0
56     LINEAR,             ///< No transformation @SINCE_1_0.0
57     REVERSE,            ///< Reverse linear @SINCE_1_0.0
58
59     EASE_IN_SQUARE,     ///< Speeds up and comes to a sudden stop (Square) @SINCE_1_0.0
60     EASE_OUT_SQUARE,    ///< Sudden start and slows to a gradual stop (Square) @SINCE_1_0.0
61
62     EASE_IN,            ///< Speeds up and comes to a sudden stop (Cubic) @SINCE_1_0.0
63     EASE_OUT,           ///< Sudden start and slows to a gradual stop (Cubic) @SINCE_1_0.0
64     EASE_IN_OUT,        ///< Speeds up and slows to a gradual stop (Cubic) @SINCE_1_0.0
65
66     EASE_IN_SINE,       ///< Speeds up and comes to a sudden stop (sinusoidal) @SINCE_1_0.0
67     EASE_OUT_SINE,      ///< Sudden start and slows to a gradual stop (sinusoidal) @SINCE_1_0.0
68     EASE_IN_OUT_SINE,   ///< Speeds up and slows to a gradual stop (sinusoidal) @SINCE_1_0.0
69
70     BOUNCE,             ///< Sudden start, loses momentum and returns to start position @SINCE_1_0.0
71     SIN,                ///< Single revolution @SINCE_1_0.0
72     EASE_OUT_BACK,      ///< Sudden start, exceed end position and return to a gradual stop @SINCE_1_0.0
73
74     COUNT
75   };
76
77   /**
78    * @brief Enumeration for all possible functioning modes for the alpha function.
79    * @SINCE_1_0.0
80    */
81   enum Mode
82   {
83     BUILTIN_FUNCTION,  ///< The user has specified a built-in function @SINCE_1_0.0
84     CUSTOM_FUNCTION,   ///< The user has provided a custom function @SINCE_1_0.0
85     BEZIER             ///< The user has provided the control points of a bezier curve @SINCE_1_0.0
86   };
87
88   /**
89    * @brief Default constructor.
90    * Creates an alpha function object with the default built-in alpha function.
91    * @SINCE_1_0.0
92    * @return The alpha function
93    */
94   AlphaFunction();
95
96   /**
97    * @brief Constructor.
98    * Creates an alpha function object with the built-in alpha function passed as a parameter
99    * to the constructor.
100    * @SINCE_1_0.0
101    * @param[in] function One of the built-in alpha functions
102    * @return The alpha function
103    */
104   AlphaFunction( BuiltinFunction function);
105
106   /**
107    * @brief Constructor.
108    * Creates an alpha function object using a pointer to an alpha function passed as a parameter
109    * to the constructor.
110    * @SINCE_1_0.0
111    * @param[in] function A pointer to an alpha function
112    * @return The alpha function
113    */
114   AlphaFunction( AlphaFunctionPrototype function);
115
116   /**
117    * @brief Constructor.
118    *
119    * Creates a bezier alpha function. The bezier will have the first point at (0,0) and
120    * the end point at (1,1).
121    * @SINCE_1_0.0
122    * @param[in] controlPoint0 A Vector2 which will be used as the first control point of the curve
123    * @param[in] controlPoint1 A Vector2 which will be used as the second control point of the curve
124    * @return The alpha function
125    * @note The x components of the control points will be clamped to the range [0,1] to prevent
126    * non monotonic curves.
127    */
128   AlphaFunction( const Dali::Vector2& controlPoint0, const Dali::Vector2& controlPoint1 );
129
130   /**
131    * @brief Returns the control points of the alpha function.
132    * @SINCE_1_0.0
133    * @return Vector4 containing the two control points of the curve
134    * (xy for the first point and zw for the second)
135    */
136   Vector4 GetBezierControlPoints() const;
137
138   /**
139    * @brief Returns the pointer to the custom function.
140    * @SINCE_1_0.0
141    * @return A pointer to a custom alpha function, or @c 0 if not defined
142    */
143   AlphaFunctionPrototype GetCustomFunction() const;
144
145   /**
146    * @brief Returns the built-in function used by the alpha function.
147    * @SINCE_1_0.0
148    * @return One of the built-in alpha functions. In case no built-in function
149    * has been specified, it will return AlphaFunction::DEFAULT
150    */
151   BuiltinFunction GetBuiltinFunction() const;
152
153   /**
154    * @brief Returns the functioning mode of the alpha function
155    * @SINCE_1_0.0
156    * @return The functioning mode of the alpha function
157    */
158   Mode GetMode() const;
159
160 private:
161
162   Vector4                 mBezierControlPoints;   //< Control points for the bezier alpha function
163   AlphaFunctionPrototype  mCustom;                //< Pointer to an alpha function
164   BuiltinFunction         mBuiltin : Log<COUNT>::value+2; //< Enum indicating the built-in alpha function
165   Mode                    mMode    : 3;                   //< Enum indicating the functioning mode of the AlphaFunction
166 };
167
168 /**
169  * @}
170  */
171 } // namespace Dali
172
173 #endif // __DALI_ALPHA_FUNCTION_H__