mirror of
https://github.com/LCEMP/LCEMP.git
synced 2026-05-25 18:24:46 +00:00
fix: better cursor handling
This commit is contained in:
@@ -33,6 +33,7 @@ void KeyboardMouseInput::Init()
|
||||
m_mouseWheel = 0;
|
||||
m_mouseWheelAccum = 0;
|
||||
m_mouseGrabbed = false;
|
||||
m_cursorHiddenForUI = false;
|
||||
m_windowFocused = true;
|
||||
m_hasInput = false;
|
||||
|
||||
@@ -106,7 +107,7 @@ void KeyboardMouseInput::Tick()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_mouseGrabbed && g_hWnd)
|
||||
if ((m_mouseGrabbed || m_cursorHiddenForUI) && g_hWnd)
|
||||
{
|
||||
RECT rc;
|
||||
GetClientRect(g_hWnd, &rc);
|
||||
@@ -239,7 +240,36 @@ void KeyboardMouseInput::SetMouseGrabbed(bool grabbed)
|
||||
m_mouseDeltaAccumX = 0;
|
||||
m_mouseDeltaAccumY = 0;
|
||||
}
|
||||
else if (!grabbed && g_hWnd)
|
||||
else if (!grabbed && !m_cursorHiddenForUI && g_hWnd)
|
||||
{
|
||||
while (ShowCursor(TRUE) < 0) {}
|
||||
ClipCursor(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardMouseInput::SetCursorHiddenForUI(bool hidden)
|
||||
{
|
||||
if (m_cursorHiddenForUI == hidden)
|
||||
return;
|
||||
|
||||
m_cursorHiddenForUI = hidden;
|
||||
if (hidden && g_hWnd)
|
||||
{
|
||||
while (ShowCursor(FALSE) >= 0) {}
|
||||
ClipCursorToWindow(g_hWnd);
|
||||
|
||||
RECT rc;
|
||||
GetClientRect(g_hWnd, &rc);
|
||||
POINT center;
|
||||
center.x = (rc.right - rc.left) / 2;
|
||||
center.y = (rc.bottom - rc.top) / 2;
|
||||
ClientToScreen(g_hWnd, ¢er);
|
||||
SetCursorPos(center.x, center.y);
|
||||
|
||||
m_mouseDeltaAccumX = 0;
|
||||
m_mouseDeltaAccumY = 0;
|
||||
}
|
||||
else if (!hidden && !m_mouseGrabbed && g_hWnd)
|
||||
{
|
||||
while (ShowCursor(TRUE) < 0) {}
|
||||
ClipCursor(NULL);
|
||||
@@ -264,7 +294,7 @@ void KeyboardMouseInput::SetWindowFocused(bool focused)
|
||||
m_windowFocused = focused;
|
||||
if (focused)
|
||||
{
|
||||
if (m_mouseGrabbed)
|
||||
if (m_mouseGrabbed || m_cursorHiddenForUI)
|
||||
{
|
||||
while (ShowCursor(FALSE) >= 0) {}
|
||||
ClipCursorToWindow(g_hWnd);
|
||||
|
||||
Reference in New Issue
Block a user