Skip to content

Commit 28261db

Browse files
author
nitrocaster
committed
Clip desktop cursor in window mode when game cursor is hidden.
1 parent 2e5489b commit 28261db

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/xrGame/UICursor.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,36 @@ void CUICursor::OnScreenResolutionChanged()
3131
InitInternal ();
3232
}
3333

34+
void CUICursor::Clip(bool clip)
35+
{
36+
HWND hwnd = Device.m_hWnd;
37+
if (hwnd)
38+
{
39+
if (clip)
40+
{
41+
RECT clientRect;
42+
::GetClientRect(hwnd, &clientRect);
43+
::ClientToScreen(hwnd, (LPPOINT)&clientRect.left);
44+
::ClientToScreen(hwnd, (LPPOINT)&clientRect.right);
45+
::ClipCursor(&clientRect);
46+
}
47+
else
48+
::ClipCursor(nullptr);
49+
}
50+
}
51+
52+
void CUICursor::Show()
53+
{
54+
bVisible = true;
55+
Clip(false);
56+
}
57+
58+
void CUICursor::Hide()
59+
{
60+
bVisible = false;
61+
Clip(true);
62+
}
63+
3464
void CUICursor::InitInternal()
3565
{
3666
m_static = xr_new<CUIStatic>();

src/xrGame/UICursor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CUICursor: public pureRender,
2525
virtual void OnScreenResolutionChanged ();
2626

2727
bool IsVisible () {return bVisible;}
28-
void Show () {bVisible = true;}
29-
void Hide () {bVisible = false;}
28+
void Show();
29+
void Hide();
30+
void Clip(bool clip);
3031
};

0 commit comments

Comments
 (0)