Simplify gfx_animation_ticker_generic

This commit is contained in:
twinaphex 2021-04-22 18:48:14 +02:00
parent d24f808d79
commit 0211e7749e

View File

@ -283,29 +283,26 @@ static float easing_out_in_bounce(float t, float b, float c, float d)
return easing_in_bounce((t * 2) - d, b + c / 2, c / 2, d); return easing_in_bounce((t * 2) - d, b + c / 2, c / 2, d);
} }
static void gfx_animation_ticker_generic(uint64_t idx, static size_t gfx_animation_ticker_generic(uint64_t idx,
size_t max_width, size_t *offset, size_t *width) size_t old_width)
{ {
int ticker_period = (int)(2 * (*width - max_width) + 4); const int phase_left_stop = 2;
int phase = idx % ticker_period; int ticker_period = (int)(2 * old_width + 4);
int phase = idx % ticker_period;
int phase_left_stop = 2; int phase_left_moving = (int)(phase_left_stop + old_width);
int phase_left_moving = (int)(phase_left_stop + (*width - max_width)); int phase_right_stop = phase_left_moving + 2;
int phase_right_stop = phase_left_moving + 2;
int left_offset = phase - phase_left_stop; int left_offset = phase - phase_left_stop;
int right_offset = (int)((*width - max_width) - (phase - phase_right_stop)); int right_offset = (int)(old_width - (phase - phase_right_stop));
if (phase < phase_left_stop) if (phase < phase_left_stop)
*offset = 0; return 0;
else if (phase < phase_left_moving) else if (phase < phase_left_moving)
*offset = left_offset; return left_offset;
else if (phase < phase_right_stop) else if (phase < phase_right_stop)
*offset = *width - max_width; return old_width;
else return right_offset;
*offset = right_offset;
*width = max_width;
} }
static void gfx_animation_ticker_loop(uint64_t idx, static void gfx_animation_ticker_loop(uint64_t idx,
@ -1428,13 +1425,11 @@ bool gfx_animation_ticker(gfx_animation_ctx_ticker_t *ticker)
case TICKER_TYPE_BOUNCE: case TICKER_TYPE_BOUNCE:
default: default:
{ {
size_t offset = 0; size_t offset = gfx_animation_ticker_generic(
gfx_animation_ticker_generic(
ticker->idx, ticker->idx,
ticker->len, str_len - ticker->len);
&offset,
&str_len); str_len = ticker->len;
utf8cpy( utf8cpy(
ticker->s, ticker->s,