From 8935f2af3ca8b6720e98ecbe25b52c4a56db9bc4 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sun, 24 Mar 2024 21:55:39 +0100 Subject: [PATCH] Make long tap delay customizable and change default to 400ms --- builtin/settingtypes.txt | 15 ++++++++++----- src/defaultsettings.cpp | 3 ++- src/gui/touchscreengui.cpp | 3 ++- src/gui/touchscreengui.h | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index b9c0cda80..8ffb1c3c1 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -157,16 +157,21 @@ invert_hotbar_mouse_wheel (Hotbar: Invert mouse wheel direction) bool false # Requires: !android enable_touch (Enable touchscreen) bool true -# The length in pixels it takes for touchscreen interaction to start. -# -# Requires: touchscreen_gui -touchscreen_threshold (Touchscreen threshold) int 20 0 100 - # Touchscreen sensitivity multiplier. # # Requires: touchscreen_gui touchscreen_sensitivity (Touchscreen sensitivity) float 0.2 0.001 10.0 +# The length in pixels after which a touch interaction is considered movement. +# +# Requires: touchscreen_gui +touchscreen_threshold (Movement threshold) int 20 0 100 + +# The delay in milliseconds after which a touch interaction is considered a long tap. +# +# Requires: touchscreen_gui +touch_long_tap_delay (Threshold for long taps) int 400 100 1000 + # Use crosshair to select object instead of whole screen. # If enabled, a crosshair will be shown and will be used for selecting object. # diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 11b42c779..0907c4c6d 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -485,8 +485,9 @@ void set_default_settings() settings->setDefault("keymap_sneak", "KEY_SHIFT"); #endif - settings->setDefault("touchscreen_threshold", "20"); settings->setDefault("touchscreen_sensitivity", "0.2"); + settings->setDefault("touchscreen_threshold", "20"); + settings->setDefault("touch_long_tap_delay", "400"); settings->setDefault("touch_use_crosshair", "false"); settings->setDefault("fixed_virtual_joystick", "false"); settings->setDefault("virtual_joystick_triggers_aux1", "false"); diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 2d41d4fde..007420b08 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -414,6 +414,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) } m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold"); + m_long_tap_delay = g_settings->getU16("touch_long_tap_delay"); m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick"); m_joystick_triggers_aux1 = g_settings->getBool("virtual_joystick_triggers_aux1"); m_screensize = m_device->getVideoDriver()->getScreenSize(); @@ -999,7 +1000,7 @@ void TouchScreenGUI::step(float dtime) if (m_has_move_id && !m_move_has_really_moved && m_tap_state == TapState::None) { u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs()); - if (delta > MIN_DIG_TIME_MS) { + if (delta > m_long_tap_delay) { m_tap_state = TapState::LongTap; } } diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 1e9aa128d..2ee881b93 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -79,7 +79,6 @@ typedef enum AHBB_Dir_Right_Left } autohide_button_bar_dir; -#define MIN_DIG_TIME_MS 500 #define BUTTON_REPEAT_DELAY 0.2f #define SETTINGS_BAR_Y_OFFSET 5 #define RARE_CONTROLS_BAR_Y_OFFSET 5 @@ -225,6 +224,7 @@ private: v2u32 m_screensize; s32 button_size; double m_touchscreen_threshold; + u16 m_long_tap_delay; bool m_visible; // is the whole touch screen gui visible std::unordered_map> m_hotbar_rects;