From 5b51124b62b1cdabecc76cd996b133fce6550639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Mon, 2 Nov 2015 02:22:21 +0700 Subject: [PATCH] (Menu) Make the mouse left click and the pointer tap use the same codepath --- menu/drivers/glui.c | 18 ++++++++---------- menu/drivers/rgui.c | 12 ++++++------ menu/drivers/xmb.c | 12 ++++++------ menu/menu_driver.c | 6 +++--- menu/menu_driver.h | 8 ++++---- menu/menu_input.c | 28 ++++++++++++---------------- 6 files changed, 39 insertions(+), 45 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 382977bee4..d6005f7798 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -1415,13 +1415,12 @@ static size_t glui_list_get_selection(void *data) return glui->categories.selection_ptr; } -static int glui_pointer_tap(menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action) +static int glui_pointer_tap(unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { size_t selection, idx; unsigned header_height, width, height, i; bool scroll = false; - menu_input_t *menu_input = menu_input_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr(); glui_handle_t *glui = menu ? (glui_handle_t*)menu->userdata : NULL; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); @@ -1435,20 +1434,19 @@ static int glui_pointer_tap(menu_file_list_cbs_t *cbs, menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); menu_display_ctl(MENU_DISPLAY_CTL_HEADER_HEIGHT, &header_height); - if ((unsigned)menu_input->pointer.start_y < header_height) + if (y < header_height) { menu_entries_pop_stack(&selection, 0); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); } - else if ((unsigned)menu_input->pointer.start_y > height - glui->tabs_height) + else if (y > height - glui->tabs_height) { for (i = 0; i <= GLUI_SYSTEM_TAB_END; i++) { unsigned tab_width = width / (GLUI_SYSTEM_TAB_END + 1); unsigned start = tab_width * i; - if ((unsigned)menu_input->pointer.start_x >= start && - (unsigned)menu_input->pointer.start_x < start + tab_width) + if (x >= start && x < start + tab_width) { glui->categories.selection_ptr = i; @@ -1460,12 +1458,12 @@ static int glui_pointer_tap(menu_file_list_cbs_t *cbs, } } } - else if (menu_input->pointer.ptr <= (menu_entries_get_size() - 1)) + else if (ptr <= (menu_entries_get_size() - 1)) { - if (menu_input->pointer.ptr == selection && cbs && cbs->action_select) + if (ptr == selection && cbs && cbs->action_select) return menu_entry_action(entry, selection, MENU_ACTION_SELECT); - idx = menu_input->pointer.ptr; + idx = ptr; menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 4349579915..450a5ccd9b 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -840,8 +840,8 @@ static int rgui_environ(menu_environ_cb_t type, void *data) return 0; } -static int rgui_pointer_tap(menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action) +static int rgui_pointer_tap(unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { size_t selection, idx; unsigned header_height; @@ -851,17 +851,17 @@ static int rgui_pointer_tap(menu_file_list_cbs_t *cbs, menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); menu_display_ctl(MENU_DISPLAY_CTL_HEADER_HEIGHT, &header_height); - if ((unsigned)menu_input->pointer.start_y < header_height) + if (y < header_height) { menu_entries_pop_stack(&selection, 0); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); } - else if (menu_input->pointer.ptr <= (menu_entries_get_size() - 1)) + else if (ptr <= (menu_entries_get_size() - 1)) { - if (menu_input->pointer.ptr == selection && cbs && cbs->action_select) + if (ptr == selection && cbs && cbs->action_select) return menu_entry_action(entry, selection, MENU_ACTION_SELECT); - idx = menu_input->pointer.ptr; + idx = ptr; menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 1958408462..d95daf37ec 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2721,8 +2721,8 @@ static bool xmb_menu_init_list(void *data) return true; } -static int xmb_pointer_tap(menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action) +static int xmb_pointer_tap(unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { size_t selection, idx; unsigned header_height; @@ -2732,17 +2732,17 @@ static int xmb_pointer_tap(menu_file_list_cbs_t *cbs, menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); menu_display_ctl(MENU_DISPLAY_CTL_HEADER_HEIGHT, &header_height); - if ((unsigned)menu_input->pointer.start_y < header_height) + if (y < header_height) { menu_entries_pop_stack(&selection, 0); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &selection); } - else if (menu_input->pointer.ptr <= (menu_entries_get_size() - 1)) + else if (ptr <= (menu_entries_get_size() - 1)) { - if (menu_input->pointer.ptr == selection && cbs && cbs->action_select) + if (ptr == selection && cbs && cbs->action_select) return menu_entry_action(entry, selection, MENU_ACTION_SELECT); - idx = menu_input->pointer.ptr; + idx = ptr; menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); diff --git a/menu/menu_driver.c b/menu/menu_driver.c index d47a993c8d..e12851b2ff 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -393,14 +393,14 @@ bool menu_environment_cb(menu_environ_cb_t type, void *data) return false; } -int menu_driver_pointer_tap(menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action) +int menu_driver_pointer_tap(unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { int ret = 0; const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); if (driver->pointer_tap) - ret = driver->pointer_tap(cbs, entry, action); + ret = driver->pointer_tap(x, y, ptr, cbs, entry, action); return ret; } diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 7eaac07ce9..3b73414b0a 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -142,8 +142,8 @@ typedef struct menu_ctx_driver const char *ident; menu_video_driver_type_t type; int (*environ_cb)(menu_environ_cb_t type, void *data); - int (*pointer_tap)(menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action); + int (*pointer_tap)(unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action); } menu_ctx_driver_t; extern menu_ctx_driver_t menu_ctx_rmenu; @@ -230,8 +230,8 @@ int menu_driver_bind_init(menu_file_list_cbs_t *cbs, const char *elem0, const char *elem1, uint32_t label_hash, uint32_t menu_label_hash); -int menu_driver_pointer_tap(menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action); +int menu_driver_pointer_tap(unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action); /* HACK */ extern unsigned int rdb_entry_start_game_selection_ptr; diff --git a/menu/menu_input.c b/menu/menu_input.c index 3c34763573..113b10bd1b 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -790,8 +790,9 @@ static int menu_input_pointer(unsigned *action) static int menu_input_mouse_frame( menu_file_list_cbs_t *cbs, menu_entry_t *entry, - uint64_t input_mouse) + uint64_t input_mouse, unsigned action) { + int ret; size_t selection; menu_input_t *menu_input = menu_input_get_ptr(); @@ -799,16 +800,8 @@ static int menu_input_mouse_frame( if (BIT64_GET(input_mouse, MOUSE_ACTION_BUTTON_L)) { - if (BIT64_GET(input_mouse, MOUSE_ACTION_BUTTON_L_TOGGLE)) - return menu_entry_action(entry, selection, MENU_ACTION_SELECT); - - if (BIT64_GET(input_mouse, MOUSE_ACTION_BUTTON_L_SET_NAVIGATION)) - { - size_t idx = menu_input->mouse.ptr; - bool scroll = false; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET, &scroll); - } + ret = menu_driver_pointer_tap(menu_input->mouse.x, menu_input->mouse.y, + menu_input->mouse.ptr, cbs, entry, action); } if (BIT64_GET(input_mouse, MOUSE_ACTION_BUTTON_R)) @@ -829,7 +822,7 @@ static int menu_input_mouse_frame( menu_navigation_ctl(MENU_NAVIGATION_CTL_DECREMENT, &decrement_by); } - return 0; + return ret; } static int menu_input_mouse_post_iterate(uint64_t *input_mouse, @@ -1029,7 +1022,9 @@ static int menu_input_pointer_post_iterate(menu_file_list_cbs_t *cbs, if (menu_input->pointer.oldpressed[0]) { if (!menu_input->pointer.dragging) - ret = menu_driver_pointer_tap(cbs, entry, action); + ret = menu_driver_pointer_tap(menu_input->pointer.start_x, + menu_input->pointer.start_y, menu_input->pointer.ptr, + cbs, entry, action); menu_input->pointer.oldpressed[0] = false; menu_input->pointer.start_x = 0; @@ -1075,9 +1070,10 @@ void menu_input_post_iterate(int *ret, unsigned action) menu_entry_get(&entry, 0, selection, NULL, false); if (settings->menu.mouse.enable) - *ret = menu_input_mouse_post_iterate (&menu_input->mouse.state, cbs, action); - - *ret = menu_input_mouse_frame(cbs, &entry, menu_input->mouse.state); + { + *ret = menu_input_mouse_post_iterate(&menu_input->mouse.state, cbs, action); + *ret |= menu_input_mouse_frame(cbs, &entry, menu_input->mouse.state, action); + } if (settings->menu.pointer.enable) *ret |= menu_input_pointer_post_iterate(cbs, &entry, action);