diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index fecb46fbb8..3eb77bc192 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -307,7 +307,7 @@ static void glui_frame(void) get_title(label, dir, menu_type, title, sizeof(title)); - menu_ticker_line(title_buf, glui->term_width - 3, + menu_animation_ticker_line(title_buf, glui->term_width - 3, g_extern.frame_count / glui->margin, title, true); glui_blit_line(gl, glui->margin * 2, glui->margin + glui->line_height, title_buf, true); @@ -370,9 +370,9 @@ static void glui_frame(void) selected = (i == driver.menu->selection_ptr); - menu_ticker_line(entry_title_buf, glui->term_width - (w + 1 + 2), + menu_animation_ticker_line(entry_title_buf, glui->term_width - (w + 1 + 2), g_extern.frame_count / glui->margin, path_buf, selected); - menu_ticker_line(type_str_buf, w, + menu_animation_ticker_line(type_str_buf, w, g_extern.frame_count / glui->margin, type_str, selected); strlcpy(message, entry_title_buf, sizeof(message)); diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 85931b823b..6f53ea0fd1 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -354,7 +354,7 @@ static void rgui_render(void) get_title(label, dir, menu_type, title, sizeof(title)); - menu_ticker_line(title_buf, RGUI_TERM_WIDTH - 3, + menu_animation_ticker_line(title_buf, RGUI_TERM_WIDTH - 3, g_extern.frame_count / RGUI_TERM_START_X, title, true); blit_line(RGUI_TERM_START_X + RGUI_TERM_START_X, RGUI_TERM_START_X, title_buf, true); @@ -418,9 +418,9 @@ static void rgui_render(void) if (i > (driver.menu->selection_ptr + 100)) continue; - menu_ticker_line(entry_title_buf, RGUI_TERM_WIDTH - (w + 1 + 2), + menu_animation_ticker_line(entry_title_buf, RGUI_TERM_WIDTH - (w + 1 + 2), g_extern.frame_count / RGUI_TERM_START_X, path_buf, selected); - menu_ticker_line(type_str_buf, w, g_extern.frame_count / RGUI_TERM_START_X, + menu_animation_ticker_line(type_str_buf, w, g_extern.frame_count / RGUI_TERM_START_X, type_str, selected); snprintf(message, sizeof(message), "%c %-*.*s %-*s", diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 56e7e8373d..1315c78ebe 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -867,7 +867,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, xmb_draw_icon(gl, xmb, icon, icon_x, icon_y, node->alpha, 0, node->zoom); - menu_ticker_line(name, 35, g_extern.frame_count / 20, path_buf, + menu_animation_ticker_line(name, 35, g_extern.frame_count / 20, path_buf, (i == current)); xmb_draw_text(gl, xmb, name, @@ -875,7 +875,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, xmb->margin_top + node->y + xmb->label_margin_top, 1, node->label_alpha, 0); - menu_ticker_line(value, 35, g_extern.frame_count / 20, type_str, + menu_animation_ticker_line(value, 35, g_extern.frame_count / 20, type_str, (i == current)); if(( strcmp(type_str, "...") diff --git a/menu/menu.c b/menu/menu.c index ff2e38a402..35f569e20c 100644 --- a/menu/menu.c +++ b/menu/menu.c @@ -275,65 +275,6 @@ void menu_free(void *data) free(data); } -/** - * menu_ticker_line: - * @buf : buffer to write new message line to. - * @len : length of buffer @input. - * @idx : Index. Will be used for ticker logic. - * @str : Input string. - * @selected : Is the item currently selected in the menu? - * - * Take the contents of @str and apply a ticker effect to it, - * and write the results in @buf. - **/ -void menu_ticker_line(char *buf, size_t len, unsigned idx, - const char *str, bool selected) -{ - unsigned ticker_period, phase, phase_left_stop; - unsigned phase_left_moving, phase_right_stop; - unsigned left_offset, right_offset; - size_t str_len = strlen(str); - - if (str_len <= len) - { - strlcpy(buf, str, len + 1); - return; - } - - if (!selected) - { - strlcpy(buf, str, len + 1 - 3); - strlcat(buf, "...", len + 1); - return; - } - - /* Wrap long strings in options with some kind of ticker line. */ - ticker_period = 2 * (str_len - len) + 4; - phase = idx % ticker_period; - - phase_left_stop = 2; - phase_left_moving = phase_left_stop + (str_len - len); - phase_right_stop = phase_left_moving + 2; - - left_offset = phase - phase_left_stop; - right_offset = (str_len - len) - (phase - phase_right_stop); - - /* Ticker period: - * [Wait at left (2 ticks), - * Progress to right(type_len - w), - * Wait at right (2 ticks), - * Progress to left]. - */ - if (phase < phase_left_stop) - strlcpy(buf, str, len + 1); - else if (phase < phase_left_moving) - strlcpy(buf, str + left_offset, len + 1); - else if (phase < phase_right_stop) - strlcpy(buf, str + str_len - len, len + 1); - else - strlcpy(buf, str + right_offset, len + 1); -} - void menu_apply_deferred_settings(void) { rarch_setting_t *setting = NULL; diff --git a/menu/menu.h b/menu/menu.h index 56eaae055b..28366d84e1 100644 --- a/menu/menu.h +++ b/menu/menu.h @@ -177,20 +177,6 @@ int menu_iterate(retro_input_t input, **/ void menu_free(void *data); -/** - * menu_ticker_line: - * @buf : buffer to write new message line to. - * @len : length of buffer @input. - * @idx : Index. Will be used for ticker logic. - * @str : Input string. - * @selected : Is the item currently selected in the menu? - * - * Take the contents of @str and apply a ticker effect to it, - * and write the results in @buf. - **/ -void menu_ticker_line(char *buf, size_t len, unsigned tick, - const char *str, bool selected); - /** * menu_load_content: * diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 9bf8e6534e..67797be801 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -17,6 +17,8 @@ #include "menu_animation.h" #include "../driver.h" #include +#include +#include /* from https://github.com/kikito/tween.lua/blob/master/tween.lua */ @@ -444,3 +446,61 @@ void menu_animation_update(animation_t *animation, float dt) animation->size = 0; } +/** + * menu_animation_ticker_line: + * @buf : buffer to write new message line to. + * @len : length of buffer @input. + * @idx : Index. Will be used for ticker logic. + * @str : Input string. + * @selected : Is the item currently selected in the menu? + * + * Take the contents of @str and apply a ticker effect to it, + * and write the results in @buf. + **/ +void menu_animation_ticker_line(char *buf, size_t len, unsigned idx, + const char *str, bool selected) +{ + unsigned ticker_period, phase, phase_left_stop; + unsigned phase_left_moving, phase_right_stop; + unsigned left_offset, right_offset; + size_t str_len = strlen(str); + + if (str_len <= len) + { + strlcpy(buf, str, len + 1); + return; + } + + if (!selected) + { + strlcpy(buf, str, len + 1 - 3); + strlcat(buf, "...", len + 1); + return; + } + + /* Wrap long strings in options with some kind of ticker line. */ + ticker_period = 2 * (str_len - len) + 4; + phase = idx % ticker_period; + + phase_left_stop = 2; + phase_left_moving = phase_left_stop + (str_len - len); + phase_right_stop = phase_left_moving + 2; + + left_offset = phase - phase_left_stop; + right_offset = (str_len - len) - (phase - phase_right_stop); + + /* Ticker period: + * [Wait at left (2 ticks), + * Progress to right(type_len - w), + * Wait at right (2 ticks), + * Progress to left]. + */ + if (phase < phase_left_stop) + strlcpy(buf, str, len + 1); + else if (phase < phase_left_moving) + strlcpy(buf, str + left_offset, len + 1); + else if (phase < phase_right_stop) + strlcpy(buf, str + str_len - len, len + 1); + else + strlcpy(buf, str + right_offset, len + 1); +} diff --git a/menu/menu_animation.h b/menu/menu_animation.h index 69e7a6aef5..0bbca69282 100644 --- a/menu/menu_animation.h +++ b/menu/menu_animation.h @@ -102,6 +102,20 @@ bool menu_animation_push(animation_t *animation, float duration, void menu_animation_update(animation_t *animation, float dt); +/** + * menu_animation_ticker_line: + * @buf : buffer to write new message line to. + * @len : length of buffer @input. + * @idx : Index. Will be used for ticker logic. + * @str : Input string. + * @selected : Is the item currently selected in the menu? + * + * Take the contents of @str and apply a ticker effect to it, + * and write the results in @buf. + **/ +void menu_animation_ticker_line(char *buf, size_t len, unsigned tick, + const char *str, bool selected); + #ifdef __cplusplus } #endif