From 002928c3990d72200b3f04b3c4615bfe43cc183b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Sat, 4 Mar 2017 15:11:29 +0100 Subject: [PATCH 1/5] (Menu) Separate callbacks for pointer_up and pointer_down --- menu/drivers/materialui.c | 44 ++++++++++++++++++++++++++++++++++++--- menu/menu_driver.c | 26 +++++++++++++++++++++++ menu/menu_driver.h | 8 +++++++ menu/menu_input.c | 13 ++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 1efbab7a96..3998114f1a 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -1898,7 +1898,43 @@ static size_t mui_list_get_selection(void *data) return mui->categories.selection_ptr; } -static int mui_pointer_tap(void *userdata, +static int mui_pointer_down(void *userdata, + unsigned x, unsigned y, + 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; + + if (!mui) + return 0; + + header_height = menu_display_get_header_height(); + video_driver_get_size(&width, &height); + + if (y < header_height) + { + // do nothing + } + else if (y > height - mui->tabs_height) + { + // do nothing + } + else if (ptr <= (menu_entries_get_size() - 1)) + { + size_t idx; + bool scroll = false; + menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + idx = ptr; + menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + } + + return 0; +} + +static int mui_pointer_up(void *userdata, unsigned x, unsigned y, unsigned ptr, menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) @@ -2056,10 +2092,12 @@ menu_ctx_driver_t menu_ctx_mui = { mui_load_image, "glui", mui_environ, - mui_pointer_tap, + NULL, NULL, NULL, mui_osk_ptr_at_pos, NULL, - NULL + NULL, + mui_pointer_down, + mui_pointer_up, }; diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 1ce0cc7e66..f9f21fe8e9 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -883,6 +883,32 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) point->cbs, point->entry, point->action); } break; + case RARCH_MENU_CTL_POINTER_DOWN: + { + menu_ctx_pointer_t *point = (menu_ctx_pointer_t*)data; + if (!menu_driver_ctx || !menu_driver_ctx->pointer_down) + { + point->retcode = 0; + return false; + } + point->retcode = menu_driver_ctx->pointer_down(menu_userdata, + point->x, point->y, point->ptr, + point->cbs, point->entry, point->action); + } + break; + case RARCH_MENU_CTL_POINTER_UP: + { + menu_ctx_pointer_t *point = (menu_ctx_pointer_t*)data; + if (!menu_driver_ctx || !menu_driver_ctx->pointer_up) + { + point->retcode = 0; + return false; + } + point->retcode = menu_driver_ctx->pointer_up(menu_userdata, + point->x, point->y, point->ptr, + point->cbs, point->entry, point->action); + } + break; case RARCH_MENU_CTL_OSK_PTR_AT_POS: { unsigned width = 0; diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 98e965afc6..3f09724aa0 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -137,6 +137,8 @@ enum rarch_menu_ctl_state RARCH_MENU_CTL_ENVIRONMENT, RARCH_MENU_CTL_DRIVER_DATA_GET, RARCH_MENU_CTL_POINTER_TAP, + RARCH_MENU_CTL_POINTER_DOWN, + RARCH_MENU_CTL_POINTER_UP, RARCH_MENU_CTL_OSK_PTR_AT_POS, RARCH_MENU_CTL_BIND_INIT, RARCH_MENU_CTL_UPDATE_THUMBNAIL_PATH, @@ -278,6 +280,12 @@ typedef struct menu_ctx_driver int (*osk_ptr_at_pos)(void *data, int x, int y, unsigned width, unsigned height); void (*update_savestate_thumbnail_path)(void *data, unsigned i); void (*update_savestate_thumbnail_image)(void *data); + int (*pointer_down)(void *data, unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, + menu_entry_t *entry, unsigned action); + int (*pointer_up)(void *data, unsigned x, unsigned y, unsigned ptr, + menu_file_list_cbs_t *cbs, + menu_entry_t *entry, unsigned action); } menu_ctx_driver_t; typedef struct menu_ctx_load_image diff --git a/menu/menu_input.c b/menu/menu_input.c index 0cffbe330c..61786152b6 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -273,6 +273,7 @@ static int menu_input_mouse_frame( } else { + menu_driver_ctl(RARCH_MENU_CTL_POINTER_UP, &point); menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); ret = point.retcode; } @@ -448,6 +449,17 @@ static int menu_input_pointer_post_iterate( pointer_old_x = pointer_x; pointer_old_y = pointer_y; pointer_oldpressed[0] = true; + + menu_ctx_pointer_t point; + + point.x = start_x; + point.y = start_y; + point.ptr = menu_input->pointer.ptr; + point.cbs = cbs; + point.entry = entry; + point.action = action; + + menu_driver_ctl(RARCH_MENU_CTL_POINTER_DOWN, &point); } else if (abs(pointer_x - start_x) > (dpi / 10) || abs(pointer_y - start_y) > (dpi / 10)) @@ -495,6 +507,7 @@ static int menu_input_pointer_post_iterate( } else { + menu_driver_ctl(RARCH_MENU_CTL_POINTER_UP, &point); menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); ret = point.retcode; } From 013bf29fff890145fe5202a81377bfdfe2301d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Sat, 4 Mar 2017 15:35:05 +0100 Subject: [PATCH 2/5] (Menu) A long press will reset a setting to its default value --- menu/menu_input.c | 20 +++++++++++++++++--- menu/menu_input.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/menu/menu_input.c b/menu/menu_input.c index 61786152b6..e11adad36b 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -439,6 +439,8 @@ static int menu_input_pointer_post_iterate( video_context_driver_get_metrics(&metrics); + menu_input->pointer.counter++; + if (!pointer_oldpressed[0]) { menu_input->pointer.accel = 0; @@ -507,9 +509,20 @@ static int menu_input_pointer_post_iterate( } else { - menu_driver_ctl(RARCH_MENU_CTL_POINTER_UP, &point); - menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); - ret = point.retcode; + if (menu_input->pointer.counter > 32) + { + size_t selection; + menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); + if (cbs && cbs->action_start) + return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_START); + + } + else + { + menu_driver_ctl(RARCH_MENU_CTL_POINTER_UP, &point); + menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); + ret = point.retcode; + } } } @@ -520,6 +533,7 @@ static int menu_input_pointer_post_iterate( pointer_old_y = 0; menu_input->pointer.dx = 0; menu_input->pointer.dy = 0; + menu_input->pointer.counter = 0; menu_input_ctl(MENU_INPUT_CTL_UNSET_POINTER_DRAGGED, NULL); } diff --git a/menu/menu_input.h b/menu/menu_input.h index cec5559b77..7efac468f3 100644 --- a/menu/menu_input.h +++ b/menu/menu_input.h @@ -98,6 +98,7 @@ typedef struct menu_input bool pressed[2]; bool back; unsigned ptr; + unsigned counter; } pointer; } menu_input_t; From bb0d4dae074cdfdb441f85716dd3bd0234b6f1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Sat, 4 Mar 2017 22:16:55 +0100 Subject: [PATCH 3/5] (Menu) iOS touch fixes --- menu/drivers/materialui.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 3998114f1a..70060caa07 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -1903,7 +1903,6 @@ static int mui_pointer_down(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; @@ -1924,11 +1923,18 @@ static int mui_pointer_down(void *userdata, } else if (ptr <= (menu_entries_get_size() - 1)) { - size_t idx; - bool scroll = false; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); - idx = ptr; - menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SELECTION, &idx); + size_t ii = 0; + file_list_t *list = menu_entries_get_selection_buf_ptr(0); + for (ii = 0; ii < menu_entries_get_size(); ii++) + { + mui_node_t *node = (mui_node_t*) + menu_entries_get_userdata_at_offset(list, ii); + + 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); + } } return 0; @@ -1984,11 +1990,6 @@ static int mui_pointer_up(void *userdata, menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &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_ctl(MENU_NAVIGATION_CTL_SET, &scroll); } return 0; From 199d7b63a115b145b7c4fd9c73da372aafed970f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Sun, 5 Mar 2017 00:15:21 +0100 Subject: [PATCH 4/5] (Menu) Attempt to fix scroll speed issue --- menu/drivers/materialui.c | 2 +- menu/menu_input.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 70060caa07..953f231935 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -608,7 +608,7 @@ static void mui_render(void *data) menu_input_ctl(MENU_INPUT_CTL_POINTER_ACCEL_READ, &old_accel_val); - mui->scroll_y -= old_accel_val / 60.0; + mui->scroll_y -= old_accel_val; new_accel_val = old_accel_val * 0.96; diff --git a/menu/menu_input.c b/menu/menu_input.c index e11adad36b..e55c5ccfbf 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -476,8 +476,7 @@ static int menu_input_pointer_post_iterate( menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); - s = (menu_input->pointer.dy * 550000000.0 ) / - ( dpi * delta_time ); + s = menu_input->pointer.dy; menu_input->pointer.accel = (accel0 + accel1 + s) / 3; accel0 = accel1; accel1 = menu_input->pointer.accel; From 130e3a77d80f726bd7a7275fde65465adcd58482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Sun, 5 Mar 2017 09:49:22 +0100 Subject: [PATCH 5/5] (GLUI) Fix the menu entry being selected while we try to scroll --- menu/drivers/materialui.c | 67 +++++++++++---------------------------- 1 file changed, 19 insertions(+), 48 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 953f231935..d2fe2ef76c 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -1898,48 +1898,6 @@ static size_t mui_list_get_selection(void *data) return mui->categories.selection_ptr; } -static int mui_pointer_down(void *userdata, - unsigned x, unsigned y, - unsigned ptr, menu_file_list_cbs_t *cbs, - menu_entry_t *entry, unsigned action) -{ - unsigned width, height; - unsigned header_height, i; - mui_handle_t *mui = (mui_handle_t*)userdata; - - if (!mui) - return 0; - - header_height = menu_display_get_header_height(); - video_driver_get_size(&width, &height); - - if (y < header_height) - { - // do nothing - } - else if (y > height - mui->tabs_height) - { - // do nothing - } - else if (ptr <= (menu_entries_get_size() - 1)) - { - size_t ii = 0; - file_list_t *list = menu_entries_get_selection_buf_ptr(0); - for (ii = 0; ii < menu_entries_get_size(); ii++) - { - mui_node_t *node = (mui_node_t*) - menu_entries_get_userdata_at_offset(list, ii); - - 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); - } - } - - return 0; -} - static int mui_pointer_up(void *userdata, unsigned x, unsigned y, unsigned ptr, menu_file_list_cbs_t *cbs, @@ -1985,11 +1943,24 @@ static int mui_pointer_up(void *userdata, } else if (ptr <= (menu_entries_get_size() - 1)) { - size_t idx; - bool scroll = false; - menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); - if (ptr == selection && cbs && cbs->action_select) - return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_SELECT); + size_t ii = 0; + file_list_t *list = menu_entries_get_selection_buf_ptr(0); + for (ii = 0; ii < menu_entries_get_size(); ii++) + { + mui_node_t *node = (mui_node_t*) + menu_entries_get_userdata_at_offset(list, ii); + + 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); + if (ptr == ii && cbs && cbs->action_select) + return menu_entry_action(entry, (unsigned)ii, MENU_ACTION_SELECT); + } + } + + } return 0; @@ -2099,6 +2070,6 @@ menu_ctx_driver_t menu_ctx_mui = { mui_osk_ptr_at_pos, NULL, NULL, - mui_pointer_down, + NULL, mui_pointer_up, };