Skip to content

Commit

Permalink
Engine: implemented config option for mouse-to-touch emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Mar 5, 2025
1 parent ac06e1b commit b46f1c8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Engine/ac/gamesetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ struct GameConfig
float MouseSpeed = 1.f;
// Touch-to-mouse emulation mode (how the touches are handled overall)
TouchMouseEmulation TouchEmulateMouse = kTouchMouse_None; // touch-to-mouse style
bool TouchMotionRelative = false; // touch control abs/relative mode
bool TouchMotionRelative = false; // touch control abs/relative mode
// Mouse-to-touch emulation (LMB creates touch events)
bool MouseEmulateTouch = false;

// Cache options
size_t SpriteCacheSize = DefSpriteCacheSize; // in KB
Expand Down
5 changes: 5 additions & 0 deletions Engine/device/mousew32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ void Mouse::SetTouch2MouseMode(TouchMouseEmulation mode, bool relative, float sp
ags_touch_set_mouse_emulation(mode, relative, speed);
}

void Mouse::SetMouse2Touch(bool enable)
{
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, enable ? "1" : "0");
}

void Mouse::SetSpeedUnit(float f)
{
SpeedUnit = f;
Expand Down
4 changes: 3 additions & 1 deletion Engine/device/mousew32.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ namespace Mouse
void SetMovementControl(bool on);
// Tell if the mouse movement control is enabled
bool IsControlEnabled();
// Set the touch2mouse motion mode: absolute/relative
// Set the touch2mouse emulation mode and absolute/relative motion mode
void SetTouch2MouseMode(TouchMouseEmulation mode, bool relative, float speed);
// Set the mouse2touch emulation mode
void SetMouse2Touch(bool enable);
// Set base speed factor, which would serve as a mouse speed unit
void SetSpeedUnit(float f);
// Get base speed factor
Expand Down
1 change: 1 addition & 0 deletions Engine/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void load_common_config(const ConfigTree &cfg, GameConfig &setup)
CfgReadString(cfg, "touch", "emul_mouse_mode", "one_finger"),
CstrArr<kNumTouchMouseModes>{ "off", "one_finger", "two_fingers" }, setup.TouchEmulateMouse);
setup.TouchMotionRelative = CfgReadBoolInt(cfg, "touch", "emul_mouse_relative");
setup.MouseEmulateTouch = CfgReadBoolInt(cfg, "touch", "mouse_as_touch", setup.MouseEmulateTouch);

// Translation / localization
setup.Translation = CfgReadString(cfg, "language", "translation");
Expand Down
7 changes: 5 additions & 2 deletions Engine/main/engine_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ void engine_post_gfxmode_mouse_setup(const Size &init_desktop)
Debug::Printf(kDbgMsg_Info, "Mouse speed control: %s, unit: %f, user value: %f",
usetup.MouseCtrlEnabled ? "enabled" : "disabled", Mouse::GetSpeedUnit(), Mouse::GetSpeed());
Mouse::SetTouch2MouseMode(usetup.TouchEmulateMouse, usetup.TouchMotionRelative, usetup.MouseSpeed);
Debug::Printf(kDbgMsg_Info, "Touch-to-mouse motion mode: %s",
usetup.TouchMotionRelative ? "relative" : "absolute");
Mouse::SetMouse2Touch(usetup.MouseEmulateTouch);
const char *emul_mode_names[] = { "none", "one finger", "two fingers" };
Debug::Printf(kDbgMsg_Info, "Touch-to-mouse emulation: %s, motion: %s",
emul_mode_names[usetup.TouchEmulateMouse], usetup.TouchMotionRelative ? "relative" : "absolute");
Debug::Printf(kDbgMsg_Info, "Mouse-to-touch emulation: %s", usetup.MouseEmulateTouch ? "enabled" : "disabled");

on_coordinates_scaling_changed();

Expand Down

0 comments on commit b46f1c8

Please sign in to comment.