'menu_entry' optimisations

This commit is contained in:
jdgleaver 2019-05-30 10:09:26 +01:00
parent e680fab6e1
commit ff16fb347a
14 changed files with 304 additions and 328 deletions

View File

@ -46,6 +46,12 @@ static int action_select_default(const char *path, const char *label, unsigned t
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
menu_entry_init(&entry); menu_entry_init(&entry);
/* Note: If menu_entry_action() is modified,
* will have to verify that these parameters
* remain unused... */
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, idx, NULL, false); menu_entry_get(&entry, 0, idx, NULL, false);
if (selection_buf) if (selection_buf)
@ -53,10 +59,7 @@ static int action_select_default(const char *path, const char *label, unsigned t
file_list_get_actiondata_at_offset(selection_buf, idx); file_list_get_actiondata_at_offset(selection_buf, idx);
if (!cbs) if (!cbs)
{
menu_entry_free(&entry);
return -1; return -1;
}
if (cbs->setting) if (cbs->setting)
{ {
@ -102,8 +105,6 @@ static int action_select_default(const char *path, const char *label, unsigned t
if (action != MENU_ACTION_NOOP) if (action != MENU_ACTION_NOOP)
ret = menu_entry_action(&entry, (unsigned)idx, action); ret = menu_entry_action(&entry, (unsigned)idx, action);
menu_entry_free(&entry);
task_queue_check(); task_queue_check();
return ret; return ret;

View File

@ -606,33 +606,35 @@ static void materialui_compute_entries_box(materialui_handle_t* mui, int width)
for (i = 0; i < entries_end; i++) for (i = 0; i < entries_end; i++)
{ {
menu_entry_t entry; menu_entry_t entry;
char *sublabel_str = NULL; char wrapped_sublabel_str[512];
const char *sublabel_str = NULL;
unsigned lines = 0; unsigned lines = 0;
materialui_node_t *node = (materialui_node_t*) materialui_node_t *node = (materialui_node_t*)
file_list_get_userdata_at_offset(list, i); file_list_get_userdata_at_offset(list, i);
wrapped_sublabel_str[0] = '\0';
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get(&entry, 0, i, NULL, true);
sublabel_str = menu_entry_get_sublabel(&entry); menu_entry_get_sublabel(&entry, &sublabel_str);
menu_entry_free(&entry);
if (sublabel_str) if (!string_is_empty(sublabel_str))
{ {
if (!string_is_empty(sublabel_str)) int icon_margin = 0;
{
int icon_margin = 0;
if (node->texture_switch2_set) if (node->texture_switch2_set)
if (mui->textures.list[node->texture_switch2_index]) if (mui->textures.list[node->texture_switch2_index])
icon_margin = mui->icon_size; icon_margin = mui->icon_size;
word_wrap(sublabel_str, sublabel_str, word_wrap(wrapped_sublabel_str, sublabel_str,
(int)((usable_width - icon_margin) / mui->glyph_width2), (int)((usable_width - icon_margin) / mui->glyph_width2),
false, 0); false, 0);
lines = materialui_count_lines(sublabel_str); lines = materialui_count_lines(wrapped_sublabel_str);
}
free(sublabel_str);
} }
node->line_height = (scale_factor / 3) + (lines * mui->font->size); node->line_height = (scale_factor / 3) + (lines * mui->font->size);
@ -743,8 +745,9 @@ static void materialui_render_label_value(
menu_animation_ctx_ticker_t ticker; menu_animation_ctx_ticker_t ticker;
char label_str[255]; char label_str[255];
char value_str[255]; char value_str[255];
char wrapped_sublabel_str[512];
unsigned entry_type = 0; unsigned entry_type = 0;
char *sublabel_str = NULL; const char *sublabel_str = NULL;
bool switch_is_on = true; bool switch_is_on = true;
int value_len = (int)utf8len(value); int value_len = (int)utf8len(value);
int ticker_limit = 0; int ticker_limit = 0;
@ -761,9 +764,13 @@ static void materialui_render_label_value(
ticker.type_enum = (enum menu_animation_ticker_type)settings->uints.menu_ticker_type; ticker.type_enum = (enum menu_animation_ticker_type)settings->uints.menu_ticker_type;
ticker.spacer = NULL; ticker.spacer = NULL;
label_str[0] = value_str[0] = '\0'; label_str[0] = value_str[0] = wrapped_sublabel_str[0] = '\0';
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get(&entry, 0, i, NULL, true);
entry_type = menu_entry_get_type_new(&entry); entry_type = menu_entry_get_type_new(&entry);
@ -861,27 +868,23 @@ static void materialui_render_label_value(
} }
} }
sublabel_str = menu_entry_get_sublabel(&entry); menu_entry_get_sublabel(&entry, &sublabel_str);
if (texture_switch2) if (texture_switch2)
icon_margin = mui->icon_size; icon_margin = mui->icon_size;
/* Sublabel */ /* Sublabel */
if (sublabel_str) if (!string_is_empty(sublabel_str) && mui->font)
{ {
if (!string_is_empty(sublabel_str) && mui->font) word_wrap(wrapped_sublabel_str, sublabel_str,
{ (int)((usable_width - icon_margin) / mui->glyph_width2),
word_wrap(sublabel_str, sublabel_str, false, 0);
(int)((usable_width - icon_margin) / mui->glyph_width2),
false, 0);
menu_display_draw_text(mui->font2, sublabel_str, menu_display_draw_text(mui->font2, wrapped_sublabel_str,
mui->margin + icon_margin, mui->margin + icon_margin,
y + (scale_factor / 4) + mui->font->size, y + (scale_factor / 4) + mui->font->size,
width, height, sublabel_color, TEXT_ALIGN_LEFT, width, height, sublabel_color, TEXT_ALIGN_LEFT,
1.0f, false, 0, false); 1.0f, false, 0, false);
}
free(sublabel_str);
} }
menu_display_draw_text(mui->font, label_str, menu_display_draw_text(mui->font, label_str,
@ -931,8 +934,6 @@ static void materialui_render_label_value(
switch_is_on ? &label_color[0] : &pure_white[0] switch_is_on ? &label_color[0] : &pure_white[0]
); );
} }
menu_entry_free(&entry);
} }
static void materialui_render_menu_list( static void materialui_render_menu_list(
@ -964,16 +965,14 @@ static void materialui_render_menu_list(
for (i = 0; i < entries_end; i++) for (i = 0; i < entries_end; i++)
{ {
menu_entry_t entry; menu_entry_t entry;
char entry_value[255]; const char *entry_value = NULL;
char *rich_label = NULL; const char *rich_label = NULL;
bool entry_selected = false; bool entry_selected = false;
materialui_node_t *node = (materialui_node_t*) materialui_node_t *node = (materialui_node_t*)
file_list_get_userdata_at_offset(list, i); file_list_get_userdata_at_offset(list, i);
size_t selection = menu_navigation_get_selection(); size_t selection = menu_navigation_get_selection();
int y = header_height - mui->scroll_y + sum; int y = header_height - mui->scroll_y + sum;
entry_value[0] = '\0';
sum += node->line_height; sum += node->line_height;
if (y + (int)node->line_height < 0) if (y + (int)node->line_height < 0)
@ -983,9 +982,12 @@ static void materialui_render_menu_list(
break; break;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, (unsigned)i, NULL, true); menu_entry_get(&entry, 0, (unsigned)i, NULL, true);
menu_entry_get_value(&entry, entry_value, sizeof(entry_value)); menu_entry_get_value(&entry, &entry_value);
rich_label = menu_entry_get_rich_label(&entry); menu_entry_get_rich_label(&entry, &rich_label);
entry_selected = selection == i; entry_selected = selection == i;
/* Render label, value, and associated icons */ /* Render label, value, and associated icons */
@ -1006,9 +1008,6 @@ static void materialui_render_menu_list(
menu_list_color, menu_list_color,
sublabel_color sublabel_color
); );
menu_entry_free(&entry);
free(rich_label);
} }
} }

View File

@ -233,10 +233,15 @@ int generic_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_action a
selection = MAX(MIN(selection, (menu_entries_get_size() - 1)), 0); selection = MAX(MIN(selection, (menu_entries_get_size() - 1)), 0);
menu_entry_init(&entry); menu_entry_init(&entry);
/* Note: If menu_entry_action() is modified,
* will have to verify that these parameters
* remain unused... */
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, false); menu_entry_get(&entry, 0, selection, NULL, false);
ret = menu_entry_action(&entry, ret = menu_entry_action(&entry,
(unsigned)selection, (enum menu_action)action); (unsigned)selection, (enum menu_action)action);
menu_entry_free(&entry);
if (ret) if (ret)
goto end; goto end;

View File

@ -1285,12 +1285,14 @@ static void ozone_set_thumbnail_content(void *data, const char *s)
menu_entry_t entry; menu_entry_t entry;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
if (!string_is_empty(entry.path)) if (!string_is_empty(entry.path))
menu_thumbnail_set_content(ozone->thumbnail_path_data, entry.path); menu_thumbnail_set_content(ozone->thumbnail_path_data, entry.path);
menu_entry_free(&entry);
} }
} }
else if (string_is_equal(s, "imageviewer")) else if (string_is_equal(s, "imageviewer"))
@ -1301,13 +1303,15 @@ static void ozone_set_thumbnail_content(void *data, const char *s)
ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(selection_buf, selection); ozone_node_t *node = (ozone_node_t*)file_list_get_userdata_at_offset(selection_buf, selection);
menu_entry_init(&entry); menu_entry_init(&entry);
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
if (node) if (node)
if (!string_is_empty(entry.path) && !string_is_empty(node->fullpath)) if (!string_is_empty(entry.path) && !string_is_empty(node->fullpath))
menu_thumbnail_set_content_image(ozone->thumbnail_path_data, node->fullpath, entry.path); menu_thumbnail_set_content_image(ozone->thumbnail_path_data, node->fullpath, entry.path);
menu_entry_free(&entry);
} }
else if (!string_is_empty(s)) else if (!string_is_empty(s))
{ {
@ -1366,11 +1370,15 @@ static void ozone_selection_changed(ozone_handle_t *ozone, bool allow_animation)
size_t new_selection = menu_navigation_get_selection(); size_t new_selection = menu_navigation_get_selection();
ozone_node_t *node = (ozone_node_t*) file_list_get_userdata_at_offset(selection_buf, new_selection); ozone_node_t *node = (ozone_node_t*) file_list_get_userdata_at_offset(selection_buf, new_selection);
menu_entry_init(&entry);
if (!node) if (!node)
return; return;
menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
if (ozone->selection != new_selection) if (ozone->selection != new_selection)
@ -1424,8 +1432,6 @@ static void ozone_selection_changed(ozone_handle_t *ozone, bool allow_animation)
/* TODO: update savestate thumbnail and path */ /* TODO: update savestate thumbnail and path */
} }
menu_entry_free(&entry);
} }
static void ozone_navigation_clear(void *data, bool pending_push) static void ozone_navigation_clear(void *data, bool pending_push)

View File

@ -213,9 +213,14 @@ void ozone_compute_entries_position(ozone_handle_t *ozone)
{ {
/* Entry */ /* Entry */
menu_entry_t entry; menu_entry_t entry;
ozone_node_t *node = NULL; ozone_node_t *node = NULL;
const char *sublabel_str = NULL;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
menu_entry_get(&entry, 0, (unsigned)i, NULL, true); menu_entry_get(&entry, 0, (unsigned)i, NULL, true);
/* Empty playlist detection: /* Empty playlist detection:
@ -237,14 +242,20 @@ void ozone_compute_entries_position(ozone_handle_t *ozone)
if (!node) if (!node)
continue; continue;
node->height = ozone->dimensions.entry_height + (entry.sublabel ? ozone->dimensions.entry_spacing + 40 : 0); node->height = ozone->dimensions.entry_height;
node->wrap = false; node->wrap = false;
if (entry.sublabel) menu_entry_get_sublabel(&entry, &sublabel_str);
{
char *sublabel_str = menu_entry_get_sublabel(&entry);
int sublabel_max_width = video_info_width - if (!string_is_empty(sublabel_str))
{
int sublabel_max_width;
char wrapped_sublabel_str[512];
wrapped_sublabel_str[0] = '\0';
node->height += ozone->dimensions.entry_spacing + 40;
sublabel_max_width = video_info_width -
entry_padding * 2 - ozone->dimensions.entry_icon_padding * 2; entry_padding * 2 - ozone->dimensions.entry_icon_padding * 2;
if (ozone->depth == 1) if (ozone->depth == 1)
@ -253,24 +264,20 @@ void ozone_compute_entries_position(ozone_handle_t *ozone)
if (ozone->show_thumbnail_bar) if (ozone->show_thumbnail_bar)
sublabel_max_width -= ozone->dimensions.thumbnail_bar_width; sublabel_max_width -= ozone->dimensions.thumbnail_bar_width;
word_wrap(sublabel_str, sublabel_str, sublabel_max_width / ozone->sublabel_font_glyph_width, false, 0); word_wrap(wrapped_sublabel_str, sublabel_str, sublabel_max_width / ozone->sublabel_font_glyph_width, false, 0);
lines = ozone_count_lines(sublabel_str); lines = ozone_count_lines(wrapped_sublabel_str);
if (lines > 1) if (lines > 1)
{ {
node->height += lines * 15; node->height += lines * 15;
node->wrap = true; node->wrap = true;
} }
free(sublabel_str);
} }
node->position_y = ozone->entries_height; node->position_y = ozone->entries_height;
ozone->entries_height += node->height; ozone->entries_height += node->height;
menu_entry_free(&entry);
} }
/* Update scrolling */ /* Update scrolling */
@ -467,27 +474,29 @@ border_iterate:
menu_entry_t entry; menu_entry_t entry;
menu_animation_ctx_ticker_t ticker; menu_animation_ctx_ticker_t ticker;
static const char* const ticker_spacer = OZONE_TICKER_SPACER; static const char* const ticker_spacer = OZONE_TICKER_SPACER;
char entry_value[255];
char rich_label[255]; char rich_label[255];
char entry_value_ticker[255]; char entry_value_ticker[255];
char *sublabel_str; char wrapped_sublabel_str[512];
ozone_node_t *node = NULL; const char *sublabel_str = NULL;
char *entry_rich_label = NULL; ozone_node_t *node = NULL;
bool entry_selected = false; const char *entry_rich_label = NULL;
int text_offset = -ozone->dimensions.entry_icon_padding - ozone->dimensions.entry_icon_size; const char *entry_value = NULL;
float *icon_color = NULL; bool entry_selected = false;
int text_offset = -ozone->dimensions.entry_icon_padding - ozone->dimensions.entry_icon_size;
float *icon_color = NULL;
/* Initial ticker configuration */ /* Initial ticker configuration */
ticker.type_enum = (enum menu_animation_ticker_type)settings->uints.menu_ticker_type; ticker.type_enum = (enum menu_animation_ticker_type)settings->uints.menu_ticker_type;
ticker.spacer = ticker_spacer; ticker.spacer = ticker_spacer;
entry_value[0] = '\0';
entry_selected = selection == i; entry_selected = selection == i;
node = (ozone_node_t*) file_list_get_userdata_at_offset(selection_buf, i); node = (ozone_node_t*) file_list_get_userdata_at_offset(selection_buf, i);
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
menu_entry_get(&entry, 0, (unsigned)i, selection_buf, true); menu_entry_get(&entry, 0, (unsigned)i, selection_buf, true);
menu_entry_get_value(&entry, entry_value, sizeof(entry_value)); menu_entry_get_value(&entry, &entry_value);
if (!node) if (!node)
continue; continue;
@ -498,7 +507,7 @@ border_iterate:
goto icons_iterate; goto icons_iterate;
/* Prepare text */ /* Prepare text */
entry_rich_label = menu_entry_get_rich_label(&entry); menu_entry_get_rich_label(&entry, &entry_rich_label);
ticker.idx = menu_animation_get_ticker_idx(); ticker.idx = menu_animation_get_ticker_idx();
ticker.s = rich_label; ticker.s = rich_label;
@ -515,20 +524,22 @@ border_iterate:
y = video_info_height / 2 - 60; y = video_info_height / 2 - 60;
} }
sublabel_str = menu_entry_get_sublabel(&entry); menu_entry_get_sublabel(&entry, &sublabel_str);
if (node->wrap && sublabel_str) if (node->wrap && !string_is_empty(sublabel_str))
{ {
int sublabel_max_width = video_info_width - int sublabel_max_width = video_info_width -
entry_padding * 2 - ozone->dimensions.entry_icon_padding * 2; entry_padding * 2 - ozone->dimensions.entry_icon_padding * 2;
if (ozone->show_thumbnail_bar) if (ozone->show_thumbnail_bar)
sublabel_max_width -= ozone->dimensions.thumbnail_bar_width; sublabel_max_width -= ozone->dimensions.thumbnail_bar_width;
if (ozone->depth == 1) if (ozone->depth == 1)
sublabel_max_width -= (unsigned) ozone->dimensions.sidebar_width; sublabel_max_width -= (unsigned) ozone->dimensions.sidebar_width;
word_wrap(sublabel_str, sublabel_str, sublabel_max_width / ozone->sublabel_font_glyph_width, false, 0); wrapped_sublabel_str[0] = '\0';
word_wrap(wrapped_sublabel_str, sublabel_str, sublabel_max_width / ozone->sublabel_font_glyph_width, false, 0);
sublabel_str = wrapped_sublabel_str;
} }
/* Icon */ /* Icon */
@ -578,7 +589,7 @@ border_iterate:
/* Draw text */ /* Draw text */
ozone_draw_text(video_info, ozone, rich_label, text_offset + (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_size + ozone->dimensions.entry_icon_padding * 2, ozone_draw_text(video_info, ozone, rich_label, text_offset + (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_size + ozone->dimensions.entry_icon_padding * 2,
y + ozone->dimensions.entry_height / 2 + FONT_SIZE_ENTRIES_LABEL * 3/8 + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_label, COLOR_TEXT_ALPHA(ozone->theme->text_rgba, alpha_uint32), false); y + ozone->dimensions.entry_height / 2 + FONT_SIZE_ENTRIES_LABEL * 3/8 + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_label, COLOR_TEXT_ALPHA(ozone->theme->text_rgba, alpha_uint32), false);
if (sublabel_str) if (!string_is_empty(sublabel_str))
ozone_draw_text(video_info, ozone, sublabel_str, (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_padding, ozone_draw_text(video_info, ozone, sublabel_str, (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_padding,
y + ozone->dimensions.entry_height + 1 + 5 + FONT_SIZE_ENTRIES_SUBLABEL + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_sublabel, COLOR_TEXT_ALPHA(ozone->theme->text_sublabel_rgba, alpha_uint32), false); y + ozone->dimensions.entry_height + 1 + 5 + FONT_SIZE_ENTRIES_SUBLABEL + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_sublabel, COLOR_TEXT_ALPHA(ozone->theme->text_sublabel_rgba, alpha_uint32), false);
@ -595,14 +606,8 @@ border_iterate:
ozone_draw_entry_value(ozone, video_info, entry_value_ticker, (unsigned) ozone->dimensions.sidebar_width + entry_padding + x_offset + entry_width - ozone->dimensions.entry_icon_padding, ozone_draw_entry_value(ozone, video_info, entry_value_ticker, (unsigned) ozone->dimensions.sidebar_width + entry_padding + x_offset + entry_width - ozone->dimensions.entry_icon_padding,
y + ozone->dimensions.entry_height / 2 + FONT_SIZE_ENTRIES_LABEL * 3/8 + scroll_y, alpha_uint32, &entry); y + ozone->dimensions.entry_height / 2 + FONT_SIZE_ENTRIES_LABEL * 3/8 + scroll_y, alpha_uint32, &entry);
free(entry_rich_label);
if (sublabel_str)
free(sublabel_str);
icons_iterate: icons_iterate:
y += node->height; y += node->height;
menu_entry_free(&entry);
} }
/* Text layer */ /* Text layer */

View File

@ -3389,10 +3389,11 @@ static void rgui_render(void *data, bool is_idle)
for (i = new_start; i < end; i++, y += FONT_HEIGHT_STRIDE) for (i = new_start; i < end; i++, y += FONT_HEIGHT_STRIDE)
{ {
char entry_value[255];
char entry_title_buf[255]; char entry_title_buf[255];
char type_str_buf[255]; char type_str_buf[255];
menu_entry_t entry; menu_entry_t entry;
const char *entry_label = NULL;
const char *entry_value = NULL;
size_t entry_title_max_len = 0; size_t entry_title_max_len = 0;
unsigned entry_value_len = 0; unsigned entry_value_len = 0;
bool entry_selected = (i == selection); bool entry_selected = (i == selection);
@ -3402,19 +3403,19 @@ static void rgui_render(void *data, bool is_idle)
if (i > (selection + 100)) if (i > (selection + 100))
continue; continue;
entry_value[0] = '\0';
entry_title_buf[0] = '\0'; entry_title_buf[0] = '\0';
type_str_buf[0] = '\0'; type_str_buf[0] = '\0';
/* Get current entry */ /* Get current entry */
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, (unsigned)i, NULL, true); menu_entry_get(&entry, 0, (unsigned)i, NULL, true);
/* Read entry parameters /* Read entry parameters */
* Note: can use entry.path/entry.rich_label directly, menu_entry_get_rich_label(&entry, &entry_label);
* but have to use menu_entry_get_value() for the value menu_entry_get_value(&entry, &entry_value);
* since this function handles password entries... */
menu_entry_get_value(&entry, entry_value, sizeof(entry_value));
/* Get base length of entry title field */ /* Get base length of entry title field */
entry_title_max_len = RGUI_TERM_WIDTH(fb_width) - (1 + 2); entry_title_max_len = RGUI_TERM_WIDTH(fb_width) - (1 + 2);
@ -3478,7 +3479,7 @@ static void rgui_render(void *data, bool is_idle)
/* Format entry title string */ /* Format entry title string */
ticker.s = entry_title_buf; ticker.s = entry_title_buf;
ticker.len = entry_title_max_len; ticker.len = entry_title_max_len;
ticker.str = string_is_empty(entry.rich_label) ? entry.path : entry.rich_label; ticker.str = entry_label;
ticker.selected = entry_selected; ticker.selected = entry_selected;
menu_animation_ticker(&ticker); menu_animation_ticker(&ticker);
@ -3508,8 +3509,6 @@ static void rgui_render(void *data, bool is_idle)
if (entry_selected) if (entry_selected)
blit_line(fb_width, x, y, ">", blit_line(fb_width, x, y, ">",
entry_color, rgui->colors.shadow_color); entry_color, rgui->colors.shadow_color);
menu_entry_free(&entry);
} }
/* Draw mini thumbnails, if required */ /* Draw mini thumbnails, if required */
@ -4351,10 +4350,18 @@ static void rgui_update_menu_sublabel(rgui_t *rgui)
if (settings->bools.menu_show_sublabels && selection < menu_entries_get_size()) if (settings->bools.menu_show_sublabels && selection < menu_entries_get_size())
{ {
menu_entry_t entry; menu_entry_t entry;
const char *sublabel = NULL;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
menu_entry_get(&entry, 0, (unsigned)selection, NULL, true); menu_entry_get(&entry, 0, (unsigned)selection, NULL, true);
if (!string_is_empty(entry.sublabel)) menu_entry_get_sublabel(&entry, &sublabel);
if (!string_is_empty(sublabel))
{ {
static const char* const sublabel_spacer = RGUI_TICKER_SPACER; static const char* const sublabel_spacer = RGUI_TICKER_SPACER;
struct string_list *list = NULL; struct string_list *list = NULL;
@ -4364,7 +4371,7 @@ static void rgui_update_menu_sublabel(rgui_t *rgui)
/* Sanitise sublabel /* Sanitise sublabel
* > Replace newline characters with standard delimiter * > Replace newline characters with standard delimiter
* > Remove whitespace surrounding each sublabel line */ * > Remove whitespace surrounding each sublabel line */
list = string_split(entry.sublabel, "\n"); list = string_split(sublabel, "\n");
if (list) if (list)
{ {
for (line_index = 0; line_index < list->size; line_index++) for (line_index = 0; line_index < list->size; line_index++)
@ -4382,8 +4389,6 @@ static void rgui_update_menu_sublabel(rgui_t *rgui)
string_list_free(list); string_list_free(list);
} }
} }
menu_entry_free(&entry);
} }
} }

View File

@ -863,11 +863,10 @@ static void stripes_update_thumbnail_path(void *data, unsigned i, char pos)
playlist_t *playlist = NULL; playlist_t *playlist = NULL;
const char *dir_thumbnails = settings->paths.directory_thumbnails; const char *dir_thumbnails = settings->paths.directory_thumbnails;
menu_entry_init(&entry);
if (!stripes || string_is_empty(dir_thumbnails)) if (!stripes || string_is_empty(dir_thumbnails))
goto end; goto end;
menu_entry_init(&entry);
menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get(&entry, 0, i, NULL, true);
entry_type = menu_entry_get_type_new(&entry); entry_type = menu_entry_get_type_new(&entry);
@ -996,8 +995,6 @@ end:
if (pos == 'L') if (pos == 'L')
stripes->left_thumbnail_file_path = strdup(new_path); stripes->left_thumbnail_file_path = strdup(new_path);
} }
menu_entry_free(&entry);
} }
static void stripes_update_savestate_thumbnail_path(void *data, unsigned i) static void stripes_update_savestate_thumbnail_path(void *data, unsigned i)
@ -1055,8 +1052,6 @@ static void stripes_update_savestate_thumbnail_path(void *data, unsigned i)
free(path); free(path);
} }
} }
menu_entry_free(&entry);
} }
static void stripes_update_thumbnail_image(void *data) static void stripes_update_thumbnail_image(void *data)
@ -1180,7 +1175,7 @@ static void stripes_selection_pointer_changed(
menu_entry_init(&entry); menu_entry_init(&entry);
if (!stripes) if (!stripes)
goto end; return;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
@ -1244,9 +1239,6 @@ static void stripes_selection_pointer_changed(
menu_animation_push(&anim_entry); menu_animation_push(&anim_entry);
} }
} }
end:
menu_entry_free(&entry);
} }
static void stripes_list_open_old(stripes_handle_t *stripes, static void stripes_list_open_old(stripes_handle_t *stripes,
@ -1749,8 +1741,6 @@ static void stripes_list_switch(stripes_handle_t *stripes)
if (!string_is_empty(entry.path)) if (!string_is_empty(entry.path))
stripes_set_thumbnail_content(stripes, entry.path, 0 /* will be ignored */); stripes_set_thumbnail_content(stripes, entry.path, 0 /* will be ignored */);
menu_entry_free(&entry);
stripes_update_thumbnail_path(stripes, 0, 'R'); stripes_update_thumbnail_path(stripes, 0, 'R');
stripes_update_thumbnail_image(stripes); stripes_update_thumbnail_image(stripes);
} }
@ -1765,8 +1755,6 @@ static void stripes_list_switch(stripes_handle_t *stripes)
if (!string_is_empty(entry.path)) if (!string_is_empty(entry.path))
stripes_set_thumbnail_content(stripes, entry.path, 0 /* will be ignored */); stripes_set_thumbnail_content(stripes, entry.path, 0 /* will be ignored */);
menu_entry_free(&entry);
stripes_update_thumbnail_path(stripes, 0, 'L'); stripes_update_thumbnail_path(stripes, 0, 'L');
stripes_update_thumbnail_image(stripes); stripes_update_thumbnail_image(stripes);
} }
@ -2350,7 +2338,7 @@ static int stripes_draw_item(
float icon_x, icon_y, label_offset; float icon_x, icon_y, label_offset;
menu_animation_ctx_ticker_t ticker; menu_animation_ctx_ticker_t ticker;
char tmp[255]; char tmp[255];
char *ticker_str = NULL; const char *ticker_str = NULL;
unsigned entry_type = 0; unsigned entry_type = 0;
const float half_size = stripes->icon_size / 2.0f; const float half_size = stripes->icon_size / 2.0f;
uintptr_t texture_switch = 0; uintptr_t texture_switch = 0;
@ -2467,7 +2455,7 @@ static int stripes_draw_item(
} }
if (!string_is_empty(entry->path)) if (!string_is_empty(entry->path))
ticker_str = menu_entry_get_rich_label(entry); menu_entry_get_rich_label(entry, &ticker_str);
ticker.s = tmp; ticker.s = tmp;
ticker.len = ticker_limit; ticker.len = ticker_limit;
@ -2585,13 +2573,9 @@ static int stripes_draw_item(
stripes->shadow_offset); stripes->shadow_offset);
iterate: iterate:
if (!string_is_empty(ticker_str))
free(ticker_str);
return 0; return 0;
end: end:
if (!string_is_empty(ticker_str))
free(ticker_str);
return -1; return -1;
} }
@ -2662,7 +2646,6 @@ static void stripes_draw_items(
list, color, thumb_ident, left_thumb_ident, list, color, thumb_ident, left_thumb_ident,
i, current, i, current,
width, height); width, height);
menu_entry_free(&entry);
if (ret == -1) if (ret == -1)
break; break;
} }

View File

@ -955,6 +955,10 @@ static void xmb_update_savestate_thumbnail_path(void *data, unsigned i)
return; return;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.path_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get(&entry, 0, i, NULL, true);
if (!string_is_empty(xmb->savestate_thumbnail_file_path)) if (!string_is_empty(xmb->savestate_thumbnail_file_path))
@ -1000,8 +1004,6 @@ static void xmb_update_savestate_thumbnail_path(void *data, unsigned i)
free(path); free(path);
} }
} }
menu_entry_free(&entry);
} }
static void xmb_update_thumbnail_image(void *data) static void xmb_update_thumbnail_image(void *data)
@ -1184,12 +1186,14 @@ static void xmb_set_thumbnail_content(void *data, const char *s)
menu_entry_t entry; menu_entry_t entry;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
if (!string_is_empty(entry.path)) if (!string_is_empty(entry.path))
menu_thumbnail_set_content(xmb->thumbnail_path_data, entry.path); menu_thumbnail_set_content(xmb->thumbnail_path_data, entry.path);
menu_entry_free(&entry);
} }
} }
else if (string_is_equal(s, "imageviewer")) else if (string_is_equal(s, "imageviewer"))
@ -1200,13 +1204,15 @@ static void xmb_set_thumbnail_content(void *data, const char *s)
xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(selection_buf, selection); xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(selection_buf, selection);
menu_entry_init(&entry); menu_entry_init(&entry);
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
if (node) if (node)
if (!string_is_empty(entry.path) && !string_is_empty(node->fullpath)) if (!string_is_empty(entry.path) && !string_is_empty(node->fullpath))
menu_thumbnail_set_content_image(xmb->thumbnail_path_data, node->fullpath, entry.path); menu_thumbnail_set_content_image(xmb->thumbnail_path_data, node->fullpath, entry.path);
menu_entry_free(&entry);
} }
else if (!string_is_empty(s)) else if (!string_is_empty(s))
{ {
@ -1246,12 +1252,17 @@ static void xmb_selection_pointer_changed(
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
size_t selection = menu_navigation_get_selection(); size_t selection = menu_navigation_get_selection();
menu_entries_ctl(MENU_ENTRIES_CTL_LIST_GET, &menu_list);
menu_entry_init(&entry);
if (!xmb) if (!xmb)
goto end; return;
menu_entries_ctl(MENU_ENTRIES_CTL_LIST_GET, &menu_list);
menu_entry_init(&entry);
entry.path_enabled = false;
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, true); menu_entry_get(&entry, 0, selection, NULL, true);
end = (unsigned)menu_entries_get_size(); end = (unsigned)menu_entries_get_size();
@ -1377,9 +1388,6 @@ static void xmb_selection_pointer_changed(
menu_animation_push(&anim_entry); menu_animation_push(&anim_entry);
} }
} }
end:
menu_entry_free(&entry);
} }
static void xmb_list_open_old(xmb_handle_t *xmb, static void xmb_list_open_old(xmb_handle_t *xmb,
@ -2832,7 +2840,7 @@ static int xmb_draw_item(
float icon_x, icon_y, label_offset; float icon_x, icon_y, label_offset;
menu_animation_ctx_ticker_t ticker; menu_animation_ctx_ticker_t ticker;
char tmp[255]; char tmp[255];
char *ticker_str = NULL; const char *ticker_str = NULL;
unsigned entry_type = 0; unsigned entry_type = 0;
const float half_size = xmb->icon_size / 2.0f; const float half_size = xmb->icon_size / 2.0f;
uintptr_t texture_switch = 0; uintptr_t texture_switch = 0;
@ -2876,11 +2884,7 @@ static int xmb_draw_item(
sizeof(entry_path)); sizeof(entry_path));
if (!string_is_empty(entry_path)) if (!string_is_empty(entry_path))
{ strlcpy(entry->path, entry_path, sizeof(entry->path));
if (!string_is_empty(entry->path))
free(entry->path);
entry->path = strdup(entry_path);
}
} }
if (string_is_equal(entry->value, if (string_is_equal(entry->value,
@ -2948,7 +2952,7 @@ static int xmb_draw_item(
} }
if (!string_is_empty(entry->path)) if (!string_is_empty(entry->path))
ticker_str = menu_entry_get_rich_label(entry); menu_entry_get_rich_label(entry, &ticker_str);
ticker.s = tmp; ticker.s = tmp;
ticker.len = ticker_limit; ticker.len = ticker_limit;
@ -2997,8 +3001,8 @@ static int xmb_draw_item(
if (!string_is_empty(entry->value)) if (!string_is_empty(entry->value))
{ {
char entry_value[255]; const char *entry_value = NULL;
menu_entry_get_value(entry, entry_value, sizeof(entry_value)); menu_entry_get_value(entry, &entry_value);
ticker.str = entry_value; ticker.str = entry_value;
menu_animation_ticker(&ticker); menu_animation_ticker(&ticker);
@ -3079,8 +3083,6 @@ static int xmb_draw_item(
&color[0], &color[0],
xmb->shadow_offset); xmb->shadow_offset);
if (!string_is_empty(ticker_str))
free(ticker_str);
return 0; return 0;
} }
@ -3141,6 +3143,9 @@ static void xmb_draw_items(
int ret; int ret;
menu_entry_t entry; menu_entry_t entry;
menu_entry_init(&entry); menu_entry_init(&entry);
entry.label_enabled = false;
entry.rich_label_enabled = false;
entry.sublabel_enabled = (i == current);
menu_entry_get(&entry, 0, i, list, true); menu_entry_get(&entry, 0, i, list, true);
ret = xmb_draw_item(video_info, ret = xmb_draw_item(video_info,
&entry, &entry,
@ -3149,7 +3154,6 @@ static void xmb_draw_items(
list, color, list, color,
i, current, i, current,
width, height); width, height);
menu_entry_free(&entry);
if (ret == -1) if (ret == -1)
break; break;
} }

View File

@ -584,24 +584,20 @@ static void xui_render(void *data, bool is_idle)
for (i = 0; i < end; i++) for (i = 0; i < end; i++)
{ {
menu_entry_t entry; menu_entry_t entry;
char *entry_path = NULL; const char *entry_path = NULL;
char entry_value[PATH_MAX_LENGTH] = {0}; const char *entry_value = NULL;
wchar_t msg_right[PATH_MAX_LENGTH] = {0}; wchar_t msg_right[PATH_MAX_LENGTH] = {0};
wchar_t msg_left[PATH_MAX_LENGTH] = {0}; wchar_t msg_left[PATH_MAX_LENGTH] = {0};
menu_entry_init(&entry); menu_entry_init(&entry);
menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get(&entry, 0, i, NULL, true);
menu_entry_get_value(&entry, entry_value, sizeof(entry_value)); menu_entry_get_value(&entry, &entry_value);
entry_path = menu_entry_get_path(&entry); menu_entry_get_path(&entry, &entry_path);
mbstowcs(msg_left, entry_path, sizeof(msg_left) / sizeof(wchar_t)); mbstowcs(msg_left, entry_path, sizeof(msg_left) / sizeof(wchar_t));
mbstowcs(msg_right, entry_value, sizeof(msg_right) / sizeof(wchar_t)); mbstowcs(msg_right, entry_value, sizeof(msg_right) / sizeof(wchar_t));
xui_set_list_text(i, msg_left, msg_right); xui_set_list_text(i, msg_left, msg_right);
menu_entry_free(&entry);
if (!string_is_empty(entry_path))
free(entry_path);
} }
selection = menu_navigation_get_selection(); selection = menu_navigation_get_selection();

View File

@ -109,84 +109,59 @@ enum menu_entry_type menu_entry_get_type(uint32_t i)
return MENU_ENTRY_ACTION; return MENU_ENTRY_ACTION;
} }
void menu_entry_free(menu_entry_t *entry)
{
if (!entry)
return;
if (!string_is_empty(entry->label))
free(entry->label);
if (!string_is_empty(entry->rich_label))
free(entry->rich_label);
if (!string_is_empty(entry->sublabel))
free(entry->sublabel);
if (!string_is_empty(entry->path))
free(entry->path);
if (!string_is_empty(entry->value))
free(entry->value);
entry->path = NULL;
entry->label = NULL;
entry->value = NULL;
entry->sublabel = NULL;
entry->rich_label = NULL;
}
void menu_entry_init(menu_entry_t *entry) void menu_entry_init(menu_entry_t *entry)
{ {
entry->path = NULL; entry->path[0] = '\0';
entry->label = NULL; entry->label[0] = '\0';
entry->value = NULL; entry->sublabel[0] = '\0';
entry->sublabel = NULL; entry->rich_label[0] = '\0';
entry->rich_label = NULL; entry->value[0] = '\0';
entry->enum_idx = MSG_UNKNOWN; entry->password_value[0] = '\0';
entry->entry_idx = 0; entry->enum_idx = MSG_UNKNOWN;
entry->idx = 0; entry->entry_idx = 0;
entry->type = 0; entry->idx = 0;
entry->spacing = 0; entry->type = 0;
entry->spacing = 0;
entry->path_enabled = true;
entry->label_enabled = true;
entry->rich_label_enabled = true;
entry->value_enabled = true;
entry->sublabel_enabled = true;
} }
char *menu_entry_get_path(menu_entry_t *entry) void menu_entry_get_path(menu_entry_t *entry, const char **path)
{ {
if (!entry || string_is_empty(entry->path)) if (!entry || !path)
return NULL; return;
return strdup(entry->path);
*path = entry->path;
} }
/* void menu_entry_get_rich_label(menu_entry_t *entry, const char **rich_label)
* Return Value
*
* The function returns a heap-allocated string if
* successful. It's the callee's responsibility to
* free this.
*/
char *menu_entry_get_rich_label(menu_entry_t *entry)
{ {
if (!entry) if (!entry || !rich_label)
return NULL; return;
if (!string_is_empty(entry->rich_label)) if (!string_is_empty(entry->rich_label))
return strdup(entry->rich_label); *rich_label = entry->rich_label;
if (!string_is_empty(entry->path)) else
return strdup(entry->path); *rich_label = entry->path;
return NULL;
} }
/* void menu_entry_get_sublabel(menu_entry_t *entry, const char **sublabel)
* Return Value
*
* The function returns a heap-allocated string if
* successful. It's the callee's responsibility to
* free this.
*/
char *menu_entry_get_sublabel(menu_entry_t *entry)
{ {
if (!entry || string_is_empty(entry->sublabel)) if (!entry || !sublabel)
return NULL; return;
return strdup(entry->sublabel);
*sublabel = entry->sublabel;
} }
void menu_entry_get_label(menu_entry_t *entry, char *s, size_t len) void menu_entry_get_label(menu_entry_t *entry, const char **label)
{ {
if (entry && !string_is_empty(entry->label)) if (!entry || !label)
strlcpy(s, entry->label, len); return;
*label = entry->label;
} }
unsigned menu_entry_get_spacing(menu_entry_t *entry) unsigned menu_entry_get_spacing(menu_entry_t *entry)
@ -339,20 +314,15 @@ void menu_entry_reset(uint32_t i)
menu_entry_action(&entry, i, MENU_ACTION_START); menu_entry_action(&entry, i, MENU_ACTION_START);
} }
void menu_entry_get_value(menu_entry_t *entry, char *s, size_t len) void menu_entry_get_value(menu_entry_t *entry, const char **value)
{ {
size_t size, i; if (!entry || !value)
if (!entry || string_is_empty(entry->value))
return; return;
size = strlcpy(s, entry->value, len);
if (menu_entry_is_password(entry)) if (menu_entry_is_password(entry))
{ *value = entry->password_value;
for (i = 0; i < size; i++) else
s[i] = '*'; *value = entry->value;
}
} }
void menu_entry_set_value(uint32_t i, const char *s) void menu_entry_set_value(uint32_t i, const char *s)
@ -409,6 +379,7 @@ void menu_entry_get(menu_entry_t *entry, size_t stack_idx,
menu_file_list_cbs_t *cbs = NULL; menu_file_list_cbs_t *cbs = NULL;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(stack_idx); file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(stack_idx);
file_list_t *list = (userdata) ? (file_list_t*)userdata : selection_buf; file_list_t *list = (userdata) ? (file_list_t*)userdata : selection_buf;
bool path_enabled = entry->path_enabled;
newpath[0] = '\0'; newpath[0] = '\0';
@ -421,8 +392,8 @@ void menu_entry_get(menu_entry_t *entry, size_t stack_idx,
cbs = (menu_file_list_cbs_t*)list->list[i].actiondata; cbs = (menu_file_list_cbs_t*)list->list[i].actiondata;
entry->idx = (unsigned)i; entry->idx = (unsigned)i;
if (!string_is_empty(entry_label)) if (entry->label_enabled && !string_is_empty(entry_label))
entry->label = strdup(entry_label); strlcpy(entry->label, entry_label, sizeof(entry->label));
if (cbs) if (cbs)
{ {
@ -433,79 +404,85 @@ void menu_entry_get(menu_entry_t *entry, size_t stack_idx,
menu_entries_get_last_stack(NULL, &label, NULL, NULL, NULL); menu_entries_get_last_stack(NULL, &label, NULL, NULL, NULL);
if (cbs->action_get_value && use_representation) if (entry->rich_label_enabled && cbs->action_label)
{ {
char tmp[255];
tmp[0] = '\0';
cbs->action_get_value(list,
&entry->spacing, entry->type,
(unsigned)i, label,
tmp,
sizeof(tmp),
path,
newpath,
sizeof(newpath)
);
if (!string_is_empty(tmp))
entry->value = strdup(tmp);
}
if (cbs->action_label)
{
char tmp[255];
tmp[0] = '\0';
cbs->action_label(list, cbs->action_label(list,
entry->type, (unsigned)i, entry->type, (unsigned)i,
label, path, label, path,
tmp, entry->rich_label,
sizeof(tmp)); sizeof(entry->rich_label));
if (!string_is_empty(tmp)) if (string_is_empty(entry->rich_label))
entry->rich_label = strdup(tmp); path_enabled = true;
} }
if (cbs->action_sublabel) if ((path_enabled || entry->value_enabled) &&
cbs->action_get_value &&
use_representation)
{ {
char tmp[512]; cbs->action_get_value(list,
tmp[0] = '\0'; &entry->spacing, entry->type,
(unsigned)i, label,
entry->value,
entry->value_enabled ? sizeof(entry->value) : 0,
path,
newpath,
path_enabled ? sizeof(newpath) : 0);
if (!string_is_empty(cbs->action_sublabel_cache)) if (!string_is_empty(entry->value))
entry->sublabel = strdup(cbs->action_sublabel_cache);
else
{ {
if (menu_entry_is_password(entry))
{
size_t size, i;
size = strlcpy(entry->password_value, entry->value,
sizeof(entry->password_value));
for (i = 0; i < size; i++)
entry->password_value[i] = '*';
}
}
}
if (entry->sublabel_enabled)
{
if (!string_is_empty(cbs->action_sublabel_cache))
strlcpy(entry->sublabel,
cbs->action_sublabel_cache, sizeof(entry->sublabel));
else if (cbs->action_sublabel)
{
char tmp[512];
tmp[0] = '\0';
if (cbs->action_sublabel(list, if (cbs->action_sublabel(list,
entry->type, (unsigned)i, entry->type, (unsigned)i,
label, path, label, path,
tmp, tmp,
sizeof(tmp))) sizeof(tmp)) > 0)
{ {
/* if this function callback returns true, /* If this function callback returns true,
* we know that the value won't change - so we * we know that the value won't change - so we
* can cache it instead. */ * can cache it instead. */
strlcpy(cbs->action_sublabel_cache, strlcpy(cbs->action_sublabel_cache,
tmp, sizeof(cbs->action_sublabel_cache)); tmp, sizeof(cbs->action_sublabel_cache));
} }
if (!string_is_empty(tmp)) strlcpy(entry->sublabel, tmp, sizeof(entry->sublabel));
entry->sublabel = strdup(tmp);
} }
} }
} }
if (!string_is_empty(path) && !use_representation) if (path_enabled)
strlcpy(newpath, path, sizeof(newpath)); {
else if (cbs && cbs->setting && cbs->setting->enum_value_idx != MSG_UNKNOWN if (!string_is_empty(path) && !use_representation)
&& !cbs->setting->dont_use_enum_idx_representation) strlcpy(newpath, path, sizeof(newpath));
strlcpy(newpath, else if (cbs && cbs->setting && cbs->setting->enum_value_idx != MSG_UNKNOWN
msg_hash_to_str(cbs->setting->enum_value_idx), && !cbs->setting->dont_use_enum_idx_representation)
sizeof(newpath)); strlcpy(newpath,
msg_hash_to_str(cbs->setting->enum_value_idx),
if (!string_is_empty(newpath)) sizeof(newpath));
entry->path = strdup(newpath);
if (!string_is_empty(newpath))
strlcpy(entry->path, newpath, sizeof(entry->path));
}
} }
bool menu_entry_is_currently_selected(unsigned id) bool menu_entry_is_currently_selected(unsigned id)

View File

@ -208,19 +208,25 @@ typedef struct menu_entry
unsigned type; unsigned type;
unsigned spacing; unsigned spacing;
size_t entry_idx; size_t entry_idx;
char *path; char path[255];
char *label; char label[255];
char *sublabel; char sublabel[512];
char *rich_label; char rich_label[255];
char *value; char value[255];
char password_value[255];
bool checked; bool checked;
bool path_enabled;
bool label_enabled;
bool rich_label_enabled;
bool value_enabled;
bool sublabel_enabled;
} menu_entry_t; } menu_entry_t;
enum menu_entry_type menu_entry_get_type(uint32_t i); enum menu_entry_type menu_entry_get_type(uint32_t i);
char *menu_entry_get_path(menu_entry_t *entry); void menu_entry_get_path(menu_entry_t *entry, const char **path);
void menu_entry_get_label(menu_entry_t *entry, char *s, size_t len); void menu_entry_get_label(menu_entry_t *entry, const char **label);
unsigned menu_entry_get_spacing(menu_entry_t *entry); unsigned menu_entry_get_spacing(menu_entry_t *entry);
@ -250,11 +256,11 @@ void menu_entry_pathdir_extensions(uint32_t i, char *s, size_t len);
void menu_entry_reset(uint32_t i); void menu_entry_reset(uint32_t i);
char *menu_entry_get_rich_label(menu_entry_t *entry); void menu_entry_get_rich_label(menu_entry_t *entry, const char **rich_label);
char *menu_entry_get_sublabel(menu_entry_t *entry); void menu_entry_get_sublabel(menu_entry_t *entry, const char **sublabel);
void menu_entry_get_value(menu_entry_t *entry, char *s, size_t len); void menu_entry_get_value(menu_entry_t *entry, const char **value);
void menu_entry_set_value(uint32_t i, const char *s); void menu_entry_set_value(uint32_t i, const char *s);
@ -276,8 +282,6 @@ int menu_entry_select(uint32_t i);
int menu_entry_action(menu_entry_t *entry, int menu_entry_action(menu_entry_t *entry,
unsigned i, enum menu_action action); unsigned i, enum menu_action action);
void menu_entry_free(menu_entry_t *entry);
void menu_entry_init(menu_entry_t *entry); void menu_entry_init(menu_entry_t *entry);
RETRO_END_DECLS RETRO_END_DECLS

View File

@ -882,12 +882,17 @@ void menu_input_post_iterate(int *ret, unsigned action)
: NULL; : NULL;
menu_entry_init(&entry); menu_entry_init(&entry);
/* Note: If menu_input_mouse_frame() or
* menu_input_pointer_post_iterate() are
* modified, will have to verify that these
* parameters remain unused... */
entry.rich_label_enabled = false;
entry.value_enabled = false;
entry.sublabel_enabled = false;
menu_entry_get(&entry, 0, selection, NULL, false); menu_entry_get(&entry, 0, selection, NULL, false);
*ret = menu_input_mouse_frame(cbs, &entry, action); *ret = menu_input_mouse_frame(cbs, &entry, action);
if (settings->bools.menu_pointer_enable) if (settings->bools.menu_pointer_enable)
*ret |= menu_input_pointer_post_iterate(cbs, &entry, action); *ret |= menu_input_pointer_post_iterate(cbs, &entry, action);
menu_entry_free(&entry);
} }

View File

@ -258,6 +258,10 @@ bool menu_thumbnail_set_content(menu_thumbnail_path_data_t *path_data, const cha
/* Determine content image name */ /* Determine content image name */
fill_content_img(path_data); fill_content_img(path_data);
/* Have to set content path to *something*...
* Just use label value (it doesn't matter) */
strlcpy(path_data->content_path, label, sizeof(path_data->content_path));
/* Redundant error check... */ /* Redundant error check... */
if (string_is_empty(path_data->content_img)) if (string_is_empty(path_data->content_img))
return false; return false;

View File

@ -113,7 +113,7 @@ static void RunActionSheet(const char* title, const struct string_list* items,
{ {
menu_entry_t entry; menu_entry_t entry;
char buffer[PATH_MAX_LENGTH]; char buffer[PATH_MAX_LENGTH];
char *label = NULL; const char *label = NULL;
static NSString* const cell_id = @"text"; static NSString* const cell_id = @"text";
self.parentTable = tableView; self.parentTable = tableView;
@ -125,7 +125,7 @@ static void RunActionSheet(const char* title, const struct string_list* items,
menu_entry_init(&entry); menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true); menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
label = menu_entry_get_path(&entry); menu_entry_get_path(&entry, &label);
menu_entry_get_value(&entry, buffer, sizeof(buffer)); menu_entry_get_value(&entry, buffer, sizeof(buffer));
if (string_is_empty(label)) if (string_is_empty(label))
@ -137,10 +137,6 @@ static void RunActionSheet(const char* title, const struct string_list* items,
result.textLabel.text = BOXSTRING(label); result.textLabel.text = BOXSTRING(label);
result.detailTextLabel.text = BOXSTRING(buffer); result.detailTextLabel.text = BOXSTRING(buffer);
menu_entry_free(&entry);
if (!string_is_empty(label))
free(label);
return result; return result;
} }
@ -158,7 +154,7 @@ static void RunActionSheet(const char* title, const struct string_list* items,
- (UITableViewCell*)cellForTableView:(UITableView*)tableView - (UITableViewCell*)cellForTableView:(UITableView*)tableView
{ {
menu_entry_t entry; menu_entry_t entry;
char *label = NULL; const char *label = NULL;
static NSString* const cell_id = @"boolean_setting"; static NSString* const cell_id = @"boolean_setting";
UITableViewCell* result = UITableViewCell* result =
@ -175,7 +171,7 @@ static void RunActionSheet(const char* title, const struct string_list* items,
menu_entry_init(&entry); menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true); menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
label = menu_entry_get_path(&entry); menu_entry_get_path(&entry, &label);
if (!string_is_empty(label)) if (!string_is_empty(label))
result.textLabel.text = BOXSTRING(label); result.textLabel.text = BOXSTRING(label);
@ -187,9 +183,6 @@ static void RunActionSheet(const char* title, const struct string_list* items,
action:@selector(handleBooleanSwitch:) action:@selector(handleBooleanSwitch:)
forControlEvents:UIControlEventValueChanged]; forControlEvents:UIControlEventValueChanged];
[(id)result.accessoryView setOn:(menu_entry_get_bool_value(self.i))]; [(id)result.accessoryView setOn:(menu_entry_get_bool_value(self.i))];
menu_entry_free(&entry);
if (!string_is_empty(label))
free(label);
return result; return result;
} }
@ -226,12 +219,12 @@ static void RunActionSheet(const char* title, const struct string_list* items,
{ {
menu_entry_t entry; menu_entry_t entry;
struct string_list* items = NULL; struct string_list* items = NULL;
char *label = NULL; const char *label = NULL;
RAMenuItemEnum __weak* weakSelf = self; RAMenuItemEnum __weak* weakSelf = self;
menu_entry_init(&entry); menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true); menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
label = menu_entry_get_path(&entry); menu_entry_get_path(&entry, &label);
items = menu_entry_enum_values(self.i); items = menu_entry_enum_values(self.i);
if (!string_is_empty(label)) if (!string_is_empty(label))
@ -248,9 +241,6 @@ static void RunActionSheet(const char* title, const struct string_list* items,
}); });
} }
string_list_free(items); string_list_free(items);
menu_entry_free(&entry);
if (!string_is_empty(label))
free(label);
} }
@end @end
@ -265,11 +255,11 @@ static void RunActionSheet(const char* title, const struct string_list* items,
ofController:(UIViewController *)controller ofController:(UIViewController *)controller
{ {
menu_entry_t entry; menu_entry_t entry;
char *label = NULL; const char *label = NULL;
menu_entry_init(&entry); menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true); menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
label = menu_entry_get_path(&entry); menu_entry_get_path(&entry, &label);
self.alert = [[UIAlertView alloc] self.alert = [[UIAlertView alloc]
@ -290,9 +280,6 @@ static void RunActionSheet(const char* title, const struct string_list* items,
selector:@selector(checkBind:) selector:@selector(checkBind:)
userInfo:nil userInfo:nil
repeats:YES]; repeats:YES];
menu_entry_free(&entry);
if (!string_is_empty(label))
free(label);
} }
- (void)finishWithClickedButton:(bool)clicked - (void)finishWithClickedButton:(bool)clicked
@ -444,14 +431,14 @@ replacementString:(NSString *)string
{ {
menu_entry_t entry; menu_entry_t entry;
char buffer[PATH_MAX_LENGTH]; char buffer[PATH_MAX_LENGTH];
char *label = NULL; const char *label = NULL;
UIAlertView *alertView = NULL; UIAlertView *alertView = NULL;
UITextField *field = NULL; UITextField *field = NULL;
NSString *desc = NULL; NSString *desc = NULL;
menu_entry_init(&entry); menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true); menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
label = menu_entry_get_path(&entry); menu_entry_get_path(&entry, &label);
desc = BOXSTRING(label); desc = BOXSTRING(label);
@ -474,11 +461,6 @@ replacementString:(NSString *)string
field.placeholder = BOXSTRING(buffer); field.placeholder = BOXSTRING(buffer);
menu_entry_free(&entry);
if (!string_is_empty(label))
free(label);
[alertView show]; [alertView show];
} }