mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 18:40:49 +00:00
Merge pull request #1975 from heuripedes/glui-improvements
GLUI improvements
This commit is contained in:
commit
0cdde16e2d
@ -308,6 +308,28 @@ static void glui_render(void)
|
||||
menu_entries_set_start(menu->scroll_y / glui->line_height);
|
||||
}
|
||||
|
||||
static void glui_render_label_value(glui_handle_t *glui, int y, unsigned width,
|
||||
uint64_t index, uint32_t color, bool selected, const char *label, const char *value)
|
||||
{
|
||||
char label_str[PATH_MAX_LENGTH];
|
||||
char value_str[PATH_MAX_LENGTH];
|
||||
int label_limit = glui->ticker_limit;
|
||||
int value_len = strlen(value);
|
||||
|
||||
label_str[0] = '\0';
|
||||
value_str[0] = '\0';
|
||||
|
||||
/* resize label boundary to fit more on the screen */
|
||||
if (value_len + 2 < glui->ticker_limit)
|
||||
label_limit += (int)glui->ticker_limit - (value_len + 2);
|
||||
|
||||
menu_animation_ticker_str(label_str, label_limit, index, label, selected);
|
||||
menu_animation_ticker_str(value_str, glui->ticker_limit, index, value, selected);
|
||||
|
||||
glui_blit_line(glui->margin, y, label_str, color, TEXT_ALIGN_LEFT);
|
||||
glui_blit_line(width - glui->margin, y, value_str, color, TEXT_ALIGN_RIGHT);
|
||||
}
|
||||
|
||||
static void glui_render_menu_list(glui_handle_t *glui,
|
||||
menu_handle_t *menu,
|
||||
uint32_t normal_color,
|
||||
@ -331,34 +353,19 @@ static void glui_render_menu_list(glui_handle_t *glui,
|
||||
{
|
||||
bool entry_selected;
|
||||
menu_entry_t entry;
|
||||
char message[PATH_MAX_LENGTH];
|
||||
char entry_title_buf[PATH_MAX_LENGTH];
|
||||
char type_str_buf[PATH_MAX_LENGTH];
|
||||
|
||||
int y = disp->header_height - menu->scroll_y + (glui->line_height * i);
|
||||
|
||||
if (y > (int)height || ((y + (int)glui->line_height) < 0))
|
||||
continue;
|
||||
|
||||
message[0] = '\0';
|
||||
entry_title_buf[0] = '\0';
|
||||
type_str_buf[0] = '\0';
|
||||
|
||||
menu_entries_get(i, &entry);
|
||||
|
||||
entry_selected = entries->navigation.selection_ptr == i;
|
||||
|
||||
menu_animation_ticker_line(entry_title_buf, glui->ticker_limit,
|
||||
frame_count / 40, entry.path, entry_selected);
|
||||
menu_animation_ticker_line(type_str_buf, glui->ticker_limit,
|
||||
frame_count / 40, entry.value, entry_selected);
|
||||
|
||||
strlcpy(message, entry_title_buf, sizeof(message));
|
||||
|
||||
glui_blit_line(glui->margin, y, message,
|
||||
entry_selected ? hover_color : normal_color, TEXT_ALIGN_LEFT);
|
||||
|
||||
glui_blit_line(width - glui->margin, y, type_str_buf,
|
||||
entry_selected ? hover_color : normal_color, TEXT_ALIGN_RIGHT);
|
||||
glui_render_label_value(glui, y, width, frame_count / 40,
|
||||
entry_selected ? hover_color : normal_color, entry_selected,
|
||||
entry.path, entry.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,7 +436,7 @@ static void glui_frame(void)
|
||||
glui_render_quad(gl, 0, 0, width,
|
||||
disp->header_height, 0.2, 0.2, 0.2, 1);
|
||||
|
||||
menu_animation_ticker_line(title_buf, glui->ticker_limit,
|
||||
menu_animation_ticker_str(title_buf, glui->ticker_limit,
|
||||
frame_count / 100, title, true);
|
||||
glui_blit_line(width / 2, 0, title_buf,
|
||||
title_color, TEXT_ALIGN_CENTER);
|
||||
@ -505,8 +512,20 @@ static void glui_allocate_white_texture(glui_handle_t *glui)
|
||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_NEAREST);
|
||||
}
|
||||
|
||||
static void glui_font(menu_handle_t *menu)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
const char *font_path = NULL;
|
||||
|
||||
font_path = settings->video.font_enable ? settings->video.font_path : NULL;
|
||||
|
||||
if (!menu_display_init_main_font(menu, font_path, menu->display.font.size))
|
||||
RARCH_ERR("Failed to load font.");
|
||||
}
|
||||
|
||||
static void glui_layout(menu_handle_t *menu, glui_handle_t *glui)
|
||||
{
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
float scale_factor, glyph_width;
|
||||
unsigned width, height;
|
||||
video_driver_get_size(&width, &height);
|
||||
@ -515,11 +534,7 @@ static void glui_layout(menu_handle_t *menu, glui_handle_t *glui)
|
||||
resolution, so we should be dpi aware to ensure the entries hitboxes are big
|
||||
enough. On desktops, we just care about readability, with every widget size
|
||||
proportional to the display width. */
|
||||
#ifdef RARCH_MOBILE
|
||||
scale_factor = menu_display_get_dpi();
|
||||
#else
|
||||
scale_factor = width / 7.5;
|
||||
#endif
|
||||
|
||||
glui->line_height = scale_factor / 3;
|
||||
glui->margin = scale_factor / 6;
|
||||
@ -528,6 +543,17 @@ static void glui_layout(menu_handle_t *menu, glui_handle_t *glui)
|
||||
/* we assume the average glyph aspect ratio is close to 3:4 */
|
||||
glyph_width = menu->display.font.size * 3/4;
|
||||
glui->ticker_limit = (width/2) / glyph_width;
|
||||
|
||||
glui_font(menu);
|
||||
|
||||
if (disp && disp->font.buf) /* calculate a more realistic ticker_limit */
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
int m_width = driver->font_osd_driver->get_message_width(disp->font.buf, "M", 1, 1);
|
||||
|
||||
if (m_width)
|
||||
glui->ticker_limit = (width / 2) / m_width - 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void *glui_init(void)
|
||||
@ -717,17 +743,6 @@ static void glui_populate_entries(const char *path,
|
||||
menu->scroll_y = glui_get_scroll();
|
||||
}
|
||||
|
||||
static void glui_font(menu_handle_t *menu)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
const char *font_path = NULL;
|
||||
|
||||
font_path = settings->video.font_enable ? settings->video.font_path : NULL;
|
||||
|
||||
if (!menu_display_init_main_font(menu, font_path, menu->display.font.size))
|
||||
RARCH_WARN("Failed to load font.");
|
||||
}
|
||||
|
||||
static void glui_context_reset(void)
|
||||
{
|
||||
glui_handle_t *glui = NULL;
|
||||
@ -740,7 +755,6 @@ static void glui_context_reset(void)
|
||||
glui = (glui_handle_t*)menu->userdata;
|
||||
|
||||
glui_layout(menu, glui);
|
||||
glui_font(menu);
|
||||
glui_context_bg_destroy(glui);
|
||||
glui_allocate_white_texture(glui);
|
||||
|
||||
|
@ -466,7 +466,7 @@ static void rgui_render(void)
|
||||
|
||||
menu_entries_get_title(title, sizeof(title));
|
||||
|
||||
menu_animation_ticker_line(title_buf, RGUI_TERM_WIDTH - 10,
|
||||
menu_animation_ticker_str(title_buf, RGUI_TERM_WIDTH - 10,
|
||||
frame_count / RGUI_TERM_START_X, title, true);
|
||||
|
||||
hover_color = HOVER_COLOR(settings);
|
||||
@ -527,9 +527,9 @@ static void rgui_render(void)
|
||||
menu_entry_get_value(i, entry_value, sizeof(entry_value));
|
||||
menu_entry_get_path(i, entry_path, sizeof(entry_path));
|
||||
|
||||
menu_animation_ticker_line(entry_title_buf, RGUI_TERM_WIDTH - (entry_spacing + 1 + 2),
|
||||
menu_animation_ticker_str(entry_title_buf, RGUI_TERM_WIDTH - (entry_spacing + 1 + 2),
|
||||
frame_count / RGUI_TERM_START_X, entry_path, entry_selected);
|
||||
menu_animation_ticker_line(type_str_buf, entry_spacing,
|
||||
menu_animation_ticker_str(type_str_buf, entry_spacing,
|
||||
frame_count / RGUI_TERM_START_X,
|
||||
entry_value, entry_selected);
|
||||
|
||||
|
@ -171,7 +171,7 @@ static void rmenu_render(void)
|
||||
|
||||
menu_entries_get_title(title, sizeof(title));
|
||||
|
||||
menu_animation_ticker_line(title_buf, RMENU_TERM_WIDTH,
|
||||
menu_animation_ticker_str(title_buf, RMENU_TERM_WIDTH,
|
||||
frame_count / 15, title, true);
|
||||
|
||||
font_parms.x = POSITION_EDGE_MIN + POSITION_OFFSET;
|
||||
@ -206,9 +206,9 @@ static void rmenu_render(void)
|
||||
menu_entry_get_value(i, entry_value, sizeof(entry_value));
|
||||
menu_entry_get_path(i, entry_path, sizeof(entry_path));
|
||||
|
||||
menu_animation_ticker_line(entry_title_buf, RMENU_TERM_WIDTH - (entry_spacing + 1 + 2),
|
||||
menu_animation_ticker_str(entry_title_buf, RMENU_TERM_WIDTH - (entry_spacing + 1 + 2),
|
||||
frame_count / 15, entry_path, entry_selected);
|
||||
menu_animation_ticker_line(type_str_buf, entry_spacing,
|
||||
menu_animation_ticker_str(type_str_buf, entry_spacing,
|
||||
frame_count / 15, entry_value, entry_selected);
|
||||
|
||||
snprintf(message, sizeof(message), "%c %s",
|
||||
|
@ -560,7 +560,7 @@ static void rmenu_xui_render(void)
|
||||
menu_entries_get_title(title, sizeof(title));
|
||||
mbstowcs(strw_buffer, title, sizeof(strw_buffer) / sizeof(wchar_t));
|
||||
XuiTextElementSetText(m_menutitle, strw_buffer);
|
||||
menu_animation_ticker_line(title, RXUI_TERM_WIDTH - 3, (unsigned int)frame_count / 15, title, true);
|
||||
menu_animation_ticker_str(title, RXUI_TERM_WIDTH - 3, (unsigned int)frame_count / 15, title, true);
|
||||
}
|
||||
|
||||
if (XuiHandleIsValid(m_menutitle))
|
||||
|
@ -1388,7 +1388,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl,
|
||||
ticker_limit = 70;
|
||||
}
|
||||
|
||||
menu_animation_ticker_line(name, ticker_limit,
|
||||
menu_animation_ticker_str(name, ticker_limit,
|
||||
frame_count / 20, entry.path,
|
||||
(i == current));
|
||||
|
||||
@ -1398,7 +1398,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl,
|
||||
xmb->margins.screen.top + node->y + xmb->margins.label.top,
|
||||
1, node->label_alpha, TEXT_ALIGN_LEFT);
|
||||
|
||||
menu_animation_ticker_line(value, 35,
|
||||
menu_animation_ticker_str(value, 35,
|
||||
frame_count / 20, entry.value,
|
||||
(i == current));
|
||||
|
||||
|
@ -545,8 +545,42 @@ bool menu_animation_update(menu_animation_t *anim, float dt)
|
||||
return true;
|
||||
}
|
||||
|
||||
void menu_animation_ticker_generic(uint64_t idx, int max_width,
|
||||
int *offset, int *width)
|
||||
{
|
||||
int ticker_period, phase, phase_left_stop;
|
||||
int phase_left_moving, phase_right_stop;
|
||||
int left_offset, right_offset;
|
||||
|
||||
*offset = 0;
|
||||
|
||||
if (*width <= max_width)
|
||||
return;
|
||||
|
||||
ticker_period = 2 * (*width - max_width) + 4;
|
||||
phase = idx % ticker_period;
|
||||
|
||||
phase_left_stop = 2;
|
||||
phase_left_moving = phase_left_stop + (*width - max_width);
|
||||
phase_right_stop = phase_left_moving + 2;
|
||||
|
||||
left_offset = phase - phase_left_stop;
|
||||
right_offset = (*width - max_width) - (phase - phase_right_stop);
|
||||
|
||||
if (phase < phase_left_stop)
|
||||
*offset = 0;
|
||||
else if (phase < phase_left_moving)
|
||||
*offset = -left_offset;
|
||||
else if (phase < phase_right_stop)
|
||||
*offset = -(*width - max_width);
|
||||
else
|
||||
*offset = -right_offset;
|
||||
|
||||
*width = max_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* menu_animation_ticker_line:
|
||||
* menu_animation_ticker_str:
|
||||
* @s : buffer to write new message line to.
|
||||
* @len : length of buffer @input.
|
||||
* @idx : Index. Will be used for ticker logic.
|
||||
@ -556,14 +590,12 @@ bool menu_animation_update(menu_animation_t *anim, float dt)
|
||||
* Take the contents of @str and apply a ticker effect to it,
|
||||
* and write the results in @s.
|
||||
**/
|
||||
void menu_animation_ticker_line(char *s, size_t len, uint64_t idx,
|
||||
void menu_animation_ticker_str(char *s, size_t len, uint64_t 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);
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
int str_len = strlen(str);
|
||||
int offset = 0;
|
||||
|
||||
if (str_len <= len)
|
||||
{
|
||||
@ -578,31 +610,9 @@ void menu_animation_ticker_line(char *s, size_t len, uint64_t idx,
|
||||
return;
|
||||
}
|
||||
|
||||
/* Wrap long strings in options with some kind of ticker line. */
|
||||
ticker_period = 2 * (str_len - len) + 4;
|
||||
phase = idx % ticker_period;
|
||||
menu_animation_ticker_generic(idx, len, &offset, &str_len);
|
||||
|
||||
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(s, str, len + 1);
|
||||
else if (phase < phase_left_moving)
|
||||
strlcpy(s, str + left_offset, len + 1);
|
||||
else if (phase < phase_right_stop)
|
||||
strlcpy(s, str + str_len - len, len + 1);
|
||||
else
|
||||
strlcpy(s, str + right_offset, len + 1);
|
||||
strlcpy(s, str - offset, str_len + 1);
|
||||
|
||||
anim->is_active = true;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ bool menu_animation_update(
|
||||
float dt);
|
||||
|
||||
/**
|
||||
* menu_animation_ticker_line:
|
||||
* menu_animation_ticker_str:
|
||||
* @s : buffer to write new message line to.
|
||||
* @len : length of buffer @input.
|
||||
* @idx : Index. Will be used for ticker logic.
|
||||
@ -145,9 +145,12 @@ bool menu_animation_update(
|
||||
* Take the contents of @str and apply a ticker effect to it,
|
||||
* and write the results in @s.
|
||||
**/
|
||||
void menu_animation_ticker_line(char *s, size_t len, uint64_t tick,
|
||||
void menu_animation_ticker_str(char *s, size_t len, uint64_t tick,
|
||||
const char *str, bool selected);
|
||||
|
||||
void menu_animation_ticker_generic(uint64_t idx, int max_width,
|
||||
int *offset, int *width);
|
||||
|
||||
menu_animation_t *menu_animation_get_ptr(void);
|
||||
|
||||
void menu_animation_update_time(menu_animation_t *anim);
|
||||
|
Loading…
x
Reference in New Issue
Block a user