Skip to content

Commit

Permalink
Move cursor clipping function to CInput.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Jan 25, 2016
1 parent 7de32ef commit 14ef214
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src/xrEngine/Xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,24 @@ BOOL CInput::iGetAsyncBtnState(int btn)
return !!mouseState[btn];
}

void CInput::ClipCursor(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 CInput::MouseUpdate()
{
HRESULT hr;
Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/xr_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ENGINE_API CInput
BOOL iGetAsyncKeyState(int dik);
BOOL iGetAsyncBtnState(int btn);
void iGetLastMouseDelta(Ivector2& p) { p.set(offs[0], offs[1]); }
void ClipCursor(bool clip);

CInput(BOOL bExclusive = true, int deviceForInit = default_key);
~CInput();
Expand Down
23 changes: 3 additions & 20 deletions src/xrGame/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ui/UIStatic.h"
#include "ui/UIBtnHint.h"
#include "xrEngine/IInputReceiver.h"
#include "xrEngine/xr_input.h"

#define C_DEFAULT color_xrgb(0xff,0xff,0xff)

Expand Down Expand Up @@ -31,34 +32,16 @@ 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);
pInput->ClipCursor(false);
}

void CUICursor::Hide()
{
bVisible = false;
Clip(true);
pInput->ClipCursor(true);
}

void CUICursor::InitInternal()
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/UICursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ class CUICursor: public pureRender,
bool IsVisible () {return bVisible;}
void Show();
void Hide();
void Clip(bool clip);
};

0 comments on commit 14ef214

Please sign in to comment.