1 #ifndef __DALI_ALPHA_FUNCTIONS_H__
2 #define __DALI_ALPHA_FUNCTIONS_H__
5 * Copyright (c) 2014 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 <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/constants.h>
28 typedef float (*AlphaFunction)(float progress); ///< Definition of an alpha function
31 * @brief Namespace containing a set of alpha functions.
33 namespace AlphaFunctions
36 inline float Linear( float progress )
41 inline float Default( float progress )
43 return Linear( progress );
46 inline float Reverse( float progress ) ///< Reverse linear
48 return 1.0f - progress;
51 inline float Square( float progress ) ///< Square (x^2)
53 return progress * progress;
56 inline float EaseIn( float progress ) ///< Speeds up and comes to a sudden stop
58 return progress * progress * progress;
61 inline float EaseOut( float progress ) ///< Sudden start and slows to a gradual stop
65 return progress * progress * progress + 1.0f;
68 inline float EaseInOut( float progress ) ///< Speeds up and slows to a gradual stop
72 return EaseOut((progress - 0.5f)*2.0f) * 0.5f + 0.5f;
76 return EaseIn(progress * 2.0f) * 0.5f;
80 inline float EaseInSine( float progress ) ///< Speeds up and comes to a sudden stop
82 return -1.0f * cosf(progress * Math::PI_2) + 1.0f;
85 inline float EaseOutSine( float progress ) ///< Sudden start and slows to a gradual stop
87 return sinf(progress * Math::PI_2);
90 inline float EaseInOutSine( float progress ) ///< Speeds up and slows to a gradual stop
92 return -0.5f * (cosf(Math::PI * progress) - 1.0f);
95 inline float EaseInSine33( float progress ) ///< Speeds up and comes to a sudden stop
97 float tmp = cosf(Math::PI_2 * 33.0f / 90.0f);
98 return -1.0f * (cosf(progress * Math::PI_2 * 33.0f / 90.0f) - tmp) / (1.0f - tmp) + 1.0f;
101 inline float EaseOutSine33( float progress ) ///< Sudden start and slows to a gradual stop
103 float tmp = cosf(Math::PI_2 * 33.0f / 90.0f);
104 return (cosf((1.0f - progress) * Math::PI_2 * 33.0f / 90.0f) - tmp) / (1.0f - tmp);
107 inline float EaseInOutSine33( float progress ) ///< Speeds up and slows to a gradual stop
109 float tmp = sinf(Math::PI_2 * 33.0f / 90.0f);
110 return (sinf((progress * Math::PI - Math::PI_2) * 33.0f / 90.0f) + tmp) / (2.0f * tmp);
113 inline float EaseInOutSine50( float progress ) ///< Speeds up and slows to a gradual stop
115 float tmp = sinf(Math::PI_2 * 50.0f / 90.0f);
116 return (sinf((progress * Math::PI - Math::PI_2) * 50.0f / 90.0f) + tmp) / (2.0f * tmp);
119 inline float EaseInOutSine60( float progress ) ///< Speeds up and slows to a gradual stop
121 float tmp = sinf(Math::PI_2 * 60.0f / 90.0f);
122 return (sinf((progress * Math::PI - Math::PI_2) * 60.0f / 90.0f) + tmp) / (2.0f * tmp);
125 inline float EaseInOutSine70( float progress ) ///< Speeds up and slows to a gradual stop
127 float tmp = sinf(Math::PI_2 * 70.0f / 90.0f);
128 return (sinf((progress * Math::PI - Math::PI_2) * 70.0f / 90.0f) + tmp) / (2.0f * tmp);
131 inline float EaseInOutSine80( float progress ) ///< Speeds up and slows to a gradual stop
133 float tmp = sinf(Math::PI_2 * 80.0f / 90.0f);
134 return (sinf((progress * Math::PI - Math::PI_2) * 80.0f / 90.0f) + tmp) / (2.0f * tmp);
137 inline float EaseInOutSine90( float progress ) ///< Speeds up and slows to a gradual stop
139 return EaseInOutSine(progress);
142 inline float DoubleEaseInOutSine60( float progress ) ///< Speeds up and slows to a gradual stop, then speeds up again and slows to a gradual stop
146 return EaseInOutSine60(progress * 2.0f) / 2.0f;
150 return EaseInOutSine60((progress - 0.5f) * 2.0f) / 2.0f + 0.5f;
154 inline float EaseOutQuint50( float progress ) ///< Sudden start and slows to a gradual stop
156 return 1.0f - powf(1.0f - progress, 1.7f);
159 inline float EaseOutQuint80( float progress ) ///< Sudden start and slows to a gradual stop
161 return 1.0f - powf(1.0f - progress, 2.3f);
164 inline float Bounce( float progress ) ///< Sudden start, loses momentum and returns to start position
166 return sinf(progress * Math::PI);
169 inline float BounceBack( float progress ) ///< Sudden start, loses momentum and returns to exceed start position and gradual stop at start position
171 if( progress > 0.0f )
173 return (sinf(progress * 2.0f * Math::PI) * sinf(progress * Math::PI)) / (progress * Math::PI);
181 inline float EaseInBack( float progress ) ///< Slow start, exceed start position and quickly reach destination
183 const float sqrt2 = 1.70158f;
185 return progress * progress * ( ( sqrt2 + 1.0f ) * progress - sqrt2 );
188 inline float EaseOutBack( float progress ) ///< Sudden start, exceed end position and return to a gradual stop
190 const float sqrt2 = 1.70158f;
193 return 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 );
196 inline float EaseInOutBack( float progress ) ///< Slow start, exceed start position, fast middle, exceed end position and return to a gradual stop
200 return EaseOutBack((progress - 0.5f)*2.0f) * 0.5f + 0.5f;
204 return EaseInBack(progress * 2.0f) * 0.5f;
208 inline float Sin( float progress ) ///< Single revolution
210 return 0.5f - cosf(progress * 2.0f * Math::PI) * 0.5f;
213 inline float Sin2x( float progress ) ///< Two revolutions
215 return 0.5f - cosf(progress * 4.0f * Math::PI) * 0.5f;
218 } // namespace AlphaFunctions
222 #endif // __DALI_ALPHA_FUNCTIONS_H__