From 2f10fd14d60f24a380a520b9d953e4ddcbfb3798 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 28 Sep 2017 06:02:14 +0200 Subject: [PATCH] Create menu_entry_init/menu_entry_free --- menu/cbs/menu_cbs_select.c | 17 ++-- menu/drivers/menu_generic.c | 35 ++++---- menu/drivers/nuklear.c | 2 + menu/drivers/xmb.c | 159 ++++++++++++++---------------------- menu/drivers/zarch.c | 9 +- menu/menu_input.c | 14 +--- menu/widgets/menu_entry.c | 138 +++++++------------------------ menu/widgets/menu_entry.h | 4 + 8 files changed, 130 insertions(+), 248 deletions(-) diff --git a/menu/cbs/menu_cbs_select.c b/menu/cbs/menu_cbs_select.c index 6c6cb03e44..57f9d12886 100644 --- a/menu/cbs/menu_cbs_select.c +++ b/menu/cbs/menu_cbs_select.c @@ -39,23 +39,16 @@ static int action_select_default(const char *path, const char *label, unsigned t menu_file_list_cbs_t *cbs = NULL; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, idx, NULL, false); cbs = menu_entries_get_actiondata_at_offset(selection_buf, idx); if (!cbs) + { + menu_entry_free(&entry); return -1; + } if (cbs->setting) { @@ -96,6 +89,8 @@ static int action_select_default(const char *path, const char *label, unsigned t if (action != MENU_ACTION_NOOP) ret = menu_entry_action(&entry, (unsigned)idx, action); + menu_entry_free(&entry); + task_queue_check(); return ret; diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index 84672c084d..f8e31738d3 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -66,7 +66,6 @@ static enum action_iterate_type action_iterate_type(uint32_t hash) **/ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) { - menu_entry_t entry; enum action_iterate_type iterate_type; unsigned file_type = 0; int ret = 0; @@ -219,24 +218,28 @@ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) menu_dialog_set_active(false); break; case ITERATE_TYPE_DEFAULT: - /* FIXME: Crappy hack, needed for mouse controls - * to not be completely broken in case we press back. - * - * We need to fix this entire mess, mouse controls - * should not rely on a hack like this in order to work. */ - selection = MAX(MIN(selection, (menu_entries_get_size() - 1)), 0); + { + menu_entry_t entry; + /* FIXME: Crappy hack, needed for mouse controls + * to not be completely broken in case we press back. + * + * We need to fix this entire mess, mouse controls + * should not rely on a hack like this in order to work. */ + selection = MAX(MIN(selection, (menu_entries_get_size() - 1)), 0); - menu_entry_get(&entry, 0, selection, NULL, false); - ret = menu_entry_action(&entry, - (unsigned)selection, (enum menu_action)action); + menu_entry_init(&entry); + menu_entry_get(&entry, 0, selection, NULL, false); + ret = menu_entry_action(&entry, + (unsigned)selection, (enum menu_action)action); + menu_entry_free(&entry); + if (ret) + goto end; - if (ret) - goto end; + BIT64_SET(menu->state, MENU_STATE_POST_ITERATE); - BIT64_SET(menu->state, MENU_STATE_POST_ITERATE); - - /* Have to defer it so we let settings refresh. */ - menu_dialog_push(); + /* Have to defer it so we let settings refresh. */ + menu_dialog_push(); + } break; } diff --git a/menu/drivers/nuklear.c b/menu/drivers/nuklear.c index d863556794..faaaadec9e 100644 --- a/menu/drivers/nuklear.c +++ b/menu/drivers/nuklear.c @@ -501,11 +501,13 @@ static int nk_menu_iterate(void *data, void *userdata, enum menu_action action) if (!nk) return -1; + menu_entry_init(&entry); menu_entry_get(&entry, 0, selection, NULL, false); nk->action = action; ret = menu_entry_action(&entry, selection, action); + menu_entry_free(&entry); if (ret) return -1; return 0; diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 3801be71a8..33b13d50c2 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -984,17 +984,7 @@ static void xmb_update_thumbnail_path(void *data, unsigned i) if (!xmb) goto end; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); if (entry.type == FILE_TYPE_IMAGEVIEWER || entry.type == FILE_TYPE_IMAGE) @@ -1070,6 +1060,7 @@ static void xmb_update_thumbnail_path(void *data, unsigned i) sizeof(xmb->thumbnail_file_path)); end: + menu_entry_free(&entry); free(tmp_new); } @@ -1083,17 +1074,7 @@ static void xmb_update_savestate_thumbnail_path(void *data, unsigned i) if (!xmb) return; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); menu_driver_ctl(RARCH_MENU_CTL_PLAYLIST_GET, &playlist); @@ -1133,6 +1114,8 @@ static void xmb_update_savestate_thumbnail_path(void *data, unsigned i) free(path); } + + menu_entry_free(&entry); } static void xmb_update_thumbnail_image(void *data) @@ -1191,7 +1174,7 @@ static void xmb_update_savestate_thumbnail_image(void *data) static void xmb_selection_pointer_changed( xmb_handle_t *xmb, bool allow_animations) { - menu_entry_t e; + menu_entry_t entry; unsigned i, end, height; menu_animation_ctx_tag tag; size_t num = 0; @@ -1206,18 +1189,8 @@ static void xmb_selection_pointer_changed( if (!xmb) return; - e.path[0] = '\0'; - e.label[0] = '\0'; - e.sublabel[0] = '\0'; - e.value[0] = '\0'; - e.rich_label[0] = '\0'; - e.enum_idx = MSG_UNKNOWN; - e.entry_idx = 0; - e.idx = 0; - e.type = 0; - e.spacing = 0; - - menu_entry_get(&e, 0, selection, NULL, true); + menu_entry_init(&entry); + menu_entry_get(&entry, 0, selection, NULL, true); end = (unsigned)menu_entries_get_end(); threshold = xmb->icon.size*10; @@ -1257,15 +1230,15 @@ static void xmb_selection_pointer_changed( if ((xmb_list > XMB_SYSTEM_TAB_SETTINGS && depth == 1) || (xmb_list < XMB_SYSTEM_TAB_SETTINGS && depth == 4)) { - xmb_set_thumbnail_content(xmb, e.path, sizeof(e.path)); + xmb_set_thumbnail_content(xmb, entry.path, sizeof(entry.path)); xmb_update_thumbnail_path(xmb, i); xmb_update_thumbnail_image(xmb); } - else if (((e.type == FILE_TYPE_IMAGE || e.type == FILE_TYPE_IMAGEVIEWER || - e.type == FILE_TYPE_RDB || e.type == FILE_TYPE_RDB_ENTRY) + else if (((entry.type == FILE_TYPE_IMAGE || entry.type == FILE_TYPE_IMAGEVIEWER || + entry.type == FILE_TYPE_RDB || entry.type == FILE_TYPE_RDB_ENTRY) && xmb_list <= XMB_SYSTEM_TAB_SETTINGS)) { - xmb_set_thumbnail_content(xmb, e.path, sizeof(e.path)); + xmb_set_thumbnail_content(xmb, entry.path, sizeof(entry.path)); xmb_update_thumbnail_path(xmb, i); xmb_update_thumbnail_image(xmb); } @@ -1316,6 +1289,8 @@ static void xmb_selection_pointer_changed( menu_animation_push(&entry); } } + + menu_entry_free(&entry); } static void xmb_list_open_old(xmb_handle_t *xmb, @@ -1354,26 +1329,26 @@ static void xmb_list_open_old(xmb_handle_t *xmb, } else { - menu_animation_ctx_entry_t entry; + menu_animation_ctx_entry_t anim_entry; - entry.duration = XMB_DELAY; - entry.target_value = ia; - entry.subject = &node->alpha; - entry.easing_enum = EASING_OUT_QUAD; - entry.tag = (uintptr_t)list; - entry.cb = NULL; + anim_entry.duration = XMB_DELAY; + anim_entry.target_value = ia; + anim_entry.subject = &node->alpha; + anim_entry.easing_enum = EASING_OUT_QUAD; + anim_entry.tag = (uintptr_t)list; + anim_entry.cb = NULL; - menu_animation_push(&entry); + menu_animation_push(&anim_entry); - entry.target_value = 0; - entry.subject = &node->label_alpha; + anim_entry.target_value = 0; + anim_entry.subject = &node->label_alpha; - menu_animation_push(&entry); + menu_animation_push(&anim_entry); - entry.target_value = xmb->icon.size * dir * -2; - entry.subject = &node->x; + anim_entry.target_value = xmb->icon.size * dir * -2; + anim_entry.subject = &node->x; - menu_animation_push(&entry); + menu_animation_push(&anim_entry); } } } @@ -1424,25 +1399,25 @@ static void xmb_list_open_new(xmb_handle_t *xmb, } else { - menu_animation_ctx_entry_t entry; + menu_animation_ctx_entry_t anim_entry; - entry.duration = XMB_DELAY; - entry.target_value = ia; - entry.subject = &node->alpha; - entry.easing_enum = EASING_OUT_QUAD; - entry.tag = (uintptr_t)list; - entry.cb = NULL; + anim_entry.duration = XMB_DELAY; + anim_entry.target_value = ia; + anim_entry.subject = &node->alpha; + anim_entry.easing_enum = EASING_OUT_QUAD; + anim_entry.tag = (uintptr_t)list; + anim_entry.cb = NULL; - menu_animation_push(&entry); + menu_animation_push(&anim_entry); - entry.subject = &node->label_alpha; + anim_entry.subject = &node->label_alpha; - menu_animation_push(&entry); + menu_animation_push(&anim_entry); - entry.target_value = 0; - entry.subject = &node->x; + anim_entry.target_value = 0; + anim_entry.subject = &node->x; - menu_animation_push(&entry); + menu_animation_push(&anim_entry); } } @@ -1735,8 +1710,7 @@ static void xmb_list_switch_horizontal_list(xmb_handle_t *xmb) static void xmb_list_switch(xmb_handle_t *xmb) { - menu_entry_t e; - menu_animation_ctx_entry_t entry; + menu_animation_ctx_entry_t anim_entry; int dir = -1; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); size_t selection = menu_navigation_get_selection(); @@ -1749,16 +1723,16 @@ static void xmb_list_switch(xmb_handle_t *xmb) xmb_list_switch_horizontal_list(xmb); - entry.duration = XMB_DELAY; - entry.target_value = xmb->icon.spacing.horizontal * -(float)xmb->categories.selection_ptr; - entry.subject = &xmb->categories.x_pos; - entry.easing_enum = EASING_OUT_QUAD; + anim_entry.duration = XMB_DELAY; + anim_entry.target_value = xmb->icon.spacing.horizontal * -(float)xmb->categories.selection_ptr; + anim_entry.subject = &xmb->categories.x_pos; + anim_entry.easing_enum = EASING_OUT_QUAD; /* TODO/FIXME - integer conversion resulted in change of sign */ - entry.tag = -1; - entry.cb = NULL; + anim_entry.tag = -1; + anim_entry.cb = NULL; - if (entry.subject) - menu_animation_push(&entry); + if (anim_entry.subject) + menu_animation_push(&anim_entry); dir = -1; if (xmb->categories.selection_ptr > xmb->categories.selection_ptr_old) @@ -1775,20 +1749,14 @@ static void xmb_list_switch(xmb_handle_t *xmb) if (!string_is_equal(xmb_thumbnails_ident(), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF))) { - e.path[0] = '\0'; - e.label[0] = '\0'; - e.sublabel[0] = '\0'; - e.value[0] = '\0'; - e.rich_label[0] = '\0'; - e.enum_idx = MSG_UNKNOWN; - e.entry_idx = 0; - e.idx = 0; - e.type = 0; - e.spacing = 0; + menu_entry_t entry; - menu_entry_get(&e, 0, selection, NULL, true); + menu_entry_init(&entry); + menu_entry_get(&entry, 0, selection, NULL, true); - xmb_set_thumbnail_content(xmb, e.path, sizeof(e.path)); + xmb_set_thumbnail_content(xmb, entry.path, sizeof(entry.path)); + + menu_entry_free(&entry); xmb_update_thumbnail_path(xmb, 0); xmb_update_thumbnail_image(xmb); @@ -2396,19 +2364,10 @@ static void xmb_draw_items( if (!node) continue; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - ticker_str[0] = tmp[0] = '\0'; + menu_entry_init(&entry); + icon_y = xmb->margins.screen.top + node->y + half_size; if (icon_y < half_size) @@ -2600,6 +2559,8 @@ static void xmb_draw_items( 1, &color[0], xmb->shadow_offset); + + menu_entry_free(&entry); } menu_display_blend_end(); diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index 036d07fb8f..c9326d67bd 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -516,10 +516,11 @@ static int zarch_zui_render_lay_root_recent( { char rich_label[PATH_MAX_LENGTH]; char entry_value[PATH_MAX_LENGTH]; - menu_entry_t entry = {{0}}; + menu_entry_t entry; rich_label[0] = entry_value[0] = '\0'; + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get_rich_label(i, rich_label, sizeof(rich_label)); menu_entry_get_value(i, NULL, entry_value,sizeof(entry_value)); @@ -531,10 +532,14 @@ static int zarch_zui_render_lay_root_recent( rich_label, i, entry_value, gamepad_index == (signed)i)) { if (menu_entry_action(&entry, i, MENU_ACTION_OK)) + { + menu_entry_free(&entry); return 1; + } } j++; + menu_entry_free(&entry); } } @@ -1112,11 +1117,13 @@ static int zarch_iterate(void *data, void *userdata, enum menu_action action) if (!zui) return -1; + menu_entry_init(&entry); menu_entry_get(&entry, 0, selection, NULL, false); zui->action = action; ret = menu_entry_action(&entry, selection, action); + menu_entry_free(&entry); if (ret) return -1; return 0; diff --git a/menu/menu_input.c b/menu/menu_input.c index 0405248a79..4aace7f1eb 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -571,22 +571,14 @@ void menu_input_post_iterate(int *ret, unsigned action) if (selection_buf) cbs = menu_entries_get_actiondata_at_offset(selection_buf, selection); - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, selection, NULL, false); *ret = menu_input_mouse_frame(cbs, &entry, action); if (settings->bools.menu_pointer_enable) *ret |= menu_input_pointer_post_iterate(cbs, &entry, action); + + menu_entry_free(&entry); } diff --git a/menu/widgets/menu_entry.c b/menu/widgets/menu_entry.c index 81f341319f..c69767397f 100644 --- a/menu/widgets/menu_entry.c +++ b/menu/widgets/menu_entry.c @@ -75,21 +75,29 @@ enum menu_entry_type menu_entry_get_type(uint32_t i) return MENU_ENTRY_ACTION; } +void menu_entry_free(menu_entry_t *entry) +{ +} + +void menu_entry_init(menu_entry_t *entry) +{ + entry->path[0] = '\0'; + entry->label[0] = '\0'; + entry->sublabel[0] = '\0'; + entry->value[0] = '\0'; + entry->rich_label[0] = '\0'; + entry->enum_idx = MSG_UNKNOWN; + entry->entry_idx = 0; + entry->idx = 0; + entry->type = 0; + entry->spacing = 0; +} + void menu_entry_get_path(uint32_t i, char *s, size_t len) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); strlcpy(s, entry.path, len); @@ -99,17 +107,7 @@ void menu_entry_get_rich_label(uint32_t i, char *s, size_t len) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); if (!string_is_empty(entry.rich_label)) @@ -122,17 +120,7 @@ bool menu_entry_get_sublabel(uint32_t i, char *s, size_t len) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); if (string_is_empty(entry.sublabel)) @@ -146,17 +134,7 @@ void menu_entry_get_label(uint32_t i, char *s, size_t len) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); strlcpy(s, entry.label, len); @@ -166,17 +144,7 @@ unsigned menu_entry_get_spacing(uint32_t i) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); return entry.spacing; @@ -186,17 +154,7 @@ unsigned menu_entry_get_type_new(uint32_t i) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); return entry.type; @@ -291,17 +249,7 @@ void menu_entry_pathdir_get_value(uint32_t i, char *s, size_t len) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); strlcpy(s, entry.value, len); } @@ -321,17 +269,7 @@ void menu_entry_reset(uint32_t i) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); menu_entry_action(&entry, i, MENU_ACTION_START); @@ -342,17 +280,7 @@ void menu_entry_get_value(uint32_t i, void *data, char *s, size_t len) menu_entry_t entry; file_list_t *list = (file_list_t*)data; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, list, true); strlcpy(s, entry.value, len); } @@ -465,19 +393,9 @@ int menu_entry_select(uint32_t i) { menu_entry_t entry; - entry.path[0] = '\0'; - entry.label[0] = '\0'; - entry.sublabel[0] = '\0'; - entry.value[0] = '\0'; - entry.rich_label[0] = '\0'; - entry.enum_idx = MSG_UNKNOWN; - entry.entry_idx = 0; - entry.idx = 0; - entry.type = 0; - entry.spacing = 0; - menu_navigation_set_selection(i); + menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, false); return menu_entry_action(&entry, i, MENU_ACTION_SELECT); diff --git a/menu/widgets/menu_entry.h b/menu/widgets/menu_entry.h index af8b8b5b8b..57b24ee15c 100644 --- a/menu/widgets/menu_entry.h +++ b/menu/widgets/menu_entry.h @@ -117,6 +117,10 @@ int menu_entry_select(uint32_t i); int menu_entry_action(menu_entry_t *entry, unsigned i, enum menu_action action); +void menu_entry_free(menu_entry_t *entry); + +void menu_entry_init(menu_entry_t *entry); + RETRO_END_DECLS #endif