Skip to content

Commit

Permalink
Make long tap delay customizable and change default to 400ms
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Mar 30, 2024
1 parent 517f160 commit 8935f2a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions builtin/settingtypes.txt
Expand Up @@ -157,15 +157,20 @@ 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.
# Touchscreen sensitivity multiplier.
#
# Requires: touchscreen_gui
touchscreen_threshold (Touchscreen threshold) int 20 0 100
touchscreen_sensitivity (Touchscreen sensitivity) float 0.2 0.001 10.0

# Touchscreen sensitivity multiplier.
# The length in pixels after which a touch interaction is considered movement.
#
# Requires: touchscreen_gui
touchscreen_sensitivity (Touchscreen sensitivity) float 0.2 0.001 10.0
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.
Expand Down
3 changes: 2 additions & 1 deletion src/defaultsettings.cpp
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/gui/touchscreengui.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/touchscreengui.h
Expand Up @@ -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
Expand Down Expand Up @@ -225,6 +224,7 @@ class TouchScreenGUI
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<u16, rect<s32>> m_hotbar_rects;
Expand Down

0 comments on commit 8935f2a

Please sign in to comment.