diff --git a/menu/cbs/menu_cbs_cancel.c b/menu/cbs/menu_cbs_cancel.c index f38d5e7a73..aa0faab289 100644 --- a/menu/cbs/menu_cbs_cancel.c +++ b/menu/cbs/menu_cbs_cancel.c @@ -55,9 +55,9 @@ static int action_cancel_pop_default(const char *path, filebrowser_clear_type(); } - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &new_selection_ptr); + new_selection_ptr = menu_navigation_get_selection(); menu_entries_pop_stack(&new_selection_ptr, 0, 1); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &new_selection_ptr); + menu_navigation_set_selection(new_selection_ptr); menu_driver_ctl(RARCH_MENU_CTL_UPDATE_SAVESTATE_THUMBNAIL_PATH, NULL); menu_driver_ctl(RARCH_MENU_CTL_UPDATE_SAVESTATE_THUMBNAIL_IMAGE, NULL); diff --git a/menu/cbs/menu_cbs_info.c b/menu/cbs/menu_cbs_info.c index 4ba6df94e7..f4d2e708a8 100644 --- a/menu/cbs/menu_cbs_info.c +++ b/menu/cbs/menu_cbs_info.c @@ -29,16 +29,13 @@ static int action_info_default(unsigned type, const char *label) { - size_t selection = 0; menu_displaylist_info_t info = {0}; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); + size_t selection = menu_navigation_get_selection(); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return 0; - - info.list = menu_stack; - info.directory_ptr = selection; - info.enum_idx = MENU_ENUM_LABEL_INFO_SCREEN; + info.list = menu_stack; + info.directory_ptr = selection; + info.enum_idx = MENU_ENUM_LABEL_INFO_SCREEN; strlcpy(info.label, msg_hash_to_str(MENU_ENUM_LABEL_INFO_SCREEN), sizeof(info.label)); diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 39ec13bf63..8502b7639b 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -116,11 +116,10 @@ static int action_left_input_desc(unsigned type, const char *label, static int action_left_scroll(unsigned type, const char *label, bool wraparound) { - size_t selection; size_t scroll_accel = 0; unsigned scroll_speed = 0, fast_scroll_speed = 0; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return menu_cbs_exit(); + size_t selection = menu_navigation_get_selection(); + if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &scroll_accel)) return false; @@ -131,7 +130,7 @@ static int action_left_scroll(unsigned type, const char *label, { size_t idx = selection - fast_scroll_speed; bool scroll = true; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } else @@ -147,7 +146,6 @@ static int action_left_mainmenu(unsigned type, const char *label, bool wraparound) { menu_ctx_list_t list_info; - size_t selection = 0; unsigned push_list = 0; menu_handle_t *menu = NULL; @@ -164,7 +162,8 @@ static int action_left_mainmenu(unsigned type, const char *label, { settings_t *settings = config_get_ptr(); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); + menu_navigation_set_selection(0); + if ((list_info.selection != 0) || settings->menu.navigation.wraparound.enable) push_list = 1; @@ -172,8 +171,6 @@ static int action_left_mainmenu(unsigned type, const char *label, else push_list = 2; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); - switch (push_list) { @@ -182,12 +179,13 @@ static int action_left_mainmenu(unsigned type, const char *label, menu_ctx_list_t list_info; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); + size_t selection = menu_navigation_get_selection(); menu_file_list_cbs_t *cbs = menu_entries_get_actiondata_at_offset(selection_buf, selection); - list_info.type = MENU_LIST_HORIZONTAL; - list_info.action = MENU_ACTION_LEFT; + list_info.type = MENU_LIST_HORIZONTAL; + list_info.action = MENU_ACTION_LEFT; menu_driver_ctl(RARCH_MENU_CTL_LIST_CACHE, &list_info); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index fdd19aa0ac..fbd9c7199c 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1325,7 +1325,6 @@ static int action_ok_playlist_entry_collection(const char *path, menu_content_ctx_playlist_info_t playlist_info; char new_core_path[PATH_MAX_LENGTH]; content_ctx_info_t content_info = {0}; - size_t selection = 0; size_t selection_ptr = 0; bool playlist_initialized = false; playlist_t *playlist = NULL; @@ -1339,8 +1338,6 @@ static int action_ok_playlist_entry_collection(const char *path, if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return menu_cbs_exit(); new_core_path[0] = '\0'; @@ -1452,7 +1449,6 @@ static int action_ok_playlist_entry_collection(const char *path, static int action_ok_playlist_entry(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { - size_t selection; menu_content_ctx_playlist_info_t playlist_info; content_ctx_info_t content_info = {0}; size_t selection_ptr = 0; @@ -1465,8 +1461,6 @@ static int action_ok_playlist_entry(const char *path, if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return menu_cbs_exit(); selection_ptr = entry_idx; @@ -1543,7 +1537,6 @@ static int action_ok_playlist_entry_start_content(const char *path, { menu_content_ctx_playlist_info_t playlist_info; content_ctx_info_t content_info = {0}; - size_t selection = 0; size_t selection_ptr = 0; bool playlist_initialized = false; playlist_t *playlist = NULL; @@ -1555,8 +1548,6 @@ static int action_ok_playlist_entry_start_content(const char *path, if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return menu_cbs_exit(); menu_driver_ctl(RARCH_MENU_CTL_PLAYLIST_GET, &tmp_playlist); @@ -2054,15 +2045,12 @@ static int action_ok_path_scan_directory(const char *path, static int action_ok_core_deferred_set(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { - size_t selection; char core_display_name[PATH_MAX_LENGTH]; playlist_t *playlist = NULL; + size_t selection = menu_navigation_get_selection(); core_display_name[0] = '\0'; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return menu_cbs_exit(); - menu_driver_ctl(RARCH_MENU_CTL_PLAYLIST_GET, &playlist); retro_assert(playlist != NULL); @@ -2080,7 +2068,7 @@ static int action_ok_core_deferred_set(const char *path, playlist_write_file(playlist); menu_entries_pop_stack(&selection, 0, 1); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); + menu_navigation_set_selection(selection); return menu_cbs_exit(); } @@ -2088,15 +2076,12 @@ static int action_ok_core_deferred_set(const char *path, static int action_ok_core_deferred_set_current_core(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { - size_t selection; char core_display_name[PATH_MAX_LENGTH]; playlist_t *playlist = NULL; + size_t selection = menu_navigation_get_selection(); core_display_name[0] = '\0'; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return menu_cbs_exit(); - menu_driver_ctl(RARCH_MENU_CTL_PLAYLIST_GET, &playlist); retro_assert(playlist != NULL); @@ -2114,7 +2099,7 @@ static int action_ok_core_deferred_set_current_core(const char *path, playlist_write_file(playlist); menu_entries_pop_stack(&selection, 0, 1); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); + menu_navigation_set_selection(selection); return 0; } @@ -2932,9 +2917,9 @@ static int action_ok_delete_entry(const char *path, playlist_delete_index(playlist, rpl_entry_selection_ptr); - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &new_selection_ptr); + new_selection_ptr = menu_navigation_get_selection(); menu_entries_pop_stack(&new_selection_ptr, 0, 1); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &new_selection_ptr); + menu_navigation_set_selection(new_selection_ptr); return 0; } @@ -3857,11 +3842,8 @@ static int action_ok_load_archive_detect_core(const char *path, if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &idx)) - return false; - - menu_path = menu->scratch2_buf; - content_path = menu->scratch_buf; + menu_path = menu->scratch2_buf; + content_path = menu->scratch_buf; core_info_get_list(&list); @@ -3894,9 +3876,12 @@ static int action_ok_load_archive_detect_core(const char *path, } return 0; case 0: - return generic_action_ok_displaylist_push(path, NULL, - label, type, - idx, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST); + { + idx = menu_navigation_get_selection(); + return generic_action_ok_displaylist_push(path, NULL, + label, type, + idx, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST); + } default: break; } diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 4b682717d9..8839564396 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -126,11 +126,10 @@ int action_right_input_desc(unsigned type, const char *label, static int action_right_scroll(unsigned type, const char *label, bool wraparound) { - size_t selection; size_t scroll_accel = 0; unsigned scroll_speed = 0, fast_scroll_speed = 0; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return false; + size_t selection = menu_navigation_get_selection(); + if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &scroll_accel)) return false; @@ -141,7 +140,8 @@ static int action_right_scroll(unsigned type, const char *label, { size_t idx = selection + fast_scroll_speed; bool scroll = true; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + + menu_navigation_set_selection(idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } else @@ -156,17 +156,13 @@ static int action_right_scroll(unsigned type, const char *label, static int action_right_goto_tab(void) { menu_ctx_list_t list_info; - size_t selection = 0; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); - menu_file_list_cbs_t *cbs = NULL; + size_t selection = menu_navigation_get_selection(); + menu_file_list_cbs_t *cbs = menu_entries_get_actiondata_at_offset(selection_buf, selection); - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); - - cbs = menu_entries_get_actiondata_at_offset(selection_buf, selection); - - list_info.type = MENU_LIST_HORIZONTAL; - list_info.action = MENU_ACTION_RIGHT; + list_info.type = MENU_LIST_HORIZONTAL; + list_info.action = MENU_ACTION_RIGHT; menu_driver_ctl(RARCH_MENU_CTL_LIST_CACHE, &list_info); @@ -192,7 +188,6 @@ static int action_right_mainmenu(unsigned type, const char *label, { menu_ctx_list_t list_horiz_info; menu_ctx_list_t list_tabs_info; - size_t selection = 0; settings_t *settings = config_get_ptr(); list_horiz_info.type = MENU_LIST_HORIZONTAL; @@ -201,7 +196,7 @@ static int action_right_mainmenu(unsigned type, const char *label, menu_driver_ctl(RARCH_MENU_CTL_LIST_GET_SIZE, &list_horiz_info); menu_driver_ctl(RARCH_MENU_CTL_LIST_GET_SIZE, &list_tabs_info); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); + menu_navigation_set_selection(0); if ((list_info.selection != (list_horiz_info.size + list_tabs_info.size)) || settings->menu.navigation.wraparound.enable) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 3ff9e91b8d..98345a4e2d 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -808,26 +808,16 @@ static void mui_render_menu_list( for (; i < menu_entries_get_end(); i++) { - int y; - size_t selection; char rich_label[255]; char entry_value[255]; bool entry_selected = false; mui_node_t *node = (mui_node_t*) menu_entries_get_userdata_at_offset(list, i); - + size_t selection = menu_navigation_get_selection(); + int y = header_height - mui->scroll_y + sum; rich_label[0] = entry_value[0] = '\0'; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - continue; - - y = header_height - mui->scroll_y + sum; - - /*if ((y - (int)node->line_height) > (int)height - || ((y + (int)node->line_height) < 0)) - continue;*/ - menu_entry_get_value((unsigned)i, NULL, entry_value, sizeof(entry_value)); menu_entry_get_rich_label((unsigned)i, rich_label, sizeof(rich_label)); @@ -1255,8 +1245,7 @@ static void mui_frame(void *data, video_frame_info_t *video_info) menu_entries_get_title(title, sizeof(title)); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + selection = menu_navigation_get_selection(); if (background_rendered || libretro_running) menu_display_set_alpha(blue_50, 0.75); @@ -1568,13 +1557,11 @@ static bool mui_load_image(void *userdata, void *data, enum menu_image_type type static float mui_get_scroll(mui_handle_t *mui) { - size_t selection; unsigned width, height, half = 0; + size_t selection = menu_navigation_get_selection(); if (!mui) return 0; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return 0; video_driver_get_size(&width, &height); @@ -1688,15 +1675,13 @@ static int mui_environ(enum menu_environ_cb type, void *data, void *userdata) static void mui_preswitch_tabs(mui_handle_t *mui, unsigned action) { - size_t idx = 0; size_t stack_size = 0; file_list_t *menu_stack = NULL; + size_t idx = menu_navigation_get_selection(); if (!mui) return; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); - menu_stack = menu_entries_get_menu_stack_ptr(0); stack_size = menu_stack->size; @@ -1933,9 +1918,7 @@ static int mui_pointer_down(void *userdata, if (y > (-mui->scroll_y + header_height + node->y) && y < (-mui->scroll_y + header_height + node->y + node->line_height) ) - { - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &ii); - } + menu_navigation_set_selection(ii); } @@ -1949,7 +1932,6 @@ static int mui_pointer_up(void *userdata, unsigned ptr, menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { - size_t selection; unsigned width, height; unsigned header_height, i; mui_handle_t *mui = (mui_handle_t*)userdata; @@ -1962,7 +1944,7 @@ static int mui_pointer_up(void *userdata, if (y < header_height) { - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_CANCEL); } else if (y > height - mui->tabs_height) @@ -2016,16 +1998,14 @@ static void mui_list_insert(void *userdata, const char *unused, size_t list_size) { - size_t selection; float scale_factor; int i = (int)list_size; mui_node_t *node = NULL; mui_handle_t *mui = (mui_handle_t*)userdata; + size_t selection = menu_navigation_get_selection(); if (!mui || !list) return; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; node = (mui_node_t*)menu_entries_get_userdata_at_offset(list, i); diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index 05541db419..08ff50fb2e 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -70,20 +70,18 @@ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) { menu_entry_t entry; enum action_iterate_type iterate_type; - size_t selection = 0; unsigned file_type = 0; int ret = 0; uint32_t hash = 0; enum msg_hash_enums enum_idx = MSG_UNKNOWN; const char *label = NULL; menu_handle_t *menu = (menu_handle_t*)data; + size_t selection = menu_navigation_get_selection(); menu_entries_get_last_stack(NULL, &label, &file_type, &enum_idx, NULL); if (!menu) return 0; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return 0; menu->menu_state.msg[0] = '\0'; @@ -129,8 +127,7 @@ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) if (menu_input_key_bind_iterate(&bind)) { menu_entries_pop_stack(&selection, 0, 0); - menu_navigation_ctl( - MENU_NAVIGATION_CTL_SET_SELECTION, &selection); + menu_navigation_set_selection(selection); } else BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX); @@ -250,7 +247,7 @@ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) { size_t new_selection_ptr = selection; menu_entries_pop_stack(&new_selection_ptr, 0, 0); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); + menu_navigation_set_selection(selection); } if (BIT64_GET(menu->state, MENU_STATE_POST_ITERATE)) diff --git a/menu/drivers/nuklear.c b/menu/drivers/nuklear.c index 5008ae18c7..219c849ffc 100644 --- a/menu/drivers/nuklear.c +++ b/menu/drivers/nuklear.c @@ -490,14 +490,12 @@ static bool nk_menu_init_list(void *data) static int nk_menu_iterate(void *data, void *userdata, enum menu_action action) { int ret; - size_t selection; menu_entry_t entry; nk_menu_handle_t *nk = (nk_menu_handle_t*)userdata; + size_t selection = menu_navigation_get_selection(); if (!nk) return -1; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return 0; menu_entry_get(&entry, 0, selection, NULL, false); diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 34090a55eb..1e0e94ec87 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -574,7 +574,6 @@ static void rgui_render(void *data) for (; i < end; i++, y += FONT_HEIGHT_STRIDE) { menu_animation_ctx_ticker_t ticker; - size_t selection; char entry_path[255]; char entry_value[255]; char message[255]; @@ -582,9 +581,7 @@ static void rgui_render(void *data) char type_str_buf[255]; unsigned entry_spacing = menu_entry_get_spacing((unsigned)i); bool entry_selected = menu_entry_is_currently_selected((unsigned)i); - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - continue; + size_t selection = menu_navigation_get_selection(); if (i > (selection + 100)) continue; @@ -763,12 +760,12 @@ static void rgui_navigation_clear(void *data, bool pending_push) static void rgui_navigation_set(void *data, bool scroll) { - size_t selection, start, fb_pitch; + size_t start, fb_pitch; unsigned fb_width, fb_height; bool do_set_start = false; size_t end = menu_entries_get_end(); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + size_t selection = menu_navigation_get_selection(); + if (!scroll) return; @@ -850,25 +847,22 @@ static int rgui_pointer_tap(void *data, unsigned ptr, menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { - size_t selection; unsigned header_height = menu_display_get_header_height(); if (y < header_height) { - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_CANCEL); } else if (ptr <= (menu_entries_get_size() - 1)) { - size_t idx; bool scroll = false; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); + if (ptr == selection && cbs && cbs->action_select) return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_SELECT); - idx = ptr; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(ptr); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 63394d78cf..dbe90075fe 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1073,17 +1073,16 @@ static void xmb_selection_pointer_changed( { unsigned i, end, height; menu_animation_ctx_tag_t tag; - size_t selection, num = 0; + size_t num = 0; int threshold = 0; menu_list_t *menu_list = NULL; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); + size_t selection = menu_navigation_get_selection(); menu_entries_ctl(MENU_ENTRIES_CTL_LIST_GET, &menu_list); if (!xmb) return; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; end = (unsigned)menu_entries_get_end(); threshold = xmb->icon.size*10; @@ -1559,12 +1558,9 @@ static void xmb_list_switch_horizontal_list(xmb_handle_t *xmb) static void xmb_list_switch(xmb_handle_t *xmb) { menu_animation_ctx_entry_t entry; - size_t selection; - int dir = -1; + int dir = -1; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + size_t selection = menu_navigation_get_selection(); if (xmb->categories.selection_ptr > xmb->categories.selection_ptr_old) dir = 1; @@ -1868,12 +1864,9 @@ static void xmb_list_open(xmb_handle_t *xmb) { menu_animation_ctx_entry_t entry; - size_t selection; int dir = 0; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + size_t selection = menu_navigation_get_selection(); xmb->depth = (int)xmb_list_get_size(xmb, MENU_LIST_PLAIN); @@ -2381,10 +2374,7 @@ static void xmb_render(void *data) if (settings->menu.pointer.enable || settings->menu.mouse.enable) { - size_t selection; - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + size_t selection = menu_navigation_get_selection(); for (i = 0; i < end; i++) { @@ -2627,8 +2617,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) coord_black, coord_white); - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + selection = menu_navigation_get_selection(); strlcpy(title_truncated, xmb->title_name, sizeof(title_truncated)); if (selection > 1) @@ -3065,12 +3054,9 @@ static void xmb_layout_psp(xmb_handle_t *xmb, int width) static void xmb_layout(xmb_handle_t *xmb) { - size_t selection; unsigned width, height, i, current, end; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + size_t selection = menu_navigation_get_selection(); video_driver_get_size(&width, &height); @@ -3604,16 +3590,14 @@ static void xmb_list_insert(void *userdata, const char *unused, size_t list_size) { - size_t selection; int current = 0; int i = (int)list_size; xmb_node_t *node = NULL; xmb_handle_t *xmb = (xmb_handle_t*)userdata; + size_t selection = menu_navigation_get_selection(); if (!xmb || !list) return; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; node = (xmb_node_t*)menu_entries_get_userdata_at_offset(list, i); @@ -3735,15 +3719,14 @@ static void xmb_list_deep_copy(const file_list_t *src, file_list_t *dst) static void xmb_list_cache(void *data, enum menu_list_type type, unsigned action) { - size_t stack_size, list_size, selection; + size_t stack_size, list_size; xmb_handle_t *xmb = (xmb_handle_t*)data; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); + size_t selection = menu_navigation_get_selection(); if (!xmb) return; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; xmb_list_deep_copy(selection_buf, xmb->selection_buf_old); xmb_list_deep_copy(menu_stack, xmb->menu_stack_old); @@ -4059,26 +4042,21 @@ static int xmb_pointer_tap(void *userdata, menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { - size_t selection; unsigned header_height = menu_display_get_header_height(); if (y < header_height) { - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); return (unsigned)menu_entry_action(entry, (unsigned)selection, MENU_ACTION_CANCEL); } else if (ptr <= (menu_entries_get_size() - 1)) { - size_t idx; bool scroll = false; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); if (ptr == selection && cbs && cbs->action_select) return (unsigned)menu_entry_action(entry, (unsigned)selection, MENU_ACTION_SELECT); - idx = ptr; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(ptr); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } diff --git a/menu/drivers/xui.cpp b/menu/drivers/xui.cpp index 72e11b0646..3344667b19 100644 --- a/menu/drivers/xui.cpp +++ b/menu/drivers/xui.cpp @@ -590,8 +590,7 @@ static void xui_render(void *data) xui_set_list_text(i, msg_left, msg_right); } - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + selection = menu_navigation_get_selection(); XuiListSetCurSelVisible(m_menulist, selection); @@ -610,31 +609,19 @@ static void xui_populate_entries(void *data, const char *path, const char *label, unsigned i) { - size_t selection; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; - - (void)label; - (void)path; - + size_t selection = menu_navigation_get_selection(); XuiListSetCurSelVisible(m_menulist, selection); } static void xui_navigation_clear(void *data, bool pending_push) { - size_t selection; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; - + size_t selection = menu_navigation_get_selection(); XuiListSetCurSelVisible(m_menulist, selection); } static void xui_navigation_set_visible(void *data) { - size_t selection; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; - + size_t selection = menu_navigation_get_selection(); XuiListSetCurSelVisible(m_menulist, selection); } diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index fdd707386a..83f4247a57 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -1108,14 +1108,12 @@ static void zarch_context_reset(void *data) static int zarch_iterate(void *data, void *userdata, enum menu_action action) { int ret; - size_t selection; menu_entry_t entry; zui_t *zui = (zui_t*)userdata; + size_t selection = menu_navigation_get_selection(); if (!zui) return -1; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return 0; menu_entry_get(&entry, 0, selection, NULL, false); diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 42d7becaf6..01a684e096 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3737,7 +3737,7 @@ static bool menu_displaylist_push_list_process(menu_displaylist_info_t *info) menu_entries_ctl(MENU_ENTRIES_CTL_REFRESH, info->list); if (info->need_clear) - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(idx); if (info->need_push) { diff --git a/menu/menu_driver.c b/menu/menu_driver.c index fbee290901..07aa9e582f 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -948,9 +948,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) break; case RARCH_MENU_CTL_UPDATE_THUMBNAIL_PATH: { - size_t selection; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return false; + size_t selection = menu_navigation_get_selection(); if (!menu_driver_ctx || !menu_driver_ctx->update_thumbnail_path) return false; @@ -966,9 +964,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) break; case RARCH_MENU_CTL_UPDATE_SAVESTATE_THUMBNAIL_PATH: { - size_t selection; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return false; + size_t selection = menu_navigation_get_selection(); if (!menu_driver_ctx || !menu_driver_ctx->update_savestate_thumbnail_path) return false; diff --git a/menu/menu_entries.c b/menu/menu_entries.c index 0760997a93..3a28f526ae 100644 --- a/menu/menu_entries.c +++ b/menu/menu_entries.c @@ -176,13 +176,9 @@ static void menu_entries_build_scroll_indices(file_list_t *list) **/ static bool menu_entries_refresh(void *data) { - size_t list_size, selection; + size_t list_size; file_list_t *list = (file_list_t*)data; - - if (!list) - return false; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return false; + size_t selection = menu_navigation_get_selection(); menu_entries_build_scroll_indices(list); @@ -192,7 +188,7 @@ static bool menu_entries_refresh(void *data) { size_t idx = list_size - 1; bool scroll = true; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } else if (!list_size) @@ -636,6 +632,8 @@ bool menu_entries_ctl(enum menu_entries_ctl_state state, void *data) } break; case MENU_ENTRIES_CTL_REFRESH: + if (!data) + return false; return menu_entries_refresh(data); case MENU_ENTRIES_CTL_CLEAR: return menu_entries_clear((file_list_t*)data); diff --git a/menu/menu_input.c b/menu/menu_input.c index 9235f6a810..5afc7a06fd 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -149,10 +149,8 @@ static int menu_input_mouse_post_iterate(uint64_t *input_mouse, { if (!mouse_oldleft) { - size_t selection; menu_input_t *menu_input = menu_input_get_ptr(); - - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); BIT64_SET(*input_mouse, MENU_MOUSE_ACTION_BUTTON_L); @@ -282,8 +280,7 @@ static int menu_input_mouse_frame( if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_BUTTON_R)) { - size_t selection; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); menu_entry_action(entry, (unsigned)selection, MENU_ACTION_CANCEL); } @@ -515,8 +512,7 @@ static int menu_input_pointer_post_iterate( { if (menu_input->pointer.counter > 32) { - size_t selection; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); if (cbs && cbs->action_start) return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_START); @@ -547,10 +543,8 @@ static int menu_input_pointer_post_iterate( { if (!pointer_oldback) { - size_t selection; pointer_oldback = true; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); - menu_entry_action(entry, (unsigned)selection, MENU_ACTION_CANCEL); + menu_entry_action(entry, (unsigned)menu_navigation_get_selection(), MENU_ACTION_CANCEL); } } @@ -561,14 +555,11 @@ static int menu_input_pointer_post_iterate( void menu_input_post_iterate(int *ret, unsigned action) { - size_t selection; menu_entry_t entry; menu_file_list_cbs_t *cbs = NULL; settings_t *settings = config_get_ptr(); file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return; + size_t selection = menu_navigation_get_selection(); if (selection_buf) cbs = menu_entries_get_actiondata_at_offset(selection_buf, selection); diff --git a/menu/menu_navigation.c b/menu/menu_navigation.c index 1020518e2e..527e0bc750 100644 --- a/menu/menu_navigation.c +++ b/menu/menu_navigation.c @@ -26,6 +26,18 @@ #include "menu_driver.h" #include "menu_navigation.h" +static size_t selection_ptr = 0; + +size_t menu_navigation_get_selection(void) +{ + return selection_ptr; +} + +void menu_navigation_set_selection(size_t val) +{ + selection_ptr = val; +} + bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) { /* Quick jumping indices with L/R. @@ -36,7 +48,6 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) unsigned size; } scroll_index; static unsigned scroll_acceleration = 0; - static size_t selection_ptr = 0; switch (state) { @@ -47,10 +58,8 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) break; case MENU_NAVIGATION_CTL_CLEAR: { - size_t idx = 0; bool scroll = true; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(0); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_CLEAR, data); } @@ -73,7 +82,8 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) { size_t idx = selection_ptr + (*scroll_speed); bool scroll = true; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + + menu_navigation_set_selection(idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); menu_navigation_ctl(MENU_NAVIGATION_CTL_INCREMENT, NULL); } @@ -121,7 +131,7 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) idx = 0; } - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, NULL); menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_DECREMENT, NULL); @@ -135,8 +145,7 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) { size_t menu_list_size = menu_entries_get_size(); size_t new_selection = menu_list_size - 1; - menu_navigation_ctl( - MENU_NAVIGATION_CTL_SET_SELECTION, &new_selection); + menu_navigation_set_selection(new_selection); menu_driver_ctl(RARCH_MENU_CTL_NAVIGATION_SET_LAST, NULL); } break; @@ -192,22 +201,6 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data) RARCH_MENU_CTL_NAVIGATION_DESCEND_ALPHABET, ptr_out); } break; - case MENU_NAVIGATION_CTL_GET_SELECTION: - { - size_t *sel = (size_t*)data; - if (!sel) - return false; - *sel = selection_ptr; - } - break; - case MENU_NAVIGATION_CTL_SET_SELECTION: - { - size_t *sel = (size_t*)data; - if (!sel) - return false; - selection_ptr = *sel; - } - break; case MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES: scroll_index.size = 0; break; diff --git a/menu/menu_navigation.h b/menu/menu_navigation.h index 4ef22d355b..ff96f03ce8 100644 --- a/menu/menu_navigation.h +++ b/menu/menu_navigation.h @@ -35,14 +35,16 @@ enum menu_navigation_ctl_state MENU_NAVIGATION_CTL_SET_LAST, MENU_NAVIGATION_CTL_DESCEND_ALPHABET, MENU_NAVIGATION_CTL_ASCEND_ALPHABET, - MENU_NAVIGATION_CTL_SET_SELECTION, - MENU_NAVIGATION_CTL_GET_SELECTION, MENU_NAVIGATION_CTL_CLEAR_SCROLL_INDICES, MENU_NAVIGATION_CTL_ADD_SCROLL_INDEX, MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL }; +size_t menu_navigation_get_selection(void); + +void menu_navigation_set_selection(size_t val); + bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data); RETRO_END_DECLS diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 83eae9130a..76b11f958f 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -705,13 +705,10 @@ int menu_action_handle_setting(rarch_setting_t *setting, case ST_PATH: if (action == MENU_ACTION_OK) { - size_t selection; menu_displaylist_info_t info = {0}; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); const char *name = setting->name; - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return -1; + size_t selection = menu_navigation_get_selection(); info.list = menu_stack; info.directory_ptr = selection; @@ -856,15 +853,11 @@ int menu_setting_set_flags(rarch_setting_t *setting) int menu_setting_set(unsigned type, const char *label, unsigned action, bool wraparound) { - size_t selection; int ret = 0; - menu_file_list_cbs_t *cbs = NULL; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); - - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return 0; - - cbs = menu_entries_get_actiondata_at_offset(selection_buf, selection); + size_t selection = menu_navigation_get_selection(); + menu_file_list_cbs_t *cbs = menu_entries_get_actiondata_at_offset( + selection_buf, selection); if (!cbs) return 0; diff --git a/menu/widgets/menu_entry.c b/menu/widgets/menu_entry.c index beb5941090..12d1923135 100644 --- a/menu/widgets/menu_entry.c +++ b/menu/widgets/menu_entry.c @@ -452,11 +452,7 @@ void menu_entry_get(menu_entry_t *entry, size_t stack_idx, bool menu_entry_is_currently_selected(unsigned id) { - size_t selection; - if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) - return false; - - return (id == selection); + return (id == menu_navigation_get_selection()); } /* Performs whatever actions are associated with menu entry 'i'. @@ -481,7 +477,7 @@ int menu_entry_select(uint32_t i) entry.type = 0; entry.spacing = 0; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &i); + menu_navigation_set_selection(i); menu_entry_get(&entry, 0, i, NULL, false); diff --git a/menu/widgets/menu_input_bind_dialog.c b/menu/widgets/menu_input_bind_dialog.c index e5d8fadddf..0386285687 100644 --- a/menu/widgets/menu_input_bind_dialog.c +++ b/menu/widgets/menu_input_bind_dialog.c @@ -83,15 +83,13 @@ static int menu_input_key_bind_set_mode_common( enum menu_input_binds_ctl_state state, rarch_setting_t *setting) { - size_t selection; unsigned bind_type = 0; menu_displaylist_info_t info = {0}; struct retro_keybind *keybind = NULL; settings_t *settings = config_get_ptr(); unsigned index_offset = setting->index_offset; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); - - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + size_t selection = menu_navigation_get_selection(); switch (state) { @@ -103,10 +101,10 @@ static int menu_input_key_bind_set_mode_common( bind_type = setting_get_bind_type(setting); - menu_input_binds.begin = bind_type; - menu_input_binds.last = bind_type; - menu_input_binds.target = keybind; - menu_input_binds.user = index_offset; + menu_input_binds.begin = bind_type; + menu_input_binds.last = bind_type; + menu_input_binds.target = keybind; + menu_input_binds.user = index_offset; info.list = menu_stack; info.type = MENU_SETTINGS_CUSTOM_BIND_KEYBOARD; @@ -119,10 +117,10 @@ static int menu_input_key_bind_set_mode_common( menu_displaylist_ctl(DISPLAYLIST_PROCESS, &info); break; case MENU_INPUT_BINDS_CTL_BIND_ALL: - menu_input_binds.target = &settings->input.binds + menu_input_binds.target = &settings->input.binds [index_offset][0]; - menu_input_binds.begin = MENU_SETTINGS_BIND_BEGIN; - menu_input_binds.last = MENU_SETTINGS_BIND_LAST; + menu_input_binds.begin = MENU_SETTINGS_BIND_BEGIN; + menu_input_binds.last = MENU_SETTINGS_BIND_LAST; info.list = menu_stack; info.type = MENU_SETTINGS_CUSTOM_BIND_KEYBOARD; diff --git a/menu/widgets/menu_input_dialog.c b/menu/widgets/menu_input_dialog.c index 12041438d5..2f6e091bda 100644 --- a/menu/widgets/menu_input_dialog.c +++ b/menu/widgets/menu_input_dialog.c @@ -40,7 +40,7 @@ static void menu_input_search_cb(void *userdata, const char *str) if (str && *str && file_list_search(selection_buf, str, &idx)) { bool scroll = true; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + menu_navigation_set_selection(idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } diff --git a/menu/widgets/menu_list.c b/menu/widgets/menu_list.c index 421ecdd000..b6cfab843a 100644 --- a/menu/widgets/menu_list.c +++ b/menu/widgets/menu_list.c @@ -157,16 +157,12 @@ void menu_list_flush_stack(menu_list_t *list, while (menu_list_flush_stack_type( needle, label, type, final_type) != 0) { - size_t new_selection_ptr; - - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, - &new_selection_ptr); + size_t new_selection_ptr = menu_navigation_get_selection(); if (!menu_list_pop_stack(list, idx, &new_selection_ptr, 1)) break; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, - &new_selection_ptr); + menu_navigation_set_selection(new_selection_ptr); menu_list = menu_list_get(list, (unsigned)idx);