mirror of
https://github.com/libretro/RetroArch
synced 2025-02-09 09:39:56 +00:00
Refactor menu_navigation_get_selection
This commit is contained in:
parent
14c463dae2
commit
d4e2b6128b
@ -89,13 +89,16 @@ static int action_left_save_state(unsigned type, const char *label,
|
||||
static int action_left_scroll(unsigned type, const char *label,
|
||||
bool wraparound)
|
||||
{
|
||||
size_t selection;
|
||||
unsigned scroll_speed = 0, fast_scroll_speed = 0;
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
size_t selection = menu_navigation_get_selection(nav);
|
||||
if (!nav || !menu_list)
|
||||
return -1;
|
||||
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return -1;
|
||||
|
||||
scroll_speed = (max(nav->scroll.acceleration, 2) - 2) / 4 + 1;
|
||||
fast_scroll_speed = 4 + 4 * scroll_speed;
|
||||
|
||||
|
@ -1538,10 +1538,10 @@ static int action_ok_load_archive(const char *path,
|
||||
static int action_ok_load_archive_detect_core(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
||||
{
|
||||
size_t selection;
|
||||
int ret = 0;
|
||||
global_t *global = global_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
size_t selected = menu_navigation_get_selection(nav);
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
const char *menu_path = menu ? menu->scratch2_buf : NULL;
|
||||
@ -1550,6 +1550,9 @@ static int action_ok_load_archive_detect_core(const char *path,
|
||||
if (!menu || !menu_list)
|
||||
return -1;
|
||||
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return false;
|
||||
|
||||
ret = rarch_defer_core(global->core_info.list, menu_path, content_path, label,
|
||||
menu->deferred_path, sizeof(menu->deferred_path));
|
||||
|
||||
@ -1563,7 +1566,7 @@ static int action_ok_load_archive_detect_core(const char *path,
|
||||
return menu_common_load_content(NULL, NULL, false, CORE_TYPE_PLAIN);
|
||||
case 0:
|
||||
return generic_action_ok_displaylist_push(path, label, type,
|
||||
selected, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST);
|
||||
selection, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -118,12 +118,14 @@ static int action_right_save_state(unsigned type, const char *label,
|
||||
static int action_right_scroll(unsigned type, const char *label,
|
||||
bool wraparound)
|
||||
{
|
||||
size_t selection;
|
||||
unsigned scroll_speed = 0, fast_scroll_speed = 0;
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
size_t selection = menu_navigation_get_selection(nav);
|
||||
if (!nav || !menu_list)
|
||||
return -1;
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return false;
|
||||
|
||||
scroll_speed = (max(nav->scroll.acceleration, 2) - 2) / 4 + 1;
|
||||
fast_scroll_speed = 4 + 4 * scroll_speed;
|
||||
|
@ -325,7 +325,6 @@ static void glui_render_menu_list(glui_handle_t *glui,
|
||||
uint64_t *frame_count = video_driver_get_frame_count();
|
||||
size_t end = menu_entries_get_end();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
|
||||
if (!menu_display_ctl(MENU_DISPLAY_CTL_UPDATE_PENDING, NULL))
|
||||
return;
|
||||
@ -334,17 +333,22 @@ static void glui_render_menu_list(glui_handle_t *glui,
|
||||
|
||||
for (i = menu_entries_get_start(); i < end; i++)
|
||||
{
|
||||
int y;
|
||||
size_t selection;
|
||||
bool entry_selected;
|
||||
menu_entry_t entry;
|
||||
|
||||
int y = disp->header_height - menu->scroll_y + (glui->line_height * i);
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
continue;
|
||||
|
||||
y = disp->header_height - menu->scroll_y + (glui->line_height * i);
|
||||
|
||||
if (y > (int)height || ((y + (int)glui->line_height) < 0))
|
||||
continue;
|
||||
|
||||
menu_entries_get(i, &entry);
|
||||
|
||||
entry_selected = (menu_navigation_get_selection(nav) == i);
|
||||
entry_selected = selection == i;
|
||||
|
||||
glui_render_label_value(glui, y, width, height, *frame_count / 40,
|
||||
entry_selected ? hover_color : normal_color, entry_selected,
|
||||
@ -368,13 +372,13 @@ static void glui_frame(void)
|
||||
char title_buf[PATH_MAX_LENGTH];
|
||||
char title_msg[PATH_MAX_LENGTH];
|
||||
char timedate[PATH_MAX_LENGTH];
|
||||
size_t selection;
|
||||
gl_t *gl = NULL;
|
||||
glui_handle_t *glui = NULL;
|
||||
const struct font_renderer *font_driver = NULL;
|
||||
driver_t *driver = driver_get_ptr();
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
uint64_t *frame_count = video_driver_get_frame_count();
|
||||
@ -439,9 +443,12 @@ static void glui_frame(void)
|
||||
|
||||
menu_display_font_flush_block(menu, font_driver);
|
||||
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
glui_render_quad(gl, 0,
|
||||
disp->header_height - menu->scroll_y + glui->line_height *
|
||||
menu_navigation_get_selection(nav), width, glui->line_height,
|
||||
selection, width, glui->line_height,
|
||||
width, height,
|
||||
&highlight_bg[0]);
|
||||
|
||||
@ -704,12 +711,14 @@ static bool glui_load_image(void *data, menu_image_type_t type)
|
||||
|
||||
static float glui_get_scroll(void)
|
||||
{
|
||||
int half = 0;
|
||||
size_t selection;
|
||||
unsigned width, height;
|
||||
int half = 0;
|
||||
glui_handle_t *glui = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
size_t selection = menu_navigation_get_selection(nav);
|
||||
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return 0;
|
||||
|
||||
if (!menu || !menu->userdata)
|
||||
return 0;
|
||||
|
@ -536,6 +536,7 @@ static void rgui_render(void)
|
||||
|
||||
for (; i < end; i++, y += FONT_HEIGHT_STRIDE)
|
||||
{
|
||||
size_t selection;
|
||||
char entry_path[PATH_MAX_LENGTH];
|
||||
char entry_value[PATH_MAX_LENGTH];
|
||||
char message[PATH_MAX_LENGTH];
|
||||
@ -543,8 +544,11 @@ static void rgui_render(void)
|
||||
char type_str_buf[PATH_MAX_LENGTH];
|
||||
unsigned entry_spacing = menu_entry_get_spacing(i);
|
||||
bool entry_selected = menu_entry_is_currently_selected(i);
|
||||
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return false;
|
||||
|
||||
if (i > (menu_navigation_get_selection(nav) + 100))
|
||||
if (i > (selection + 100))
|
||||
continue;
|
||||
|
||||
entry_path[0] = '\0';
|
||||
@ -719,17 +723,13 @@ static void rgui_navigation_clear(bool pending_push)
|
||||
|
||||
static void rgui_navigation_set(bool scroll)
|
||||
{
|
||||
size_t end;
|
||||
size_t selection;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
size_t selection = menu_navigation_get_selection(nav);
|
||||
if (!menu)
|
||||
size_t end = menu_entries_get_end();
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
end = menu_entries_get_end();
|
||||
|
||||
if (!scroll)
|
||||
if (!menu || !scroll)
|
||||
return;
|
||||
|
||||
if (selection < RGUI_TERM_HEIGHT/2)
|
||||
|
@ -565,7 +565,8 @@ static void xmb_update_boxart(xmb_handle_t *xmb, unsigned i)
|
||||
|
||||
static void xmb_selection_pointer_changed(bool allow_animations)
|
||||
{
|
||||
unsigned i, current, end, tag, height, skip;
|
||||
size_t selection;
|
||||
unsigned i, end, tag, height, skip;
|
||||
int threshold = 0;
|
||||
xmb_handle_t *xmb = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
@ -581,8 +582,9 @@ static void xmb_selection_pointer_changed(bool allow_animations)
|
||||
|
||||
if (!xmb)
|
||||
return;
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
current = menu_navigation_get_selection(nav);
|
||||
end = menu_entries_get_end();
|
||||
tag = (uintptr_t)menu_list;
|
||||
threshold = xmb->icon.size*10;
|
||||
@ -604,10 +606,10 @@ static void xmb_selection_pointer_changed(bool allow_animations)
|
||||
if (!node)
|
||||
continue;
|
||||
|
||||
iy = xmb_item_y(xmb, i, current);
|
||||
iy = xmb_item_y(xmb, i, selection);
|
||||
real_iy = iy + xmb->margins.screen.top;
|
||||
|
||||
if (i == current)
|
||||
if (i == selection)
|
||||
{
|
||||
ia = xmb->item.active.alpha;
|
||||
iz = xmb->item.active.zoom;
|
||||
@ -915,13 +917,15 @@ static void xmb_list_switch_horizontal_list(xmb_handle_t *xmb, menu_handle_t *me
|
||||
|
||||
static void xmb_list_switch(xmb_handle_t *xmb)
|
||||
{
|
||||
size_t selection;
|
||||
int dir = -1;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
size_t selection = menu_navigation_get_selection(nav);
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
if (!menu)
|
||||
return;
|
||||
@ -1404,7 +1408,8 @@ static void xmb_draw_cursor(gl_t *gl, xmb_handle_t *xmb,
|
||||
|
||||
static void xmb_render(void)
|
||||
{
|
||||
unsigned i, current, end, height = 0;
|
||||
size_t selection;
|
||||
unsigned i, end, height = 0;
|
||||
xmb_handle_t *xmb = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
@ -1425,14 +1430,16 @@ static void xmb_render(void)
|
||||
|
||||
video_driver_get_size(NULL, &height);
|
||||
|
||||
current = menu_navigation_get_selection(nav);
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
end = menu_list_get_size(menu_list);
|
||||
|
||||
if (settings->menu.pointer.enable || settings->menu.mouse.enable)
|
||||
{
|
||||
for (i = 0; i < end; i++)
|
||||
{
|
||||
float item_y1 = xmb->margins.screen.top + xmb_item_y(xmb, i, current);
|
||||
float item_y1 = xmb->margins.screen.top + xmb_item_y(xmb, i, selection);
|
||||
float item_y2 = item_y1 + xmb->icon.size;
|
||||
int16_t pointer_y = menu_input_pointer_state(MENU_POINTER_Y_AXIS);
|
||||
int16_t mouse_y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS);
|
||||
|
@ -322,10 +322,10 @@ void menu_entry_get(menu_entry_t *entry, size_t i,
|
||||
|
||||
bool menu_entry_is_currently_selected(unsigned id)
|
||||
{
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
size_t selection = menu_navigation_get_selection(nav);
|
||||
if (!nav)
|
||||
return false;
|
||||
size_t selection;
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return false;
|
||||
|
||||
return (id == selection);
|
||||
}
|
||||
|
||||
|
@ -1152,16 +1152,21 @@ void menu_input_set_binds_minmax(unsigned min, unsigned max)
|
||||
|
||||
void menu_input_post_iterate(int *ret, unsigned action)
|
||||
{
|
||||
size_t selection;
|
||||
menu_file_list_cbs_t *cbs = NULL;
|
||||
menu_entry_t entry = {{0}};
|
||||
menu_input_t *menu_input = menu_input_get_ptr();
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
size_t selected = menu_navigation_get_selection(nav);
|
||||
menu_file_list_cbs_t *cbs = menu_list_get_actiondata_at_offset
|
||||
(menu_list->selection_buf, selected);
|
||||
|
||||
menu_entry_get(&entry, selected, NULL, false);
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
cbs = menu_list_get_actiondata_at_offset
|
||||
(menu_list->selection_buf, selection);
|
||||
|
||||
menu_entry_get(&entry, selection, NULL, false);
|
||||
|
||||
if (settings->menu.mouse.enable)
|
||||
*ret = menu_input_mouse_post_iterate (&menu_input->mouse.state, cbs, action);
|
||||
|
@ -172,16 +172,18 @@ static int action_iterate_help(char *s, size_t len, const char *label)
|
||||
|
||||
static int action_iterate_info(char *s, size_t len, const char *label)
|
||||
{
|
||||
size_t selection;
|
||||
uint32_t label_hash = 0;
|
||||
menu_file_list_cbs_t *cbs = NULL;
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
size_t i = menu_navigation_get_selection(nav);
|
||||
|
||||
if (!menu_list)
|
||||
return 0;
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return 0;
|
||||
|
||||
cbs = menu_list_get_actiondata_at_offset(menu_list->selection_buf, i);
|
||||
cbs = menu_list_get_actiondata_at_offset(menu_list->selection_buf, selection);
|
||||
|
||||
if (cbs->setting)
|
||||
{
|
||||
@ -427,7 +429,7 @@ int menu_iterate(bool render_this_frame, unsigned action)
|
||||
{
|
||||
menu_entry_t entry;
|
||||
enum action_iterate_type iterate_type;
|
||||
size_t selected;
|
||||
size_t selection;
|
||||
const char *label = NULL;
|
||||
int ret = 0;
|
||||
uint32_t hash = 0;
|
||||
@ -491,12 +493,12 @@ int menu_iterate(bool render_this_frame, unsigned action)
|
||||
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
|
||||
break;
|
||||
case ITERATE_TYPE_DEFAULT:
|
||||
selected = menu_navigation_get_selection(nav);
|
||||
/* FIXME: selected > selection_buf->list->size, i don't know why. */
|
||||
selected = max(min(selected, menu_list_get_size(menu_list)-1), 0);
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return 0;
|
||||
selection = max(min(selection, menu_list_get_size(menu_list)-1), 0);
|
||||
|
||||
menu_entry_get(&entry, selected, NULL, false);
|
||||
ret = menu_entry_action(&entry, selected, (enum menu_action)action);
|
||||
menu_entry_get(&entry, selection, NULL, false);
|
||||
ret = menu_entry_action(&entry, selection, (enum menu_action)action);
|
||||
|
||||
if (ret)
|
||||
goto end;
|
||||
|
@ -140,6 +140,14 @@ bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data)
|
||||
driver->navigation_descend_alphabet(ptr_out);
|
||||
}
|
||||
return true;
|
||||
case MENU_NAVIGATION_CTL_GET_SELECTION:
|
||||
{
|
||||
size_t *sel = (size_t*)data;
|
||||
if (!nav || !sel)
|
||||
return false;
|
||||
*sel = nav->selection_ptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -230,10 +238,3 @@ void menu_navigation_ascend_alphabet(menu_navigation_t *nav, size_t *ptr_out)
|
||||
|
||||
menu_navigation_ctl(MENU_NAVIGATION_CTL_ASCEND_ALPHABET, ptr_out);
|
||||
}
|
||||
|
||||
size_t menu_navigation_get_selection(menu_navigation_t *nav)
|
||||
{
|
||||
if (!nav)
|
||||
return 0;
|
||||
return nav->selection_ptr;
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ enum menu_navigation_ctl_state
|
||||
MENU_NAVIGATION_CTL_SET,
|
||||
MENU_NAVIGATION_CTL_SET_LAST,
|
||||
MENU_NAVIGATION_CTL_DESCEND_ALPHABET,
|
||||
MENU_NAVIGATION_CTL_ASCEND_ALPHABET
|
||||
MENU_NAVIGATION_CTL_ASCEND_ALPHABET,
|
||||
MENU_NAVIGATION_CTL_GET_SELECTION
|
||||
};
|
||||
|
||||
/**
|
||||
@ -96,8 +97,6 @@ void menu_navigation_descend_alphabet(menu_navigation_t *nav, size_t *ptr_out);
|
||||
**/
|
||||
void menu_navigation_ascend_alphabet(menu_navigation_t *nav, size_t *ptr_out);
|
||||
|
||||
size_t menu_navigation_get_selection(menu_navigation_t *nav);
|
||||
|
||||
bool menu_navigation_ctl(enum menu_navigation_ctl_state state, void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user