1 #ifndef DALI_ALPHA_FUNCTION_H
2 #define DALI_ALPHA_FUNCTION_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <cstdint> // uint8_t
25 #include <dali/public-api/common/constants.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/math/compile-time-math.h>
28 #include <dali/public-api/math/math-utils.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/vector4.h>
35 * @addtogroup dali_core_animation
39 using AlphaFunctionPrototype = float (*)(float); ///< Prototype of an alpha function @SINCE_1_0.0
42 * @brief Alpha functions are used in animations to specify the rate of change of the animation parameter over time.
44 * Understanding an animation as a parametric function over time, the alpha function is applied to the parameter of
45 * the animation before computing the final animation value.
48 class DALI_CORE_API AlphaFunction
52 * @brief Enumeration for built-in alpha functions.
55 enum BuiltinFunction : uint8_t
57 DEFAULT, ///< Linear @SINCE_1_0.0
58 LINEAR, ///< No transformation @SINCE_1_0.0
59 REVERSE, ///< Reverse linear @SINCE_1_0.0
60 EASE_IN_SQUARE, ///< Speeds up and comes to a sudden stop (Square) @SINCE_1_0.0
61 EASE_OUT_SQUARE, ///< Sudden start and slows to a gradual stop (Square) @SINCE_1_0.0
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 EASE_IN_SINE, ///< Speeds up and comes to a sudden stop (sinusoidal) @SINCE_1_0.0
66 EASE_OUT_SINE, ///< Sudden start and slows to a gradual stop (sinusoidal) @SINCE_1_0.0
67 EASE_IN_OUT_SINE, ///< Speeds up and slows to a gradual stop (sinusoidal) @SINCE_1_0.0
68 BOUNCE, ///< Sudden start, loses momentum and returns to start position @SINCE_1_0.0
69 SIN, ///< Single revolution @SINCE_1_0.0
70 EASE_OUT_BACK, ///< Sudden start, exceed end position and return to a gradual stop @SINCE_1_0.0
75 * @brief Enumeration for all possible functioning modes for the alpha function.
80 BUILTIN_FUNCTION, ///< The user has specified a built-in function @SINCE_1_0.0
81 CUSTOM_FUNCTION, ///< The user has provided a custom function @SINCE_1_0.0
82 BEZIER ///< The user has provided the control points of a bezier curve @SINCE_1_0.0
86 * @brief Default constructor.
87 * Creates an alpha function object with the default built-in alpha function.
94 * Creates an alpha function object with the built-in alpha function passed as a parameter
97 * @param[in] function One of the built-in alpha functions
99 AlphaFunction(BuiltinFunction function);
102 * @brief Constructor.
103 * Creates an alpha function object using a pointer to an alpha function passed as a parameter
104 * to the constructor.
106 * @param[in] function A pointer to an alpha function
108 AlphaFunction(AlphaFunctionPrototype function);
111 * @brief Constructor.
113 * Creates a bezier alpha function. The bezier will have the first point at (0,0) and
114 * the end point at (1,1).
116 * @param[in] controlPoint0 A Vector2 which will be used as the first control point of the curve
117 * @param[in] controlPoint1 A Vector2 which will be used as the second control point of the curve
118 * @note The x components of the control points will be clamped to the range [0,1] to prevent
119 * non monotonic curves.
121 AlphaFunction(const Dali::Vector2& controlPoint0, const Dali::Vector2& controlPoint1);
124 * @brief Returns the control points of the alpha function.
126 * @return Vector4 containing the two control points of the curve
127 * (xy for the first point and zw for the second)
129 Vector4 GetBezierControlPoints() const;
132 * @brief Returns the pointer to the custom function.
134 * @return A pointer to a custom alpha function, or @c 0 if not defined
136 AlphaFunctionPrototype GetCustomFunction() const;
139 * @brief Returns the built-in function used by the alpha function.
141 * @return One of the built-in alpha functions. In case no built-in function
142 * has been specified, it will return AlphaFunction::DEFAULT
144 BuiltinFunction GetBuiltinFunction() const;
147 * @brief Returns the functioning mode of the alpha function
149 * @return The functioning mode of the alpha function
151 Mode GetMode() const;
154 Mode mMode; //< Enum indicating the functioning mode of the AlphaFunction
155 BuiltinFunction mBuiltin; //< Enum indicating the built-in alpha function
159 Vector4 mBezierControlPoints; //< Control points for the bezier alpha function
160 AlphaFunctionPrototype mCustom; //< Pointer to an alpha function
169 #endif // DALI_ALPHA_FUNCTION_H