From a85908c8f920a1e859e72cec80cc61a098de7dbe Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 11 Feb 2015 01:15:16 +0100 Subject: [PATCH] (Menu) Refactor easing functions --- menu/drivers/xmb.c | 50 ++-- menu/menu_animation.c | 588 ++++++++++++++++++++++++------------------ menu/menu_animation.h | 119 ++++----- 3 files changed, 417 insertions(+), 340 deletions(-) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index ed4e919521..2dc04341fb 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -493,10 +493,10 @@ static void xmb_selection_pointer_changed(void) iz = xmb->i_active_zoom; } - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, iz, &node->zoom, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, iy, &node->y, &inOutQuad, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, iy, &node->y, EASING_IN_OUT_QUAD, NULL); } } @@ -521,9 +521,9 @@ static void xmb_list_open_old(file_list_t *list, int dir, size_t current) if (dir == -1) ia = 0; - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->label_alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, xmb->icon_size*dir*-2, &node->x, &inOutQuad, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, xmb->icon_size*dir*-2, &node->x, EASING_IN_OUT_QUAD, NULL); } } @@ -567,9 +567,9 @@ static void xmb_list_open_new(file_list_t *list, int dir, size_t current) if (i == current) ia = xmb->i_active_alpha; - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->x, &inOutQuad, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->x, EASING_IN_OUT_QUAD, NULL); } xmb->old_depth = xmb->depth; @@ -699,9 +699,9 @@ static void xmb_list_switch_old(file_list_t *list, int dir, size_t current) if (!xmb) continue; - menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->label_alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, -xmb->hspacing*dir, &node->x, &inOutQuad, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, -xmb->hspacing*dir, &node->x, EASING_IN_OUT_QUAD, NULL); } } @@ -729,9 +729,9 @@ static void xmb_list_switch_new(file_list_t *list, int dir, size_t current) if (i == current) ia = 1.0; - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->x, &inOutQuad, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->x, EASING_IN_OUT_QUAD, NULL); } } @@ -795,13 +795,13 @@ static void xmb_list_open(void) iz = xmb->c_active_zoom; } - menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL); - menu_animation_push(driver.menu->animation, XMB_DELAY, iz, &node->zoom, &inOutQuad, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + menu_animation_push(driver.menu->animation, XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, NULL); } menu_animation_push(driver.menu->animation, XMB_DELAY, xmb->hspacing * -(float)driver.menu->cat_selection_ptr, - &xmb->categories_x, &inOutQuad, NULL); + &xmb->categories_x, EASING_IN_OUT_QUAD, NULL); dir = -1; if (driver.menu->cat_selection_ptr > xmb->cat_selection_ptr_old) @@ -842,7 +842,7 @@ static void xmb_list_switch(void) ia = xmb->c_passive_alpha; menu_animation_push(driver.menu->animation, XMB_DELAY, ia, - &node->alpha, &inOutQuad, NULL); + &node->alpha, EASING_IN_OUT_QUAD, NULL); } xmb_list_open_old(xmb->selection_buf_old, dir, xmb->selection_ptr_old); @@ -852,15 +852,15 @@ static void xmb_list_switch(void) { case 1: menu_animation_push(driver.menu->animation, XMB_DELAY, xmb->icon_size*-(xmb->depth*2-2), - &xmb->x, &inOutQuad, NULL); + &xmb->x, EASING_IN_OUT_QUAD, NULL); menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &xmb->arrow_alpha, - &inOutQuad, NULL); + EASING_IN_OUT_QUAD, NULL); break; case 2: menu_animation_push(driver.menu->animation, XMB_DELAY, - xmb->icon_size*-(xmb->depth*2-2), &xmb->x, &inOutQuad, NULL); + xmb->icon_size*-(xmb->depth*2-2), &xmb->x, EASING_IN_OUT_QUAD, NULL); menu_animation_push(driver.menu->animation, XMB_DELAY, 1, &xmb->arrow_alpha, - &inOutQuad, NULL); + EASING_IN_OUT_QUAD, NULL); break; } @@ -1677,7 +1677,7 @@ static void xmb_toggle(bool menu_on) } menu_animation_push(driver.menu->animation, XMB_DELAY, 1.0f, - &xmb->alpha, &inOutQuad, NULL); + &xmb->alpha, EASING_IN_OUT_QUAD, NULL); xmb->prevent_populate = !menu->need_refresh; diff --git a/menu/menu_animation.c b/menu/menu_animation.c index a9cf55ade3..3dfbce14b9 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -18,6 +18,234 @@ #include "../driver.h" #include +/* from https://github.com/kikito/tween.lua/blob/master/tween.lua */ + +static float easing_linear(float t, float b, float c, float d) +{ + return c * t / d + b; +} + +static float easing_in_out_quad(float t, float b, float c, float d) +{ + t = t / d * 2; + if (t < 1) + return c / 2 * pow(t, 2) + b; + return -c / 2 * ((t - 1) * (t - 3) - 1) + b; +} + +static float easing_in_quad(float t, float b, float c, float d) +{ + return c * pow(t / d, 2) + b; +} + +static float easing_out_quad(float t, float b, float c, float d) +{ + t = t / d; + return -c * t * (t - 2) + b; +} + +static float easing_out_in_quad(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_quad(t * 2, b, c / 2, d); + return easing_in_quad((t * 2) - d, b + c / 2, c / 2, d); +} + +static float easing_in_cubic(float t, float b, float c, float d) +{ + return c * pow(t / d, 3) + b; +} + +static float easing_out_cubic(float t, float b, float c, float d) +{ + return c * (pow(t / d - 1, 3) + 1) + b; +} + +float easing_in_out_cubic(float t, float b, float c, float d) +{ + t = t / d * 2; + if (t < 1) + return c / 2 * t * t * t + b; + t = t - 2; + return c / 2 * (t * t * t + 2) + b; +} + +static float easing_out_in_cubic(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_cubic(t * 2, b, c / 2, d); + return easing_in_cubic((t * 2) - d, b + c / 2, c / 2, d); +} + +static float easing_in_quart(float t, float b, float c, float d) +{ + return c * pow(t / d, 4) + b; +} + +static float easing_out_quart(float t, float b, float c, float d) +{ + return -c * (pow(t / d - 1, 4) - 1) + b; +} + +static float easing_in_out_quart(float t, float b, float c, float d) +{ + t = t / d * 2; + if (t < 1) + return c / 2 * pow(t, 4) + b; + return -c / 2 * (pow(t - 2, 4) - 2) + b; +} + +static float easing_out_in_quart(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_quart(t * 2, b, c / 2, d); + return easing_in_quart((t * 2) - d, b + c / 2, c / 2, d); +} + +static float easing_in_quint(float t, float b, float c, float d) +{ + return c * pow(t / d, 5) + b; +} + +static float easing_out_quint(float t, float b, float c, float d) +{ + return c * (pow(t / d - 1, 5) + 1) + b; +} + +static float easing_in_out_quint(float t, float b, float c, float d) +{ + t = t / d * 2; + if (t < 1) + return c / 2 * pow(t, 5) + b; + return c / 2 * (pow(t - 2, 5) + 2) + b; +} + +static float easing_out_in_quint(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_quint(t * 2, b, c / 2, d); + return easing_in_quint((t * 2) - d, b + c / 2, c / 2, d); +} + +static float easing_in_sine(float t, float b, float c, float d) +{ + return -c * cos(t / d * (M_PI / 2)) + c + b; +} + +static float easing_out_sine(float t, float b, float c, float d) +{ + return c * sin(t / d * (M_PI / 2)) + b; +} + +static float easing_in_out_sine(float t, float b, float c, float d) +{ + return -c / 2 * (cos(M_PI * t / d) - 1) + b; +} + +static float easing_out_in_sine(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_sine(t * 2, b, c / 2, d); + return easing_in_sine((t * 2) -d, b + c / 2, c / 2, d); +} + +static float easing_in_expo(float t, float b, float c, float d) +{ + if (t == 0) + return b; + return c * powf(2, 10 * (t / d - 1)) + b - c * 0.001; +} + +static float easing_out_expo(float t, float b, float c, float d) +{ + if (t == d) + return b + c; + return c * 1.001 * (-powf(2, -10 * t / d) + 1) + b; +} + +static float easing_in_out_expo(float t, float b, float c, float d) +{ + if (t == 0) + return b; + if (t == d) + return b + c; + t = t / d * 2; + if (t < 1) + return c / 2 * powf(2, 10 * (t - 1)) + b - c * 0.0005; + return c / 2 * 1.0005 * (-powf(2, -10 * (t - 1)) + 2) + b; +} + +static float easing_out_in_expo(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_expo(t * 2, b, c / 2, d); + return easing_in_expo((t * 2) - d, b + c / 2, c / 2, d); +} + +static float easing_in_circ(float t, float b, float c, float d) +{ + return(-c * (sqrt(1 - powf(t / d, 2)) - 1) + b); +} + +static float easing_out_circ(float t, float b, float c, float d) +{ + return(c * sqrt(1 - powf(t / d - 1, 2)) + b); +} + +static float easing_in_out_circ(float t, float b, float c, float d) +{ + t = t / d * 2; + if (t < 1) + return -c / 2 * (sqrt(1 - t * t) - 1) + b; + t = t - 2; + return c / 2 * (sqrt(1 - t * t) + 1) + b; +} + +static float easing_out_in_circ(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_circ(t * 2, b, c / 2, d); + return easing_in_circ((t * 2) - d, b + c / 2, c / 2, d); +} + +static float easing_out_bounce(float t, float b, float c, float d) +{ + t = t / d; + if (t < 1 / 2.75) + return c * (7.5625 * t * t) + b; + if (t < 2 / 2.75) + { + t = t - (1.5 / 2.75); + return c * (7.5625 * t * t + 0.75) + b; + } + else if (t < 2.5 / 2.75) + { + t = t - (2.25 / 2.75); + return c * (7.5625 * t * t + 0.9375) + b; + } + t = t - (2.625 / 2.75); + return c * (7.5625 * t * t + 0.984375) + b; +} + +static float easing_in_bounce(float t, float b, float c, float d) +{ + return c - easing_out_bounce(d - t, 0, c, d) + b; +} + +static float easing_in_out_bounce(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_in_bounce(t * 2, 0, c, d) * 0.5 + b; + return easing_out_bounce(t * 2 - d, 0, c, d) * 0.5 + c * .5 + b; +} + +static float easing_out_in_bounce(float t, float b, float c, float d) +{ + if (t < d / 2) + return easing_out_bounce(t * 2, b, c / 2, d); + return easing_in_bounce((t * 2) - d, b + c / 2, c / 2, d); +} + void menu_animation_free(animation_t *animation) { size_t i; @@ -36,7 +264,7 @@ void menu_animation_free(animation_t *animation) bool menu_animation_push(animation_t *animation, float duration, float target_value, float* subject, - easingFunc easing, tween_cb cb) + enum animation_easing_type easing_enum, tween_cb cb) { if (animation->size >= animation->capacity) { @@ -51,9 +279,122 @@ bool menu_animation_push(animation_t *animation, animation->list[animation->size].initial_value = *subject; animation->list[animation->size].target_value = target_value; animation->list[animation->size].subject = subject; - animation->list[animation->size].easing = easing; animation->list[animation->size].cb = cb; + switch (easing_enum) + { + case EASING_LINEAR: + animation->list[animation->size].easing = &easing_linear; + break; + /* Quad */ + case EASING_IN_QUAD: + animation->list[animation->size].easing = &easing_in_quad; + break; + case EASING_OUT_QUAD: + animation->list[animation->size].easing = &easing_out_quad; + break; + case EASING_IN_OUT_QUAD: + animation->list[animation->size].easing = &easing_in_out_quad; + break; + case EASING_OUT_IN_QUAD: + animation->list[animation->size].easing = &easing_out_in_quad; + break; + /* Cubic */ + case EASING_IN_CUBIC: + animation->list[animation->size].easing = &easing_in_cubic; + break; + case EASING_OUT_CUBIC: + animation->list[animation->size].easing = &easing_out_cubic; + break; + case EASING_IN_OUT_CUBIC: + animation->list[animation->size].easing = &easing_in_out_cubic; + break; + case EASING_OUT_IN_CUBIC: + animation->list[animation->size].easing = &easing_out_in_cubic; + break; + /* Quart */ + case EASING_IN_QUART: + animation->list[animation->size].easing = &easing_in_quart; + break; + case EASING_OUT_QUART: + animation->list[animation->size].easing = &easing_out_quart; + break; + case EASING_IN_OUT_QUART: + animation->list[animation->size].easing = &easing_in_out_quart; + break; + case EASING_OUT_IN_QUART: + animation->list[animation->size].easing = &easing_out_in_quart; + break; + /* Quint */ + case EASING_IN_QUINT: + animation->list[animation->size].easing = &easing_in_quint; + break; + case EASING_OUT_QUINT: + animation->list[animation->size].easing = &easing_out_quint; + break; + case EASING_IN_OUT_QUINT: + animation->list[animation->size].easing = &easing_in_out_quint; + break; + case EASING_OUT_IN_QUINT: + animation->list[animation->size].easing = &easing_out_in_quint; + break; + /* Sine */ + case EASING_IN_SINE: + animation->list[animation->size].easing = &easing_in_sine; + break; + case EASING_OUT_SINE: + animation->list[animation->size].easing = &easing_out_sine; + break; + case EASING_IN_OUT_SINE: + animation->list[animation->size].easing = &easing_in_out_sine; + break; + case EASING_OUT_IN_SINE: + animation->list[animation->size].easing = &easing_out_in_sine; + break; + /* Expo */ + case EASING_IN_EXPO: + animation->list[animation->size].easing = &easing_in_expo; + break; + case EASING_OUT_EXPO: + animation->list[animation->size].easing = &easing_out_expo; + break; + case EASING_IN_OUT_EXPO: + animation->list[animation->size].easing = &easing_in_out_expo; + break; + case EASING_OUT_IN_EXPO: + animation->list[animation->size].easing = &easing_out_in_expo; + break; + /* Circ */ + case EASING_IN_CIRC: + animation->list[animation->size].easing = &easing_in_circ; + break; + case EASING_OUT_CIRC: + animation->list[animation->size].easing = &easing_out_circ; + break; + case EASING_IN_OUT_CIRC: + animation->list[animation->size].easing = &easing_in_out_circ; + break; + case EASING_OUT_IN_CIRC: + animation->list[animation->size].easing = &easing_out_in_circ; + break; + /* Bounce */ + case EASING_IN_BOUNCE: + animation->list[animation->size].easing = &easing_in_bounce; + break; + case EASING_OUT_BOUNCE: + animation->list[animation->size].easing = &easing_out_bounce; + break; + case EASING_IN_OUT_BOUNCE: + animation->list[animation->size].easing = &easing_in_out_bounce; + break; + case EASING_OUT_IN_BOUNCE: + animation->list[animation->size].easing = &easing_out_in_bounce; + break; + default: + animation->list[animation->size].easing = NULL; + break; + } + animation->size++; return true; @@ -102,246 +443,3 @@ void menu_animation_update(animation_t *animation, float dt) animation->size = 0; } -/* Linear */ - -float linear(float t, float b, float c, float d) -{ - return c * t / d + b; -} - -/* Quad */ - -float inQuad(float t, float b, float c, float d) -{ - return c * pow(t / d, 2) + b; -} - -float outQuad(float t, float b, float c, float d) -{ - t = t / d; - return -c * t * (t - 2) + b; -} - -float inOutQuad(float t, float b, float c, float d) -{ - t = t / d * 2; - if (t < 1) - return c / 2 * pow(t, 2) + b; - return -c / 2 * ((t - 1) * (t - 3) - 1) + b; -} - -float outInQuad(float t, float b, float c, float d) -{ - if (t < d / 2) - return outQuad(t * 2, b, c / 2, d); - return inQuad((t * 2) - d, b + c / 2, c / 2, d); -} - -/* Cubic */ - -float inCubic(float t, float b, float c, float d) -{ - return c * pow(t / d, 3) + b; -} - -float outCubic(float t, float b, float c, float d) -{ - return c * (pow(t / d - 1, 3) + 1) + b; -} - -float inOutCubic(float t, float b, float c, float d) -{ - t = t / d * 2; - if (t < 1) - return c / 2 * t * t * t + b; - t = t - 2; - return c / 2 * (t * t * t + 2) + b; -} - -float outInCubic(float t, float b, float c, float d) -{ - if (t < d / 2) - return outCubic(t * 2, b, c / 2, d); - return inCubic((t * 2) - d, b + c / 2, c / 2, d); -} - -/* Quart */ - -float inQuart(float t, float b, float c, float d) -{ - return c * pow(t / d, 4) + b; -} - -float outQuart(float t, float b, float c, float d) -{ - return -c * (pow(t / d - 1, 4) - 1) + b; -} - -float inOutQuart(float t, float b, float c, float d) -{ - t = t / d * 2; - if (t < 1) - return c / 2 * pow(t, 4) + b; - return -c / 2 * (pow(t - 2, 4) - 2) + b; -} - -float outInQuart(float t, float b, float c, float d) -{ - if (t < d / 2) - return outQuart(t * 2, b, c / 2, d); - return inQuart((t * 2) - d, b + c / 2, c / 2, d); -} - -/* Quint */ - -float inQuint(float t, float b, float c, float d) -{ - return c * pow(t / d, 5) + b; -} - -float outQuint(float t, float b, float c, float d) -{ - return c * (pow(t / d - 1, 5) + 1) + b; -} - -float inOutQuint(float t, float b, float c, float d) -{ - t = t / d * 2; - if (t < 1) - return c / 2 * pow(t, 5) + b; - return c / 2 * (pow(t - 2, 5) + 2) + b; -} - -float outInQuint(float t, float b, float c, float d) -{ - if (t < d / 2) - return outQuint(t * 2, b, c / 2, d); - return inQuint((t * 2) - d, b + c / 2, c / 2, d); -} - -/* Sine */ - -float inSine(float t, float b, float c, float d) -{ - return -c * cos(t / d * (M_PI / 2)) + c + b; -} - -float outSine(float t, float b, float c, float d) -{ - return c * sin(t / d * (M_PI / 2)) + b; -} - -float inOutSine(float t, float b, float c, float d) -{ - return -c / 2 * (cos(M_PI * t / d) - 1) + b; -} - -float outInSine(float t, float b, float c, float d) -{ - if (t < d / 2) - return outSine(t * 2, b, c / 2, d); - return inSine((t * 2) -d, b + c / 2, c / 2, d); -} - -/* Expo */ - -float inExpo(float t, float b, float c, float d) -{ - if (t == 0) - return b; - return c * powf(2, 10 * (t / d - 1)) + b - c * 0.001; -} - -float outExpo(float t, float b, float c, float d) -{ - if (t == d) - return b + c; - return c * 1.001 * (-powf(2, -10 * t / d) + 1) + b; -} - -float inOutExpo(float t, float b, float c, float d) -{ - if (t == 0) - return b; - if (t == d) - return b + c; - t = t / d * 2; - if (t < 1) - return c / 2 * powf(2, 10 * (t - 1)) + b - c * 0.0005; - return c / 2 * 1.0005 * (-powf(2, -10 * (t - 1)) + 2) + b; -} - -float outInExpo(float t, float b, float c, float d) -{ - if (t < d / 2) - return outExpo(t * 2, b, c / 2, d); - return inExpo((t * 2) - d, b + c / 2, c / 2, d); -} - -/* Circ */ - -float inCirc(float t, float b, float c, float d) -{ - return(-c * (sqrt(1 - powf(t / d, 2)) - 1) + b); -} - -float outCirc(float t, float b, float c, float d) -{ - return(c * sqrt(1 - powf(t / d - 1, 2)) + b); -} - -float inOutCirc(float t, float b, float c, float d) -{ - t = t / d * 2; - if (t < 1) - return -c / 2 * (sqrt(1 - t * t) - 1) + b; - t = t - 2; - return c / 2 * (sqrt(1 - t * t) + 1) + b; -} - -float outInCirc(float t, float b, float c, float d) -{ - if (t < d / 2) - return outCirc(t * 2, b, c / 2, d); - return inCirc((t * 2) - d, b + c / 2, c / 2, d); -} - -/* Bounce */ - -float outBounce(float t, float b, float c, float d) -{ - t = t / d; - if (t < 1 / 2.75) - return c * (7.5625 * t * t) + b; - if (t < 2 / 2.75) - { - t = t - (1.5 / 2.75); - return c * (7.5625 * t * t + 0.75) + b; - } - else if (t < 2.5 / 2.75) - { - t = t - (2.25 / 2.75); - return c * (7.5625 * t * t + 0.9375) + b; - } - t = t - (2.625 / 2.75); - return c * (7.5625 * t * t + 0.984375) + b; -} - -float inBounce(float t, float b, float c, float d) -{ - return c - outBounce(d - t, 0, c, d) + b; -} - -float inOutBounce(float t, float b, float c, float d) -{ - if (t < d / 2) - return inBounce(t * 2, 0, c, d) * 0.5 + b; - return outBounce(t * 2 - d, 0, c, d) * 0.5 + c * .5 + b; -} - -float outInBounce(float t, float b, float c, float d) -{ - if (t < d / 2) - return outBounce(t * 2, b, c / 2, d); - return inBounce((t * 2) - d, b + c / 2, c / 2, d); -} diff --git a/menu/menu_animation.h b/menu/menu_animation.h index e2b15c8e08..69e7a6aef5 100644 --- a/menu/menu_animation.h +++ b/menu/menu_animation.h @@ -48,81 +48,60 @@ typedef struct animation size_t size; } animation_t; +enum animation_easing_type +{ + /* Linear */ + EASING_LINEAR = 0, + /* Quad */ + EASING_IN_QUAD, + EASING_OUT_QUAD, + EASING_IN_OUT_QUAD, + EASING_OUT_IN_QUAD, + /* Cubic */ + EASING_IN_CUBIC, + EASING_OUT_CUBIC, + EASING_IN_OUT_CUBIC, + EASING_OUT_IN_CUBIC, + /* Quart */ + EASING_IN_QUART, + EASING_OUT_QUART, + EASING_IN_OUT_QUART, + EASING_OUT_IN_QUART, + /* Quint */ + EASING_IN_QUINT, + EASING_OUT_QUINT, + EASING_IN_OUT_QUINT, + EASING_OUT_IN_QUINT, + /* Sine */ + EASING_IN_SINE, + EASING_OUT_SINE, + EASING_IN_OUT_SINE, + EASING_OUT_IN_SINE, + /* Expo */ + EASING_IN_EXPO, + EASING_OUT_EXPO, + EASING_IN_OUT_EXPO, + EASING_OUT_IN_EXPO, + /* Circ */ + EASING_IN_CIRC, + EASING_OUT_CIRC, + EASING_IN_OUT_CIRC, + EASING_OUT_IN_CIRC, + /* Bounce */ + EASING_IN_BOUNCE, + EASING_OUT_BOUNCE, + EASING_IN_OUT_BOUNCE, + EASING_OUT_IN_BOUNCE, +}; + void menu_animation_free(animation_t *animation); -bool menu_animation_push(animation_t *animation, float duration, float target_value, float* subject, - easingFunc easing, tween_cb cb); +bool menu_animation_push(animation_t *animation, float duration, + float target_value, float* subject, + enum animation_easing_type easing_enum, tween_cb cb); void menu_animation_update(animation_t *animation, float dt); -/* from https://github.com/kikito/tween.lua/blob/master/tween.lua */ - -float linear(float t, float b, float c, float d); - -float inQuad(float t, float b, float c, float d); - -float outQuad(float t, float b, float c, float d); - -float inOutQuad(float t, float b, float c, float d); - -float outInQuad(float t, float b, float c, float d); - -float inCubic(float t, float b, float c, float d); - -float outCubic(float t, float b, float c, float d); - -float inOutCubic(float t, float b, float c, float d); - -float outInCubic(float t, float b, float c, float d); - -float inQuart(float t, float b, float c, float d); - -float outQuart(float t, float b, float c, float d); - -float inOutQuart(float t, float b, float c, float d); - -float outInQuart(float t, float b, float c, float d); - -float inQuint(float t, float b, float c, float d); - -float outQuint(float t, float b, float c, float d); - -float inOutQuint(float t, float b, float c, float d); - -float outInQuint(float t, float b, float c, float d); - -float inSine(float t, float b, float c, float d); - -float outSine(float t, float b, float c, float d); - -float inOutSine(float t, float b, float c, float d); - -float outInSine(float t, float b, float c, float d); - -float inExpo(float t, float b, float c, float d); - -float outExpo(float t, float b, float c, float d); - -float inOutExpo(float t, float b, float c, float d); - -float outInExpo(float t, float b, float c, float d); - -float inCirc(float t, float b, float c, float d); - -float outCirc(float t, float b, float c, float d); - -float inOutCirc(float t, float b, float c, float d); - -float outInCirc(float t, float b, float c, float d); - -float inBounce(float t, float b, float c, float d); - -float outBounce(float t, float b, float c, float d); - -float inOutBounce(float t, float b, float c, float d); - -float outInBounce(float t, float b, float c, float d); - #ifdef __cplusplus } #endif