Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 8da2323

Browse files
committed
Fix choppy mouse movement in GUIs while in Activity - only warp mouse when on edge of the window
1 parent 3562ee0 commit 8da2323

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Managers/UInputMan.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,18 @@ namespace RTE {
373373
void UInputMan::ForceMouseWithinBox(int x, int y, int width, int height, int whichPlayer) const {
374374
// Only mess with the mouse if the original mouse position is not above the screen and may be grabbing the title bar of the game window.
375375
if (g_WindowMan.AnyWindowHasFocus() && !m_DisableMouseMoving && !m_TrapMousePos && (whichPlayer == Players::NoPlayer || m_ControlScheme.at(whichPlayer).GetDevice() == InputDevice::DEVICE_MOUSE_KEYB)) {
376-
int limitX = std::clamp(static_cast<int>(m_AbsoluteMousePos.m_X), x, x + width);
377-
int limitY = std::clamp(static_cast<int>(m_AbsoluteMousePos.m_Y), y, y + height);
378-
SDL_WarpMouseInWindow(g_WindowMan.GetWindow(), limitX, limitY);
376+
int mousePosX = m_AbsoluteMousePos.GetFloorIntX();
377+
int mousePosY = m_AbsoluteMousePos.GetFloorIntY();
378+
379+
// -1 because the max mouse position inside the window is -1 its dimensions.
380+
int rightMostPos = x + width - 1;
381+
int bottomMostPos = y + height - 1;
382+
383+
if (mousePosX <= x || mousePosX >= rightMostPos || mousePosY <= y || mousePosY >= bottomMostPos) {
384+
int limitX = std::clamp(mousePosX, x, rightMostPos);
385+
int limitY = std::clamp(mousePosY, y, bottomMostPos);
386+
SDL_WarpMouseInWindow(g_WindowMan.GetWindow(), limitX, limitY);
387+
}
379388
}
380389
}
381390

0 commit comments

Comments
 (0)