From 1f4c881c400ae72a4777bad680f8d517e5c8a66e Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 25 Apr 2026 02:43:59 +0200 Subject: [PATCH] touch_sensitivity option --- commandline.cpp | 2 +- config.cpp | 4 ++++ control.cpp | 18 ++++++++++++++---- hypgraph.cpp | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/commandline.cpp b/commandline.cpp index 234eb9f6..879a30f1 100644 --- a/commandline.cpp +++ b/commandline.cpp @@ -326,7 +326,7 @@ int arg::readCommon() { no_find_player = true; game_keys_scroll = true; smooth_scrolling = true; - touchmode = tmode::drag; + touchmode = tmode::info; } else if(argis("-vizhr")) { diff --git a/config.cpp b/config.cpp index 76326ac5..7533ff59 100644 --- a/config.cpp +++ b/config.cpp @@ -1578,6 +1578,8 @@ EX void initConfig() { vid.killreduction = 0; param_b(vid.skipstart, "skip the start menu", false); + param_f(drag_sensitivity, "drag_sensitivity", 0) + ->editable(0, 100, 1, "drag threshold", "Drag automatically on touch movement. Only if quick mouse is off. Set to 0 to disable, large numbers are more sensitive.", 'T'); param_b(vid.quickmouse, "quick mouse", qm) -> help("Buttons activate when they are pressed (by clicking), not when they are released."); @@ -4295,6 +4297,8 @@ EX void configureMouse() { dialog::addBoolItem_action(XLAT("quick mouse"), vid.quickmouse, 'M'); #endif + add_edit(drag_sensitivity); + dialog::addSelItem(XLAT("move by clicking on compass"), its(vid.mobilecompasssize), 'C'); dialog::add_action([] { dialog::editNumber(vid.mobilecompasssize, 0, 100, 10, 20, XLAT("compass size"), XLAT("0 to disable")); diff --git a/control.cpp b/control.cpp index 2312a65f..6de66fc7 100644 --- a/control.cpp +++ b/control.cpp @@ -22,6 +22,7 @@ EX bool targetclick, hiliteclick, forcetarget, numlock_on; EX bool gtouched; EX bool holdmouse; +EX int mouse_state; // 0 = default, 1 = press, 3 = hold, 2 = release EX int getcstat, lgetcstat; EX ld getcshift; @@ -199,6 +200,7 @@ enum class tmode { move, info, drag, fire, ranged }; #endif EX bool touch_interface; +EX ld drag_sensitivity, drag_distance; EX tmode touchmode; EX vector touch_description = { "touch to move", "touch for info", "touch to drag", "touch to aim", "touch for ranged" }; @@ -811,18 +813,21 @@ EX void handleKeyNormal(int sym, int uni) { invalid = touchmode == tmode::fire && !bow::crossbow_mode(); if(!mapeditor::drawplayer && touchmode == tmode::ranged) invalid=true; if(game_keys_scroll && touchmode == tmode::move) invalid=true; + if(drag_sensitivity && touchmode == tmode::drag) invalid=true; } while(invalid); } if(sym == '-' || sym == PSEUDOKEY_WHEELDOWN) { actonrelease = false; - multi::cpid = 0; - if(touchmode == tmode::drag) { + bool adr = drag_sensitivity && !vid.quickmouse && mouse_state != 2; + if(touchmode == tmode::drag || adr) { if(holdmouse) panning(mouseoh, mouseh); + if(!holdmouse) drag_distance = 0; holdmouse = true; + if(adr && drag_distance < 1/drag_sensitivity) actonrelease = true; } else if(touchmode == tmode::info) gotoHelp(help); @@ -1296,6 +1301,7 @@ EX void handle_event(SDL_Event& ev) { int sym = 0; int uni = 0; shiftmul = 1; + mouse_state = 0; /* if(ev.type == SDL_JOYDEVICEADDED || ev.type == SDL_JOYDEVICEREMOVED) { joyx = joyy = 0; @@ -1487,8 +1493,12 @@ EX void handle_event(SDL_Event& ev) { bool up = ev.type == SDL_EVENT_MOUSE_BUTTON_UP; bool act = false; + mouse_state = down ? 1 : up ? 2 : 0; + + bool startdrag = getcstat == '-' && + (touchmode == tmode::drag || (!vid.quickmouse && drag_sensitivity && !was_holdmouse)); - if(vid.quickmouse || getcstat == PSEUDOKEY_LIST_SLIDER || (getcstat == '-' && touchmode == tmode::drag)) { + if(vid.quickmouse || getcstat == PSEUDOKEY_LIST_SLIDER || startdrag) { act = down; } else { @@ -1570,7 +1580,7 @@ EX void handle_event(SDL_Event& ev) { need_mouseh = true; - if(holdmouse && getcstat == '-') sym = uni = getcstat, fix_mouseh(); + if(holdmouse && getcstat == '-') sym = uni = getcstat, fix_mouseh(), mouse_state = 3; if(((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MMASK)) && !mouseout2()) { fix_mouseh(); diff --git a/hypgraph.cpp b/hypgraph.cpp index 8299316f..a2bf8f0a 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -2505,9 +2505,12 @@ EX void resetview() { EX void panning(shiftpoint hf0, shiftpoint ht0) { hyperpoint hf = hf0.h; hyperpoint ht = unshift(ht0, hf0.shift); + ld d = hdist(hf, ht); + if(drag_sensitivity && d < 1/drag_sensitivity && drag_distance == 0) return; View = rgpushxto0(hf) * rgpushxto0(gpushxto0(hf) * ht) * gpushxto0(hf) * View; playermoved = false; currently_scrolling = true; + drag_distance += d; } EX int cells_drawn, cells_generated;