From 43bdb0d5c5ee8c7dd1b8852c94f8a02e0d4834e7 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Tue, 17 Jan 2023 00:05:43 +0100 Subject: [PATCH] AGS: Script API: Mouse.AutoLock From upstream f49501a18b48767184e5f3d5da355405e29ad9e --- engines/ags/engine/ac/mouse.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/engines/ags/engine/ac/mouse.cpp b/engines/ags/engine/ac/mouse.cpp index fb67fb96cc2..19b10d2d5b6 100644 --- a/engines/ags/engine/ac/mouse.cpp +++ b/engines/ags/engine/ac/mouse.cpp @@ -316,6 +316,20 @@ void Mouse_EnableControl(bool on) { _GP(usetup).mouse_ctrl_enabled = on; // remember setting in config } +bool Mouse_IsAutoLocking() { + return _GP(usetup).mouse_auto_lock; +} + +void Mouse_SetAutoLock(bool on) { + _GP(usetup).mouse_auto_lock = on; + if (_GP(scsystem).windowed) { + if (_GP(usetup).mouse_auto_lock) + _GP(mouse).TryLockToWindow(); + else + _GP(mouse).UnlockFromWindow(); + } +} + //============================================================================= int GetMouseCursor() { @@ -546,6 +560,13 @@ RuntimeScriptValue Sc_Mouse_SetControlEnabled(const RuntimeScriptValue *params, API_SCALL_VOID_PBOOL(Mouse_EnableControl); } +RuntimeScriptValue Sc_Mouse_GetAutoLock(const RuntimeScriptValue *params, int32_t param_count) { + API_SCALL_BOOL(Mouse_IsAutoLocking); +} + +RuntimeScriptValue Sc_Mouse_SetAutoLock(const RuntimeScriptValue *params, int32_t param_count) { + API_SCALL_VOID_PBOOL(Mouse_SetAutoLock); +} RuntimeScriptValue Sc_Mouse_GetSpeed(const RuntimeScriptValue *params, int32_t param_count) { API_SCALL_FLOAT(_GP(mouse).GetSpeed); @@ -576,6 +597,8 @@ void RegisterMouseAPI() { ccAddExternalStaticFunction("Mouse::Update^0", Sc_RefreshMouse); ccAddExternalStaticFunction("Mouse::UseDefaultGraphic^0", Sc_set_default_cursor); ccAddExternalStaticFunction("Mouse::UseModeGraphic^1", Sc_set_mouse_cursor); + ccAddExternalStaticFunction("Mouse::get_AutoLock", Sc_Mouse_GetAutoLock); + ccAddExternalStaticFunction("Mouse::set_AutoLock", Sc_Mouse_SetAutoLock); ccAddExternalStaticFunction("Mouse::get_ControlEnabled", Sc_Mouse_GetControlEnabled); ccAddExternalStaticFunction("Mouse::set_ControlEnabled", Sc_Mouse_SetControlEnabled); ccAddExternalStaticFunction("Mouse::get_Mode", Sc_GetCursorMode);