don't scroll tickers for entries not highlighted

This commit is contained in:
ToadKing 2013-05-05 15:42:14 -04:00
parent 87c59df6ea
commit 858ad034c8
4 changed files with 32 additions and 27 deletions

View File

@ -561,7 +561,7 @@ void menu_free(void)
free(rgui);
}
void menu_ticker_line(char *buf, size_t len, unsigned index, const char *str)
void menu_ticker_line(char *buf, size_t len, unsigned index, const char *str, bool selected)
{
size_t str_len = strlen(str);
if (str_len <= len)
@ -570,27 +570,31 @@ void menu_ticker_line(char *buf, size_t len, unsigned index, const char *str)
return;
}
// Wrap long strings in options with some kind of ticker line.
unsigned ticker_period = 2 * (str_len - len) + 4;
unsigned phase = index % ticker_period;
unsigned phase_left_stop = 2;
unsigned phase_left_moving = phase_left_stop + (str_len - len);
unsigned phase_right_stop = phase_left_moving + 2;
unsigned left_offset = phase - phase_left_stop;
unsigned 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);
if (!selected)
snprintf(buf, len, "%.*s...", len - 3, str);
else
strlcpy(buf, str + right_offset, len + 1);
{
// Wrap long strings in options with some kind of ticker line.
unsigned ticker_period = 2 * (str_len - len) + 4;
unsigned phase = index % ticker_period;
unsigned phase_left_stop = 2;
unsigned phase_left_moving = phase_left_stop + (str_len - len);
unsigned phase_right_stop = phase_left_moving + 2;
unsigned left_offset = phase - phase_left_stop;
unsigned 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);
}
}
#ifndef HAVE_RMENU_XUI

View File

@ -280,7 +280,7 @@ void shader_manager_get_str(struct gfx_shader *shader,
char *type_str, size_t type_str_size, unsigned type);
#endif
void menu_ticker_line(char *buf, size_t len, unsigned tick, const char *str);
void menu_ticker_line(char *buf, size_t len, unsigned tick, const char *str, bool selected);
void load_menu_game_prepare(void);
bool load_menu_game(void);

View File

@ -436,7 +436,7 @@ static void render_text(rgui_handle_t *rgui)
}
char title_buf[256];
menu_ticker_line(title_buf, TERM_WIDTH - 3, g_extern.frame_count / 15, title);
menu_ticker_line(title_buf, TERM_WIDTH - 3, g_extern.frame_count / 15, title, true);
blit_line(rgui, TERM_START_X + 15, 15, title_buf, true);
char title_msg[64];
@ -728,23 +728,24 @@ static void render_text(rgui_handle_t *rgui)
char entry_title_buf[256];
char type_str_buf[64];
bool selected = i == rgui->selection_ptr;
strlcpy(entry_title_buf, path, sizeof(entry_title_buf));
strlcpy(type_str_buf, type_str, sizeof(type_str_buf));
if ((type == RGUI_FILE_PLAIN || type == RGUI_FILE_DIRECTORY))
menu_ticker_line(entry_title_buf, TERM_WIDTH - (w + 1 + 2), g_extern.frame_count / 15, path);
menu_ticker_line(entry_title_buf, TERM_WIDTH - (w + 1 + 2), g_extern.frame_count / 15, path, selected);
else
menu_ticker_line(type_str_buf, w, g_extern.frame_count / 15, type_str);
menu_ticker_line(type_str_buf, w, g_extern.frame_count / 15, type_str, selected);
snprintf(message, sizeof(message), "%c %-*.*s %-*s",
i == rgui->selection_ptr ? '>' : ' ',
selected ? '>' : ' ',
TERM_WIDTH - (w + 1 + 2), TERM_WIDTH - (w + 1 + 2),
entry_title_buf,
w,
type_str_buf);
blit_line(rgui, x, y, message, i == rgui->selection_ptr);
blit_line(rgui, x, y, message, selected);
}
#ifdef GEKKO

View File

@ -2280,7 +2280,7 @@ static int select_setting(void *data, uint64_t input)
}
char setting_text_buf[256];
menu_ticker_line(setting_text_buf, TICKER_LABEL_CHARS_MAX_PER_LINE, g_extern.frame_count / 15, setting_text);
menu_ticker_line(setting_text_buf, TICKER_LABEL_CHARS_MAX_PER_LINE, g_extern.frame_count / 15, setting_text, i == selected);
if (!(j < NUM_ENTRY_PER_PAGE))
{