Skip to content

Commit

Permalink
Clip desktop cursor in window mode when game cursor is hidden.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Jan 25, 2016
1 parent 2e5489b commit 28261db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/xrGame/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ void CUICursor::OnScreenResolutionChanged()
InitInternal ();
}

void CUICursor::Clip(bool clip)
{
HWND hwnd = Device.m_hWnd;
if (hwnd)
{
if (clip)
{
RECT clientRect;
::GetClientRect(hwnd, &clientRect);
::ClientToScreen(hwnd, (LPPOINT)&clientRect.left);
::ClientToScreen(hwnd, (LPPOINT)&clientRect.right);
::ClipCursor(&clientRect);
}
else
::ClipCursor(nullptr);
}
}

void CUICursor::Show()
{
bVisible = true;
Clip(false);
}

void CUICursor::Hide()
{
bVisible = false;
Clip(true);
}

void CUICursor::InitInternal()
{
m_static = xr_new<CUIStatic>();
Expand Down
5 changes: 3 additions & 2 deletions src/xrGame/UICursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CUICursor: public pureRender,
virtual void OnScreenResolutionChanged ();

bool IsVisible () {return bVisible;}
void Show () {bVisible = true;}
void Hide () {bVisible = false;}
void Show();
void Hide();
void Clip(bool clip);
};

0 comments on commit 28261db

Please sign in to comment.