diff --git a/configuration.c b/configuration.c index 5bebae629e..62bb385401 100644 --- a/configuration.c +++ b/configuration.c @@ -1226,6 +1226,7 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, #ifdef HAVE_OVERLAY SETTING_BOOL("input_overlay_enable", &settings->bools.input_overlay_enable, true, config_overlay_enable_default(), false); SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, true, false); + SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, false, false); SETTING_BOOL("input_overlay_hide_in_menu", &settings->bools.input_overlay_hide_in_menu, true, overlay_hide_in_menu, false); #endif #ifdef HAVE_COMMAND @@ -1373,6 +1374,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings, #endif SETTING_UINT("bundle_assets_extract_version_current", &settings->uints.bundle_assets_extract_version_current, true, 0, false); SETTING_UINT("bundle_assets_extract_last_version", &settings->uints.bundle_assets_extract_last_version, true, 0, false); + SETTING_UINT("input_overlay_show_physical_inputs_port", &settings->uints.input_overlay_show_physical_inputs_port, true, 0, false); *size = count; diff --git a/configuration.h b/configuration.h index f5dddca28a..9018d965dd 100644 --- a/configuration.h +++ b/configuration.h @@ -88,6 +88,7 @@ typedef struct settings bool input_overlay_enable; bool input_overlay_enable_autopreferred; bool input_overlay_hide_in_menu; + bool input_overlay_show_physical_inputs; bool input_descriptor_label_show; bool input_descriptor_hide_unbound; bool input_all_users_control_menu; @@ -328,6 +329,8 @@ typedef struct settings unsigned camera_width; unsigned camera_height; + + unsigned input_overlay_show_physical_inputs_port; } uints; struct diff --git a/input/input_overlay.c b/input/input_overlay.c index 5cb48e6c50..f67a8432ac 100644 --- a/input/input_overlay.c +++ b/input/input_overlay.c @@ -24,6 +24,7 @@ #ifdef HAVE_CONFIG_H #include "../config.h" #endif +#include "../configuration.h" #ifdef HAVE_MENU #include "../menu/menu_driver.h" @@ -31,8 +32,6 @@ #include "../verbosity.h" #include "../gfx/video_driver.h" - -#include "input_driver.h" #include "input_overlay.h" #define OVERLAY_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1) @@ -69,6 +68,8 @@ struct input_overlay input_overlay_t *overlay_ptr = NULL; +static bool input_overlay_add_inputs(input_overlay_t *ol, + unsigned port, unsigned analog_dpad_mode); /** * input_overlay_scale: * @ol : Overlay handle. @@ -573,8 +574,10 @@ void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad rarch_joypad_info_t joypad_info; input_overlay_state_t old_key_state; unsigned i, j, device; + settings_t *settings = config_get_ptr(); uint16_t key_mod = 0; bool polled = false; + bool button_pressed = false; input_overlay_state_t *ol_state = &ol->overlay_state; if (!ol_state) @@ -702,8 +705,10 @@ void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad default: break; } - - if (polled) + if(settings->bools.input_overlay_show_physical_inputs){ + button_pressed = input_overlay_add_inputs(ol, settings->uints.input_overlay_show_physical_inputs_port, analog_dpad_mode); + } + if (button_pressed || polled) input_overlay_post_poll(ol, opacity); else input_overlay_poll_clear(ol, opacity); @@ -745,4 +750,90 @@ void input_state_overlay(input_overlay_t *ol, int16_t *ret, break; } } +/** + * input_overlay_add_inputs: + * @ol : pointer to overlay + * @port : the user to show the inputs of + * + * Adds inputs from current_input to the overlay, so it's displayed + * returns true if an input that is pressed will change the overlay + */ +static bool input_overlay_add_inputs(input_overlay_t *ol, + unsigned port, unsigned analog_dpad_mode) +{ + int i; + uint64_t mask; + int id; + bool button_pressed = false; + bool current_button_pressed; + input_overlay_state_t *ol_state = &ol->overlay_state; + if(!ol_state) + return false; + + for(i = 0; i < ol->active->size; i++) + { + overlay_desc_t *desc = &(ol->active->descs[i]); + switch(desc->type) + { + case OVERLAY_TYPE_BUTTONS: + mask = desc->key_mask; + id = RETRO_DEVICE_ID_JOYPAD_B; + //Need to check all bits in the mask, multiple ones can be pressed + current_button_pressed = false; + while(mask){ + //Get the next button ID + while(mask && (mask & 1) == 0){ + id+=1; + mask = mask >> 1; + } + //light up the button if pressed + if(input_state(port, RETRO_DEVICE_JOYPAD, 0, id)){ + current_button_pressed = true; + desc->updated = true; + id+=1; + mask = mask >> 1; + }else{ + //One of the buttons not pressed + current_button_pressed = false; + desc->updated = false; + break; + } + } + button_pressed = button_pressed || current_button_pressed; + break; + case OVERLAY_TYPE_ANALOG_LEFT: + case OVERLAY_TYPE_ANALOG_RIGHT: + { + float analog_x, analog_y; + float dx, dy; + unsigned int index = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? + RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT; + + analog_x = input_state(port, RETRO_DEVICE_ANALOG, index, RETRO_DEVICE_ID_ANALOG_X); + analog_y = input_state(port, RETRO_DEVICE_ANALOG, index, RETRO_DEVICE_ID_ANALOG_Y); + dx = (analog_x/0x8000)*(desc->range_x/2); + dy = (analog_y/0x8000)*(desc->range_y/2); + + desc->delta_x = dx; + desc->delta_y = dy; + /*Maybe use some option here instead of 0, only display + changes greater than some magnitude. + */ + if((dx*dx) > 0 || (dy*dy) > 0) + button_pressed = true; + } + break; + case OVERLAY_TYPE_KEYBOARD: + if(input_state(port, RETRO_DEVICE_KEYBOARD, 0, desc->key_mask)){ + desc->updated = true; + button_pressed = true; + } + break; + default: + break; + } + } + + return button_pressed; +} diff --git a/input/input_overlay.h b/input/input_overlay.h index 93f3c83e91..af4305702a 100644 --- a/input/input_overlay.h +++ b/input/input_overlay.h @@ -24,6 +24,8 @@ #include #include +#include "input_driver.h" + RETRO_BEGIN_DECLS #define BOX_RADIAL 0x18df06d2U diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 8b25495454..bb670bbbf1 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -479,6 +479,10 @@ MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_ENABLE, "input_overlay_enable") MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU, "overlay_hide_in_menu") +MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, + "overlay_show_physical_inputs") +MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, + "overlay_show_physical_inputs_port") MSG_HASH(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE, "input_player%u_analog_dpad_mode") MSG_HASH(MENU_ENUM_LABEL_INPUT_POLL_TYPE_BEHAVIOR, diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index 45f4d19841..61b32fe093 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -572,6 +572,16 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len) { "Hide the current overlay from appearing \n" "inside the menu."); break; + case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS: + snprintf(s, len, + "Show keyboard/controller button presses on \n" + "the onscreen overlay."); + break; + case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT: + snprintf(s, len, + "Select the port to listen for controller input \n" + "to display on the onscreen overlay."); + break; case MENU_ENUM_LABEL_OVERLAY_PRESET: snprintf(s, len, "Path to input overlay."); diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 04e4a5ba52..b647b2a679 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -827,6 +827,10 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_ENABLE, "Display Overlay") MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_HIDE_IN_MENU, "Hide Overlay In Menu") +MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, + "Show Inputs On Overlay") +MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, + "Show Inputs Listen Port") MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_POLL_TYPE_BEHAVIOR, "Poll Type Behavior") MSG_HASH(MENU_ENUM_LABEL_VALUE_INPUT_POLL_TYPE_BEHAVIOR_EARLY, @@ -2512,6 +2516,10 @@ MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_FONT_SIZE, "Specify the font size in points.") MSG_HASH(MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_IN_MENU, "Hide the overlay while inside the menu, and show it again when exiting the menu.") +MSG_HASH(MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, + "Show keyboard/controller inputs on the onscreen overlay.") +MSG_HASH(MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, + "Select the port for the overlay to listen to if Show Inputs On Overlay is enabled.") MSG_HASH( MENU_ENUM_SUBLABEL_CONTENT_COLLECTION_LIST, "Scanned content will appear here." diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index cde6bd4a4c..6cc0bd459a 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -225,6 +225,8 @@ default_sublabel_macro(action_bind_sublabel_sort_savefiles_enable, MENU_ default_sublabel_macro(action_bind_sublabel_sort_savestates_enable, MENU_ENUM_SUBLABEL_SORT_SAVESTATES_ENABLE) default_sublabel_macro(action_bind_sublabel_netplay_client_swap_input, MENU_ENUM_SUBLABEL_NETPLAY_CLIENT_SWAP_INPUT) default_sublabel_macro(action_bind_sublabel_core_updater_buildbot_url, MENU_ENUM_SUBLABEL_CORE_UPDATER_BUILDBOT_URL) +default_sublabel_macro(action_bind_sublabel_input_overlay_show_physical_inputs, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS) +default_sublabel_macro(action_bind_sublabel_input_overlay_show_physical_inputs_port, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT) default_sublabel_macro(action_bind_sublabel_core_updater_buildbot_assets_url, MENU_ENUM_SUBLABEL_BUILDBOT_ASSETS_URL) default_sublabel_macro(action_bind_sublabel_core_updater_auto_extract_archive, MENU_ENUM_SUBLABEL_CORE_UPDATER_AUTO_EXTRACT_ARCHIVE) default_sublabel_macro(action_bind_sublabel_netplay_refresh_rooms, MENU_ENUM_SUBLABEL_NETPLAY_REFRESH_ROOMS) @@ -949,6 +951,12 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_hide_in_menu); break; + case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_show_physical_inputs); + break; + case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_show_physical_inputs_port); + break; case MENU_ENUM_LABEL_VIDEO_FONT_SIZE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_font_size); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 5e5538b6c4..f96521cac2 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -5007,6 +5007,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU, PARSE_ONLY_BOOL, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, + PARSE_ONLY_BOOL, false); + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, + PARSE_ONLY_UINT, false); menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_OVERLAY_PRESET, PARSE_ONLY_PATH, false); diff --git a/menu/menu_setting.c b/menu/menu_setting.c index cbeaf4012d..1f9f377b39 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -4891,6 +4891,34 @@ static bool setting_append_list( ); (*list)[list_info->index - 1].change_handler = overlay_enable_toggle_change_handler; + CONFIG_BOOL( + list, list_info, + &settings->bools.input_overlay_show_physical_inputs, + MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, + MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, + false, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE + ); + CONFIG_UINT( + list, list_info, + &settings->uints.input_overlay_show_physical_inputs_port, + MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, + MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, + 0, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler + ); + menu_settings_list_current_add_range(list, list_info, 0, MAX_USERS - 1, 1, true, true); CONFIG_PATH( list, list_info, settings->paths.path_overlay, diff --git a/msg_hash.h b/msg_hash.h index de83221198..4b37e9923a 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -598,6 +598,8 @@ enum msg_hash_enums MENU_LABEL(INPUT_OSK_OVERLAY_ENABLE), MENU_LABEL(INPUT_MENU_ENUM_TOGGLE_GAMEPAD_COMBO), MENU_LABEL(INPUT_OVERLAY_HIDE_IN_MENU), + MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS), + MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT), MENU_LABEL(INPUT_KEYBOARD_GAMEPAD_MAPPING_TYPE), MENU_LABEL(INPUT_SMALL_KEYBOARD_ENABLE), MENU_LABEL(INPUT_TOUCH_ENABLE),