mirror of
https://github.com/libretro/RetroArch.git
synced 2025-01-21 08:26:17 +00:00
Move menu_ticker_line to menu_animation.c
This commit is contained in:
parent
915c97b76f
commit
00cd281a1f
@ -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));
|
||||
|
@ -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",
|
||||
|
@ -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, "...")
|
||||
|
59
menu/menu.c
59
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;
|
||||
|
14
menu/menu.h
14
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:
|
||||
*
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "menu_animation.h"
|
||||
#include "../driver.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <compat/strl.h>
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user