summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-04-21 19:51:22 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-21 19:51:22 +0300
commit2acc486899b7253dbbc1656ea444c596d8af16ad (patch)
tree67a4ed03353e710c8a1164c1173f025f8f915e5c /src/ui/util.c
parent2e7b41f2d20cee278514b84ccf131062a62b3fee (diff)
Mobile: Working on scroll bounce behavior
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 8e808bd2..877ec7c1 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -246,6 +246,7 @@ iBool isFinished_Anim(const iAnim *d) {
246void init_Anim(iAnim *d, float value) { 246void init_Anim(iAnim *d, float value) {
247 d->due = d->when = SDL_GetTicks(); 247 d->due = d->when = SDL_GetTicks();
248 d->from = d->to = value; 248 d->from = d->to = value;
249 d->bounce = 0.0f;
249 d->flags = 0; 250 d->flags = 0;
250} 251}
251 252
@@ -276,20 +277,29 @@ static float valueAt_Anim_(const iAnim *d, const uint32_t now) {
276 return d->from; 277 return d->from;
277 } 278 }
278 float t = pos_Anim_(d, now); 279 float t = pos_Anim_(d, now);
279 const iBool isSoft = (d->flags & softer_AnimFlag) != 0; 280 const iBool isSoft = (d->flags & softer_AnimFlag) != 0;
281 const iBool isVerySoft = (d->flags & muchSofter_AnimFlag) != 0;
280 if ((d->flags & easeBoth_AnimFlag) == easeBoth_AnimFlag) { 282 if ((d->flags & easeBoth_AnimFlag) == easeBoth_AnimFlag) {
281 t = easeBoth_(t); 283 t = easeBoth_(t);
282 if (isSoft) t = easeBoth_(t); 284 if (isSoft) t = easeBoth_(t);
285 if (isVerySoft) t = easeBoth_(easeBoth_(t));
283 } 286 }
284 else if (d->flags & easeIn_AnimFlag) { 287 else if (d->flags & easeIn_AnimFlag) {
285 t = easeIn_(t); 288 t = easeIn_(t);
286 if (isSoft) t = easeIn_(t); 289 if (isSoft) t = easeIn_(t);
290 if (isVerySoft) t = easeIn_(easeIn_(t));
287 } 291 }
288 else if (d->flags & easeOut_AnimFlag) { 292 else if (d->flags & easeOut_AnimFlag) {
289 t = easeOut_(t); 293 t = easeOut_(t);
290 if (isSoft) t = easeOut_(t); 294 if (isSoft) t = easeOut_(t);
295 if (isVerySoft) t = easeOut_(easeOut_(t));
291 } 296 }
292 return d->from * (1.0f - t) + d->to * t; 297 float value = d->from * (1.0f - t) + d->to * t;
298 if (d->flags & bounce_AnimFlag) {
299 t = (1.0f - easeOut_(easeOut_(t))) * easeOut_(t);
300 value += d->bounce * t;
301 }
302 return value;
293} 303}
294 304
295void setValue_Anim(iAnim *d, float to, uint32_t span) { 305void setValue_Anim(iAnim *d, float to, uint32_t span) {
@@ -304,6 +314,7 @@ void setValue_Anim(iAnim *d, float to, uint32_t span) {
304 d->when = now; 314 d->when = now;
305 d->due = now + span; 315 d->due = now + span;
306 } 316 }
317 d->bounce = 0;
307} 318}
308 319
309void setValueSpeed_Anim(iAnim *d, float to, float unitsPerSecond) { 320void setValueSpeed_Anim(iAnim *d, float to, float unitsPerSecond) {
@@ -316,6 +327,7 @@ void setValueSpeed_Anim(iAnim *d, float to, float unitsPerSecond) {
316 d->to = to; 327 d->to = to;
317 d->when = now; 328 d->when = now;
318 d->due = d->when + span; 329 d->due = d->when + span;
330 d->bounce = 0;
319 } 331 }
320} 332}
321 333
@@ -333,9 +345,10 @@ void setValueEased_Anim(iAnim *d, float to, uint32_t span) {
333 d->from = valueAt_Anim_(d, now); 345 d->from = valueAt_Anim_(d, now);
334 d->flags = easeOut_AnimFlag; 346 d->flags = easeOut_AnimFlag;
335 } 347 }
336 d->to = to; 348 d->to = to;
337 d->when = now; 349 d->when = now;
338 d->due = now + span; 350 d->due = now + span;
351 d->bounce = 0;
339} 352}
340 353
341void setFlags_Anim(iAnim *d, int flags, iBool set) { 354void setFlags_Anim(iAnim *d, int flags, iBool set) {