diff --git a/config.def.h b/config.def.h index c5bc18f575..cd9c39e2c5 100644 --- a/config.def.h +++ b/config.def.h @@ -62,6 +62,8 @@ #define DEFAULT_MOUSE_SCALE 1 #endif +#define DEFAULT_TOUCH_SCALE 1 + #if defined(RARCH_MOBILE) || defined(HAVE_LIBNX) || defined(__WINRT__) #define DEFAULT_POINTER_ENABLE true #else diff --git a/configuration.c b/configuration.c index 5628c71df5..15eaf0b75c 100644 --- a/configuration.c +++ b/configuration.c @@ -1888,6 +1888,7 @@ static struct config_uint_setting *populate_settings_uint( #ifdef GEKKO SETTING_UINT("input_mouse_scale", &settings->uints.input_mouse_scale, true, DEFAULT_MOUSE_SCALE, false); #endif + SETTING_UINT("input_touch_scale", &settings->uints.input_touch_scale, true, DEFAULT_TOUCH_SCALE, false); #if defined(DINGUX) && defined(HAVE_LIBSHAKE) SETTING_UINT("input_dingux_rumble_gain", &settings->uints.input_dingux_rumble_gain, true, DEFAULT_DINGUX_RUMBLE_GAIN, false); #endif diff --git a/configuration.h b/configuration.h index 6784853a6f..e8a2fe10d8 100644 --- a/configuration.h +++ b/configuration.h @@ -151,6 +151,7 @@ typedef struct settings #ifdef GEKKO unsigned input_mouse_scale; #endif + unsigned input_touch_scale; unsigned input_hotkey_block_delay; unsigned input_menu_toggle_gamepad_combo; unsigned input_keyboard_gamepad_mapping_type; diff --git a/input/input_overlay.h b/input/input_overlay.h index d9ae1638cc..3f9052aba3 100644 --- a/input/input_overlay.h +++ b/input/input_overlay.h @@ -217,6 +217,7 @@ typedef struct float y_separation_portrait; float x_offset_portrait; float y_offset_portrait; + float touch_scale; bool auto_scale; } overlay_layout_desc_t; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index a8234cd6e9..35086b378b 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -1410,6 +1410,10 @@ MSG_HASH( "input_mouse_scale" ) #endif +MSG_HASH( + MENU_ENUM_LABEL_INPUT_TOUCH_SCALE, + "input_touch_scale" + ) MSG_HASH( MENU_ENUM_LABEL_INPUT_BIND_MODE, "input_bind_mode" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index da4d0aefe7..eadeea9b9d 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -12207,6 +12207,14 @@ MSG_HASH( "Adjust x/y scale for Wiimote light gun speed." ) #endif +MSG_HASH( + MENU_ENUM_LABEL_VALUE_INPUT_TOUCH_SCALE, + "Touch Scale" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_INPUT_TOUCH_SCALE, + "Adjust x/y scale of touchscreen coordinates to accommodate OS-level display scaling." + ) #ifdef HAVE_ODROIDGO2 MSG_HASH( MENU_ENUM_LABEL_VALUE_VIDEO_RGA_SCALING, diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 6d8a890b70..af4ca4e88b 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -343,6 +343,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_audio_sync, MENU_ #if defined(GEKKO) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_mouse_scale, MENU_ENUM_SUBLABEL_INPUT_MOUSE_SCALE) #endif +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_touch_scale, MENU_ENUM_SUBLABEL_INPUT_TOUCH_SCALE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_axis_threshold, MENU_ENUM_SUBLABEL_INPUT_BUTTON_AXIS_THRESHOLD) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_turbo_period, MENU_ENUM_SUBLABEL_INPUT_TURBO_PERIOD) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_duty_cycle, MENU_ENUM_SUBLABEL_INPUT_DUTY_CYCLE) @@ -3398,6 +3399,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_mouse_scale); break; #endif + case MENU_ENUM_LABEL_INPUT_TOUCH_SCALE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_touch_scale); + break; case MENU_ENUM_LABEL_AUDIO_SYNC: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_audio_sync); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 44bae10f69..5d9beb12ce 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -6128,6 +6128,10 @@ unsigned menu_displaylist_build_list( PARSE_ONLY_UINT, false) == 0) count++; #endif + if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, + MENU_ENUM_LABEL_INPUT_TOUCH_SCALE, + PARSE_ONLY_UINT, false) == 0) + count++; if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, MENU_ENUM_LABEL_INPUT_ANALOG_DEADZONE, PARSE_ONLY_FLOAT, false) == 0) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 21d707dfab..7496a0b8bf 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -6388,6 +6388,13 @@ static void setting_get_string_representation_poll_type_behavior( } } +static void setting_get_string_representation_input_touch_scale(rarch_setting_t *setting, + char *s, size_t len) +{ + if (setting) + snprintf(s, len, "x%d", *setting->value.target.unsigned_integer); +} + #ifdef HAVE_LANGEXTRA static void setting_get_string_representation_uint_user_language( rarch_setting_t *setting, @@ -12051,6 +12058,23 @@ static bool setting_append_list( menu_settings_list_current_add_range(list, list_info, 1, 4, 1, true, true); #endif + CONFIG_UINT( + list, list_info, + &settings->uints.input_touch_scale, + MENU_ENUM_LABEL_INPUT_TOUCH_SCALE, + MENU_ENUM_LABEL_VALUE_INPUT_TOUCH_SCALE, + DEFAULT_TOUCH_SCALE, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; + (*list)[list_info->index - 1].get_string_representation = + &setting_get_string_representation_input_touch_scale; + (*list)[list_info->index - 1].offset_by = 1; + menu_settings_list_current_add_range(list, list_info, 1, 4, 1, true, true); + #ifdef VITA CONFIG_BOOL( list, list_info, diff --git a/msg_hash.h b/msg_hash.h index cc808d6e21..4ddad948a7 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -953,6 +953,7 @@ enum msg_hash_enums #if defined(GEKKO) MENU_LABEL(INPUT_MOUSE_SCALE), #endif + MENU_LABEL(INPUT_TOUCH_SCALE), MENU_LABEL(INPUT_ANALOG_DEADZONE), MENU_LABEL(INPUT_ANALOG_SENSITIVITY), MENU_LABEL(INPUT_BIND_TIMEOUT), diff --git a/retroarch.c b/retroarch.c index 519ad87c0d..681741f69a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -13981,6 +13981,7 @@ bool command_event(enum event_command cmd, void *data) layout_desc.y_separation_portrait = settings->floats.input_overlay_y_separation_portrait; layout_desc.x_offset_portrait = settings->floats.input_overlay_x_offset_portrait; layout_desc.y_offset_portrait = settings->floats.input_overlay_y_offset_portrait; + layout_desc.touch_scale = (float)settings->uints.input_touch_scale; layout_desc.auto_scale = settings->bools.input_overlay_auto_scale; input_overlay_set_scale_factor(p_rarch, p_rarch->overlay_ptr, &layout_desc); @@ -21077,7 +21078,7 @@ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y) static void input_overlay_poll( input_overlay_t *ol, input_overlay_state_t *out, - int16_t norm_x, int16_t norm_y) + int16_t norm_x, int16_t norm_y, float touch_scale) { size_t i; @@ -21091,6 +21092,9 @@ static void input_overlay_poll( x /= ol->active->mod_w; y /= ol->active->mod_h; + x *= touch_scale; + y *= touch_scale; + for (i = 0; i < ol->active->size; i++) { float x_dist, y_dist; @@ -21404,6 +21408,7 @@ static void input_poll_overlay( settings_t *settings = p_rarch->configuration_settings; bool input_overlay_show_physical_inputs = settings->bools.input_overlay_show_physical_inputs; unsigned input_overlay_show_physical_inputs_port = settings->uints.input_overlay_show_physical_inputs_port; + float touch_scale = (float)settings->uints.input_touch_scale; if (!ol_state) return; @@ -21471,7 +21476,7 @@ static void input_poll_overlay( memset(&polled_data, 0, sizeof(struct input_overlay_state)); if (ol->enable) - input_overlay_poll(ol, &polled_data, x, y); + input_overlay_poll(ol, &polled_data, x, y, touch_scale); else ol->blocked = false; @@ -21605,6 +21610,8 @@ static void retroarch_overlay_init(struct rarch_state *p_rarch) float overlay_y_separation_portrait = settings->floats.input_overlay_y_separation_portrait; float overlay_x_offset_portrait = settings->floats.input_overlay_x_offset_portrait; float overlay_y_offset_portrait = settings->floats.input_overlay_y_offset_portrait; + float overlay_touch_scale = (float)settings->uints.input_touch_scale; + bool load_enabled = input_overlay_enable; #ifdef HAVE_MENU bool overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu; @@ -21649,6 +21656,7 @@ static void retroarch_overlay_init(struct rarch_state *p_rarch) layout_desc.y_separation_portrait = overlay_y_separation_portrait; layout_desc.x_offset_portrait = overlay_x_offset_portrait; layout_desc.y_offset_portrait = overlay_y_offset_portrait; + layout_desc.touch_scale = overlay_touch_scale; layout_desc.auto_scale = input_overlay_auto_scale; task_push_overlay_load_default(input_overlay_loaded, @@ -23007,6 +23015,7 @@ static void menu_input_get_touchscreen_hw_state( static bool last_cancel_pressed = false; bool overlay_active = false; bool pointer_enabled = settings->bools.menu_pointer_enable; + unsigned input_touch_scale = settings->uints.input_touch_scale; #ifdef HAVE_MFI const input_device_driver_t *sec_joypad = p_rarch->sec_joypad; @@ -23066,7 +23075,8 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->keyboard_mapping_blocked, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); - hw_state->x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; + hw_state->x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; + hw_state->x *= input_touch_scale; /* > An annoyance - we get different starting positions * depending upon whether pointer_device is @@ -23096,7 +23106,8 @@ static void menu_input_get_touchscreen_hw_state( p_rarch->keyboard_mapping_blocked, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); - hw_state->y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; + hw_state->y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; + hw_state->y *= input_touch_scale; if (pointer_device == RARCH_DEVICE_POINTER_SCREEN) {