diff --git a/Makefile.common b/Makefile.common index 2622c46af0..fced34d6fa 100644 --- a/Makefile.common +++ b/Makefile.common @@ -722,7 +722,6 @@ ifeq ($(HAVE_MENU_COMMON), 1) OBJ += menu/menu_driver.o \ menu/menu_content.o \ menu/menu_input.o \ - menu/menu_event.o \ menu/menu_entries.o \ menu/menu_setting.o \ menu/menu_networking.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index e4e05c0096..db3870ff81 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -1137,7 +1137,6 @@ MENU #ifdef HAVE_MENU #include "../menu/menu_driver.c" #include "../menu/menu_input.c" -#include "../menu/menu_event.c" #include "../menu/menu_entries.c" #include "../menu/menu_setting.c" #include "../menu/menu_cbs.c" diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 0c80afa196..c6eb0a901e 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -42,7 +42,7 @@ #include "../menu_driver.h" #include "../menu_animation.h" -#include "../menu_event.h" +#include "../menu_input.h" #include "../widgets/menu_input_dialog.h" #include "../widgets/menu_osk.h" diff --git a/menu/drivers/stripes.c b/menu/drivers/stripes.c index 0170c57e62..c466ed5599 100755 --- a/menu/drivers/stripes.c +++ b/menu/drivers/stripes.c @@ -43,17 +43,17 @@ #include "../menu_driver.h" #include "../menu_animation.h" +#include "../menu_entries.h" +#include "../menu_input.h" #include "../../core_info.h" #include "../../core.h" -#include "../menu_entries.h" + #include "../widgets/menu_entry.h" #include "../widgets/menu_input_dialog.h" #include "../widgets/menu_osk.h" #include "../widgets/menu_filebrowser.h" -#include "../menu_event.h" - #include "../../verbosity.h" #include "../../configuration.h" #include "../../playlist.h" diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index db4a4141a7..86c8d2e4ef 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -43,17 +43,17 @@ #include "../menu_driver.h" #include "../menu_animation.h" +#include "../menu_entries.h" +#include "../menu_input.h" #include "../../core_info.h" #include "../../core.h" -#include "../menu_entries.h" + #include "../widgets/menu_entry.h" #include "../widgets/menu_input_dialog.h" #include "../widgets/menu_osk.h" #include "../widgets/menu_filebrowser.h" -#include "../menu_event.h" - #include "../../verbosity.h" #include "../../configuration.h" #include "../../playlist.h" diff --git a/menu/menu_driver.c b/menu/menu_driver.c index d05085fe1c..5c784bfc9b 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -46,7 +46,7 @@ #include "menu_animation.h" #include "menu_driver.h" #include "menu_cbs.h" -#include "menu_event.h" +#include "menu_input.h" #include "menu_entries.h" #include "widgets/menu_dialog.h" #include "menu_shader.h" diff --git a/menu/menu_event.c b/menu/menu_event.c deleted file mode 100644 index 9d1846d9fc..0000000000 --- a/menu/menu_event.c +++ /dev/null @@ -1,357 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-André Santoni - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#include - -#include "widgets/menu_input_dialog.h" -#include "widgets/menu_osk.h" - -#include "menu_driver.h" -#include "menu_animation.h" - -#include "../configuration.h" -#include "../retroarch.h" -#include "../tasks/tasks_internal.h" - -static unsigned char menu_keyboard_key_state[RETROK_LAST] = {0}; - -/* This function gets called for handling pointer events. - * - * Pointer events are touchscreen events that are spawned - * by touchpad/touchscreen. */ -static int menu_event_pointer(unsigned *action) -{ - rarch_joypad_info_t joypad_info; - int pointer_x, pointer_y; - size_t fb_pitch; - unsigned fb_width, fb_height; - const struct retro_keybind *binds[MAX_USERS] = {NULL}; - const input_driver_t *input_ptr = input_get_ptr(); - void *input_data = input_get_data(); - menu_input_t *menu_input = menu_input_get_ptr(); - int pointer_device = menu_driver_is_texture_set() - ? - RETRO_DEVICE_POINTER : RARCH_DEVICE_POINTER_SCREEN; - - menu_display_get_fb_size(&fb_width, &fb_height, - &fb_pitch); - - joypad_info.joy_idx = 0; - joypad_info.auto_binds = NULL; - joypad_info.axis_threshold = 0.0f; - - pointer_x = - input_ptr->input_state(input_data, joypad_info, binds, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); - pointer_y = - input_ptr->input_state(input_data, joypad_info, binds, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); - - menu_input->pointer.pressed[0] = input_ptr->input_state(input_data, - joypad_info, - binds, - 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); - menu_input->pointer.pressed[1] = input_ptr->input_state(input_data, - joypad_info, - binds, - 0, pointer_device, 1, RETRO_DEVICE_ID_POINTER_PRESSED); - menu_input->pointer.back = input_ptr->input_state(input_data, - joypad_info, - binds, - 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); - - menu_input->pointer.x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; - menu_input->pointer.y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; - - return 0; -} - -/* Check if a specific keyboard key has been pressed. */ -unsigned char menu_event_kb_is_set(enum retro_key key) -{ - return menu_keyboard_key_state[key]; -} - -/* Set a specific keyboard key latch. */ -static void menu_event_kb_set_internal(unsigned idx, unsigned char key) -{ - menu_keyboard_key_state[idx] = key; -} - -/* Set a specific keyboard key. - * - * 'down' sets the latch (true would - * mean the key is being pressed down, while 'false' would mean that - * the key has been released). - **/ -void menu_event_kb_set(bool down, enum retro_key key) -{ - if (key == RETROK_UNKNOWN) - { - unsigned i; - - for (i = 0; i < RETROK_LAST; i++) - menu_event_kb_set_internal(i, (menu_event_kb_is_set((enum retro_key)i) & 1) << 1); - } - else - menu_event_kb_set_internal(key, ((menu_event_kb_is_set(key) & 1) << 1) | down); -} - -/* - * This function gets called in order to process all input events - * for the current frame. - * - * Sends input code to menu for one frame. - * - * It uses as input the local variables' input' and 'trigger_input'. - * - * Mouse and touch input events get processed inside this function. - * - * NOTE: 'input' and 'trigger_input' is sourced from the keyboard and/or - * the gamepad. It does not contain input state derived from the mouse - * and/or touch - this gets dealt with separately within this function. - * - * TODO/FIXME - maybe needs to be overhauled so we can send multiple - * events per frame if we want to, and we shouldn't send the - * entire button state either but do a separate event per button - * state. - */ -unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input) -{ - menu_animation_ctx_delta_t delta; - float delta_time; - /* Used for key repeat */ - static float delay_timer = 0.0f; - static float delay_count = 0.0f; - static unsigned ok_old = 0; - unsigned ret = MENU_ACTION_NOOP; - static bool initial_held = true; - static bool first_held = false; - bool set_scroll = false; - bool mouse_enabled = false; - size_t new_scroll_accel = 0; - menu_input_t *menu_input = NULL; - settings_t *settings = config_get_ptr(); - bool swap_ok_cancel_btns = settings->bools.input_menu_swap_ok_cancel_buttons; - bool input_swap_override = - input_autoconfigure_get_swap_override(); - unsigned menu_ok_btn = (!input_swap_override && - swap_ok_cancel_btns) ? - RETRO_DEVICE_ID_JOYPAD_B : RETRO_DEVICE_ID_JOYPAD_A; - unsigned menu_cancel_btn = (!input_swap_override && - swap_ok_cancel_btns) ? - RETRO_DEVICE_ID_JOYPAD_A : RETRO_DEVICE_ID_JOYPAD_B; - unsigned ok_current = BIT256_GET_PTR(p_input, - menu_ok_btn ); - unsigned ok_trigger = ok_current & ~ok_old; - - ok_old = ok_current; - - if (bits_any_set(p_input->data, ARRAY_SIZE(p_input->data))) - { - if (!first_held) - { - /* don't run anything first frame, only capture held inputs - * for old_input_state. */ - - first_held = true; - delay_timer = initial_held ? 12 : 6; - delay_count = 0; - } - - if (delay_count >= delay_timer) - { - uint32_t input_repeat = 0; - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_UP); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_DOWN); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_LEFT); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_RIGHT); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_L); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_R); - - set_scroll = true; - first_held = false; - p_trigger_input->data[0] |= p_input->data[0] & input_repeat; - - menu_driver_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, - &new_scroll_accel); - - new_scroll_accel = MIN(new_scroll_accel + 1, 64); - } - - initial_held = false; - } - else - { - set_scroll = true; - first_held = false; - initial_held = true; - } - - if (set_scroll) - menu_driver_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, - &new_scroll_accel); - - menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); - - delta.current = delta_time; - - if (menu_animation_get_ideal_delta_time(&delta)) - delay_count += delta.ideal; - - if (menu_input_dialog_get_display_kb()) - { - menu_event_osk_iterate(); - - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_DOWN)) - { - if (menu_event_get_osk_ptr() < 33) - menu_event_set_osk_ptr(menu_event_get_osk_ptr() - + OSK_CHARS_PER_LINE); - } - - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_UP)) - { - if (menu_event_get_osk_ptr() >= OSK_CHARS_PER_LINE) - menu_event_set_osk_ptr(menu_event_get_osk_ptr() - - OSK_CHARS_PER_LINE); - } - - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_RIGHT)) - { - if (menu_event_get_osk_ptr() < 43) - menu_event_set_osk_ptr(menu_event_get_osk_ptr() + 1); - } - - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_LEFT)) - { - if (menu_event_get_osk_ptr() >= 1) - menu_event_set_osk_ptr(menu_event_get_osk_ptr() - 1); - } - - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) - { - if (menu_event_get_osk_idx() > OSK_TYPE_UNKNOWN + 1) - menu_event_set_osk_idx((enum osk_type)( - menu_event_get_osk_idx() - 1)); - else - menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_LAST - 1)); - } - - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) - { - if (menu_event_get_osk_idx() < OSK_TYPE_LAST - 1) - menu_event_set_osk_idx((enum osk_type)( - menu_event_get_osk_idx() + 1)); - else - menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_UNKNOWN + 1)); - } - - if (BIT256_GET_PTR(p_trigger_input, menu_ok_btn)) - { - if (menu_event_get_osk_ptr() >= 0) - menu_event_osk_append(menu_event_get_osk_ptr()); - } - - if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) - input_keyboard_event(true, '\x7f', '\x7f', - 0, RETRO_DEVICE_KEYBOARD); - - /* send return key to close keyboard input window */ - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)) - input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); - - BIT256_CLEAR_ALL_PTR(p_trigger_input); - } - else - { - if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_UP)) - ret = MENU_ACTION_UP; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_DOWN)) - ret = MENU_ACTION_DOWN; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_LEFT)) - ret = MENU_ACTION_LEFT; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_RIGHT)) - ret = MENU_ACTION_RIGHT; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) - ret = MENU_ACTION_SCROLL_UP; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) - ret = MENU_ACTION_SCROLL_DOWN; - else if (ok_trigger) - ret = MENU_ACTION_OK; - else if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) - ret = MENU_ACTION_CANCEL; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_X)) - ret = MENU_ACTION_SEARCH; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_Y)) - ret = MENU_ACTION_SCAN; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)) - ret = MENU_ACTION_START; - else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) - ret = MENU_ACTION_INFO; - else if (BIT256_GET_PTR(p_trigger_input, RARCH_MENU_TOGGLE)) - ret = MENU_ACTION_TOGGLE; - } - - if (menu_event_kb_is_set(RETROK_F11)) - { - command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); - menu_event_kb_set_internal(RETROK_F11, 0); - } - - if (BIT256_GET_PTR(p_trigger_input, RARCH_QUIT_KEY)) - return MENU_ACTION_QUIT; - - mouse_enabled = settings->bools.menu_mouse_enable; -#ifdef HAVE_OVERLAY - if (!mouse_enabled) - mouse_enabled = !(settings->bools.input_overlay_enable - && input_overlay_is_alive(overlay_ptr)); -#endif - - if (!(menu_input = menu_input_get_ptr())) - return 0; - - if (!mouse_enabled) - menu_input->mouse.ptr = 0; - - if (settings->bools.menu_pointer_enable) - menu_event_pointer(&ret); - else - { - menu_input->pointer.x = 0; - menu_input->pointer.y = 0; - menu_input->pointer.dx = 0; - menu_input->pointer.dy = 0; - menu_input->pointer.accel = 0; - menu_input->pointer.pressed[0] = false; - menu_input->pointer.pressed[1] = false; - menu_input->pointer.back = false; - menu_input->pointer.ptr = 0; - } - - return ret; -} diff --git a/menu/menu_event.h b/menu/menu_event.h deleted file mode 100644 index cae9ec381b..0000000000 --- a/menu/menu_event.h +++ /dev/null @@ -1,62 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#ifndef _MENU_EVENT_H -#define _MENU_EVENT_H - -#include -#include - -#include -#include - -RETRO_BEGIN_DECLS - -/* - * This function gets called in order to process all input events - * for the current frame. - * - * Sends input code to menu for one frame. - * - * It uses as input the local variables' input' and 'trigger_input'. - * - * Mouse and touch input events get processed inside this function. - * - * NOTE: 'input' and 'trigger_input' is sourced from the keyboard and/or - * the gamepad. It does not contain input state derived from the mouse - * and/or touch - this gets dealt with separately within this function. - * - * TODO/FIXME - maybe needs to be overhauled so we can send multiple - * events per frame if we want to, and we shouldn't send the - * entire button state either but do a separate event per button - * state. - */ -unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_state); - -/* Set a specific keyboard key. - * - * 'down' sets the latch (true would - * mean the key is being pressed down, while 'false' would mean that - * the key has been released). - **/ -void menu_event_kb_set(bool down, enum retro_key key); - -/* Check if a specific keyboard key has been pressed. */ -unsigned char menu_event_kb_is_set(enum retro_key key); - -RETRO_END_DECLS - -#endif diff --git a/menu/menu_input.c b/menu/menu_input.c index 8fdeb4f106..98d1fc9ed4 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -23,6 +23,8 @@ #include "../config.h" #endif +#include + #include "widgets/menu_input_dialog.h" #include "widgets/menu_input_bind_dialog.h" #include "widgets/menu_osk.h" @@ -30,10 +32,11 @@ #include "menu_driver.h" #include "menu_input.h" #include "menu_animation.h" -#include "menu_event.h" #include "../configuration.h" +#include "../retroarch.h" #include "../performance_counters.h" +#include "../tasks/tasks_internal.h" enum menu_mouse_action { @@ -48,15 +51,329 @@ enum menu_mouse_action MENU_MOUSE_ACTION_HORIZ_WHEEL_DOWN }; +static unsigned char menu_keyboard_key_state[RETROK_LAST] = {0}; + static unsigned mouse_old_x = 0; static unsigned mouse_old_y = 0; +static menu_input_t menu_input_state; static rarch_timer_t mouse_activity_timer = {0}; -menu_input_t *menu_input_get_ptr(void) +/* This function gets called for handling pointer events. + * + * Pointer events are touchscreen events that are spawned + * by touchpad/touchscreen. */ +static int menu_event_pointer(unsigned *action) { - static menu_input_t menu_input_state; - return &menu_input_state; + rarch_joypad_info_t joypad_info; + int pointer_x, pointer_y; + size_t fb_pitch; + unsigned fb_width, fb_height; + const struct retro_keybind *binds[MAX_USERS] = {NULL}; + const input_driver_t *input_ptr = input_get_ptr(); + void *input_data = input_get_data(); + menu_input_t *menu_input = &menu_input_state; + int pointer_device = menu_driver_is_texture_set() + ? + RETRO_DEVICE_POINTER : RARCH_DEVICE_POINTER_SCREEN; + + menu_display_get_fb_size(&fb_width, &fb_height, + &fb_pitch); + + joypad_info.joy_idx = 0; + joypad_info.auto_binds = NULL; + joypad_info.axis_threshold = 0.0f; + + pointer_x = + input_ptr->input_state(input_data, joypad_info, binds, + 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); + pointer_y = + input_ptr->input_state(input_data, joypad_info, binds, + 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); + + menu_input->pointer.pressed[0] = input_ptr->input_state(input_data, + joypad_info, + binds, + 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); + menu_input->pointer.pressed[1] = input_ptr->input_state(input_data, + joypad_info, + binds, + 0, pointer_device, 1, RETRO_DEVICE_ID_POINTER_PRESSED); + menu_input->pointer.back = input_ptr->input_state(input_data, + joypad_info, + binds, + 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); + + menu_input->pointer.x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; + menu_input->pointer.y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; + + return 0; +} + +/* Check if a specific keyboard key has been pressed. */ +unsigned char menu_event_kb_is_set(enum retro_key key) +{ + return menu_keyboard_key_state[key]; +} + +/* Set a specific keyboard key latch. */ +static void menu_event_kb_set_internal(unsigned idx, unsigned char key) +{ + menu_keyboard_key_state[idx] = key; +} + +/* Set a specific keyboard key. + * + * 'down' sets the latch (true would + * mean the key is being pressed down, while 'false' would mean that + * the key has been released). + **/ +void menu_event_kb_set(bool down, enum retro_key key) +{ + if (key == RETROK_UNKNOWN) + { + unsigned i; + + for (i = 0; i < RETROK_LAST; i++) + menu_event_kb_set_internal(i, (menu_event_kb_is_set((enum retro_key)i) & 1) << 1); + } + else + menu_event_kb_set_internal(key, ((menu_event_kb_is_set(key) & 1) << 1) | down); +} + +/* + * This function gets called in order to process all input events + * for the current frame. + * + * Sends input code to menu for one frame. + * + * It uses as input the local variables' input' and 'trigger_input'. + * + * Mouse and touch input events get processed inside this function. + * + * NOTE: 'input' and 'trigger_input' is sourced from the keyboard and/or + * the gamepad. It does not contain input state derived from the mouse + * and/or touch - this gets dealt with separately within this function. + * + * TODO/FIXME - maybe needs to be overhauled so we can send multiple + * events per frame if we want to, and we shouldn't send the + * entire button state either but do a separate event per button + * state. + */ +unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input) +{ + menu_animation_ctx_delta_t delta; + float delta_time; + /* Used for key repeat */ + static float delay_timer = 0.0f; + static float delay_count = 0.0f; + static unsigned ok_old = 0; + unsigned ret = MENU_ACTION_NOOP; + static bool initial_held = true; + static bool first_held = false; + bool set_scroll = false; + bool mouse_enabled = false; + size_t new_scroll_accel = 0; + menu_input_t *menu_input = NULL; + settings_t *settings = config_get_ptr(); + bool swap_ok_cancel_btns = settings->bools.input_menu_swap_ok_cancel_buttons; + bool input_swap_override = + input_autoconfigure_get_swap_override(); + unsigned menu_ok_btn = (!input_swap_override && + swap_ok_cancel_btns) ? + RETRO_DEVICE_ID_JOYPAD_B : RETRO_DEVICE_ID_JOYPAD_A; + unsigned menu_cancel_btn = (!input_swap_override && + swap_ok_cancel_btns) ? + RETRO_DEVICE_ID_JOYPAD_A : RETRO_DEVICE_ID_JOYPAD_B; + unsigned ok_current = BIT256_GET_PTR(p_input, + menu_ok_btn ); + unsigned ok_trigger = ok_current & ~ok_old; + + ok_old = ok_current; + + if (bits_any_set(p_input->data, ARRAY_SIZE(p_input->data))) + { + if (!first_held) + { + /* don't run anything first frame, only capture held inputs + * for old_input_state. */ + + first_held = true; + delay_timer = initial_held ? 12 : 6; + delay_count = 0; + } + + if (delay_count >= delay_timer) + { + uint32_t input_repeat = 0; + BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_UP); + BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_DOWN); + BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_LEFT); + BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_RIGHT); + BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_L); + BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_R); + + set_scroll = true; + first_held = false; + p_trigger_input->data[0] |= p_input->data[0] & input_repeat; + + menu_driver_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, + &new_scroll_accel); + + new_scroll_accel = MIN(new_scroll_accel + 1, 64); + } + + initial_held = false; + } + else + { + set_scroll = true; + first_held = false; + initial_held = true; + } + + if (set_scroll) + menu_driver_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, + &new_scroll_accel); + + menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); + + delta.current = delta_time; + + if (menu_animation_get_ideal_delta_time(&delta)) + delay_count += delta.ideal; + + if (menu_input_dialog_get_display_kb()) + { + menu_event_osk_iterate(); + + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_DOWN)) + { + if (menu_event_get_osk_ptr() < 33) + menu_event_set_osk_ptr(menu_event_get_osk_ptr() + + OSK_CHARS_PER_LINE); + } + + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_UP)) + { + if (menu_event_get_osk_ptr() >= OSK_CHARS_PER_LINE) + menu_event_set_osk_ptr(menu_event_get_osk_ptr() + - OSK_CHARS_PER_LINE); + } + + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_RIGHT)) + { + if (menu_event_get_osk_ptr() < 43) + menu_event_set_osk_ptr(menu_event_get_osk_ptr() + 1); + } + + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_LEFT)) + { + if (menu_event_get_osk_ptr() >= 1) + menu_event_set_osk_ptr(menu_event_get_osk_ptr() - 1); + } + + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) + { + if (menu_event_get_osk_idx() > OSK_TYPE_UNKNOWN + 1) + menu_event_set_osk_idx((enum osk_type)( + menu_event_get_osk_idx() - 1)); + else + menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_LAST - 1)); + } + + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) + { + if (menu_event_get_osk_idx() < OSK_TYPE_LAST - 1) + menu_event_set_osk_idx((enum osk_type)( + menu_event_get_osk_idx() + 1)); + else + menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_UNKNOWN + 1)); + } + + if (BIT256_GET_PTR(p_trigger_input, menu_ok_btn)) + { + if (menu_event_get_osk_ptr() >= 0) + menu_event_osk_append(menu_event_get_osk_ptr()); + } + + if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) + input_keyboard_event(true, '\x7f', '\x7f', + 0, RETRO_DEVICE_KEYBOARD); + + /* send return key to close keyboard input window */ + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)) + input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); + + BIT256_CLEAR_ALL_PTR(p_trigger_input); + } + else + { + if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_UP)) + ret = MENU_ACTION_UP; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_DOWN)) + ret = MENU_ACTION_DOWN; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_LEFT)) + ret = MENU_ACTION_LEFT; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_RIGHT)) + ret = MENU_ACTION_RIGHT; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) + ret = MENU_ACTION_SCROLL_UP; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) + ret = MENU_ACTION_SCROLL_DOWN; + else if (ok_trigger) + ret = MENU_ACTION_OK; + else if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) + ret = MENU_ACTION_CANCEL; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_X)) + ret = MENU_ACTION_SEARCH; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_Y)) + ret = MENU_ACTION_SCAN; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)) + ret = MENU_ACTION_START; + else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) + ret = MENU_ACTION_INFO; + else if (BIT256_GET_PTR(p_trigger_input, RARCH_MENU_TOGGLE)) + ret = MENU_ACTION_TOGGLE; + } + + if (menu_event_kb_is_set(RETROK_F11)) + { + command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); + menu_event_kb_set_internal(RETROK_F11, 0); + } + + if (BIT256_GET_PTR(p_trigger_input, RARCH_QUIT_KEY)) + return MENU_ACTION_QUIT; + + mouse_enabled = settings->bools.menu_mouse_enable; +#ifdef HAVE_OVERLAY + if (!mouse_enabled) + mouse_enabled = !(settings->bools.input_overlay_enable + && input_overlay_is_alive(overlay_ptr)); +#endif + + menu_input = &menu_input_state; + + if (!mouse_enabled) + menu_input->mouse.ptr = 0; + + if (settings->bools.menu_pointer_enable) + menu_event_pointer(&ret); + else + { + menu_input->pointer.x = 0; + menu_input->pointer.y = 0; + menu_input->pointer.dx = 0; + menu_input->pointer.dy = 0; + menu_input->pointer.accel = 0; + menu_input->pointer.pressed[0] = false; + menu_input->pointer.pressed[1] = false; + menu_input->pointer.back = false; + menu_input->pointer.ptr = 0; + } + + return ret; } bool menu_input_mouse_check_vector_inside_hitbox(menu_input_ctx_hitbox_t *hitbox) @@ -76,7 +393,7 @@ bool menu_input_mouse_check_vector_inside_hitbox(menu_input_ctx_hitbox_t *hitbox bool menu_input_ctl(enum menu_input_ctl_state state, void *data) { static bool pointer_dragging = false; - menu_input_t *menu_input = menu_input_get_ptr(); + menu_input_t *menu_input = &menu_input_state; if (!menu_input) return false; @@ -148,7 +465,7 @@ static int menu_input_mouse_post_iterate(uint64_t *input_mouse, { if (!mouse_oldleft) { - menu_input_t *menu_input = menu_input_get_ptr(); + menu_input_t *menu_input = &menu_input_state; size_t selection = menu_navigation_get_selection(); BIT64_SET(*input_mouse, MENU_MOUSE_ACTION_BUTTON_L); @@ -218,7 +535,7 @@ static int menu_input_mouse_frame( uint64_t mouse_state = MENU_MOUSE_ACTION_NONE; int ret = 0; settings_t *settings = config_get_ptr(); - menu_input_t *menu_input = menu_input_get_ptr(); + menu_input_t *menu_input = &menu_input_state; bool mouse_enable = settings->bools.menu_mouse_enable; if (mouse_enable) @@ -340,23 +657,23 @@ static int menu_input_mouse_frame( int16_t menu_input_pointer_state(enum menu_input_pointer_state state) { - menu_input_t *menu = menu_input_get_ptr(); + menu_input_t *menu_input = &menu_input_state; - if (!menu) + if (!menu_input) return 0; switch (state) { case MENU_POINTER_X_AXIS: - return menu->pointer.x; + return menu_input->pointer.x; case MENU_POINTER_Y_AXIS: - return menu->pointer.y; + return menu_input->pointer.y; case MENU_POINTER_DELTA_X_AXIS: - return menu->pointer.dx; + return menu_input->pointer.dx; case MENU_POINTER_DELTA_Y_AXIS: - return menu->pointer.dy; + return menu_input->pointer.dy; case MENU_POINTER_PRESSED: - return menu->pointer.pressed[0]; + return menu_input->pointer.pressed[0]; } return 0; @@ -419,7 +736,7 @@ static int menu_input_pointer_post_iterate( static int16_t pointer_old_x = 0; static int16_t pointer_old_y = 0; int ret = 0; - menu_input_t *menu_input = menu_input_get_ptr(); + menu_input_t *menu_input = &menu_input_state; settings_t *settings = config_get_ptr(); if (!menu_input || !settings) diff --git a/menu/menu_input.h b/menu/menu_input.h index 2c5694eb00..b612b0fe42 100644 --- a/menu/menu_input.h +++ b/menu/menu_input.h @@ -19,7 +19,12 @@ #define _MENU_INPUT_H #include +#include + #include +#include + +#include "../input/input_types.h" RETRO_BEGIN_DECLS @@ -108,6 +113,38 @@ typedef struct menu_input_ctx_hitbox int32_t y2; } menu_input_ctx_hitbox_t; +/* + * This function gets called in order to process all input events + * for the current frame. + * + * Sends input code to menu for one frame. + * + * It uses as input the local variables' input' and 'trigger_input'. + * + * Mouse and touch input events get processed inside this function. + * + * NOTE: 'input' and 'trigger_input' is sourced from the keyboard and/or + * the gamepad. It does not contain input state derived from the mouse + * and/or touch - this gets dealt with separately within this function. + * + * TODO/FIXME - maybe needs to be overhauled so we can send multiple + * events per frame if we want to, and we shouldn't send the + * entire button state either but do a separate event per button + * state. + */ +unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_state); + +/* Set a specific keyboard key. + * + * 'down' sets the latch (true would + * mean the key is being pressed down, while 'false' would mean that + * the key has been released). + **/ +void menu_event_kb_set(bool down, enum retro_key key); + +/* Check if a specific keyboard key has been pressed. */ +unsigned char menu_event_kb_is_set(enum retro_key key); + void menu_input_post_iterate(int *ret, unsigned action); int16_t menu_input_pointer_state(enum menu_input_pointer_state state); @@ -118,8 +155,6 @@ bool menu_input_mouse_check_vector_inside_hitbox(menu_input_ctx_hitbox_t *hitbox bool menu_input_ctl(enum menu_input_ctl_state state, void *data); -menu_input_t *menu_input_get_ptr(void); - RETRO_END_DECLS #endif diff --git a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj index 0fc5f86384..9599a0e8ce 100644 --- a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj +++ b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj @@ -208,7 +208,6 @@ 05A8C54120DB72F000FF7857 /* menu_cbs.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_cbs.c; sourceTree = ""; }; 05A8C54220DB72F000FF7857 /* menu_networking.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_networking.h; sourceTree = ""; }; 05A8C54320DB72F000FF7857 /* menu_driver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_driver.h; sourceTree = ""; }; - 05A8C54420DB72F000FF7857 /* menu_event.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_event.c; sourceTree = ""; }; 05A8C54520DB72F000FF7857 /* menu_entries.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_entries.c; sourceTree = ""; }; 05A8C54620DB72F000FF7857 /* menu_setting.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_setting.c; sourceTree = ""; }; 05A8C54720DB72F000FF7857 /* menu_input.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_input.c; sourceTree = ""; }; @@ -218,7 +217,6 @@ 05A8C54B20DB72F000FF7857 /* menu_animation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_animation.h; sourceTree = ""; }; 05A8C54C20DB72F000FF7857 /* menu_cbs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_cbs.h; sourceTree = ""; }; 05A8C54D20DB72F000FF7857 /* menu_driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_driver.c; sourceTree = ""; }; - 05A8C54E20DB72F000FF7857 /* menu_event.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_event.h; sourceTree = ""; }; 05A8C54F20DB72F000FF7857 /* menu_networking.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = menu_networking.c; sourceTree = ""; }; 05A8C55020DB72F000FF7857 /* menu_input.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_input.h; sourceTree = ""; }; 05A8C55120DB72F000FF7857 /* menu_setting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu_setting.h; sourceTree = ""; }; @@ -760,8 +758,6 @@ 05A8C54320DB72F000FF7857 /* menu_driver.h */, 05A8C54520DB72F000FF7857 /* menu_entries.c */, 05A8C57020DB72F000FF7857 /* menu_entries.h */, - 05A8C54420DB72F000FF7857 /* menu_event.c */, - 05A8C54E20DB72F000FF7857 /* menu_event.h */, 05A8C54720DB72F000FF7857 /* menu_input.c */, 05A8C55020DB72F000FF7857 /* menu_input.h */, 05A8C54F20DB72F000FF7857 /* menu_networking.c */, diff --git a/retroarch.c b/retroarch.c index fed75b385c..5ad9443cd9 100644 --- a/retroarch.c +++ b/retroarch.c @@ -61,7 +61,7 @@ #ifdef HAVE_MENU #include "menu/menu_driver.h" -#include "menu/menu_event.h" +#include "menu/menu_input.h" #include "menu/widgets/menu_dialog.h" #include "menu/widgets/menu_input_dialog.h" #endif