Skip to content

Commit 14ef214

Browse files
author
nitrocaster
committed
Move cursor clipping function to CInput.
1 parent 7de32ef commit 14ef214

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/xrEngine/Xr_input.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,24 @@ BOOL CInput::iGetAsyncBtnState(int btn)
352352
return !!mouseState[btn];
353353
}
354354

355+
void CInput::ClipCursor(bool clip)
356+
{
357+
HWND hwnd = Device.m_hWnd;
358+
if (hwnd)
359+
{
360+
if (clip)
361+
{
362+
RECT clientRect;
363+
::GetClientRect(hwnd, &clientRect);
364+
::ClientToScreen(hwnd, (LPPOINT)&clientRect.left);
365+
::ClientToScreen(hwnd, (LPPOINT)&clientRect.right);
366+
::ClipCursor(&clientRect);
367+
}
368+
else
369+
::ClipCursor(nullptr);
370+
}
371+
}
372+
355373
void CInput::MouseUpdate()
356374
{
357375
HRESULT hr;

src/xrEngine/xr_input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ENGINE_API CInput
9090
BOOL iGetAsyncKeyState(int dik);
9191
BOOL iGetAsyncBtnState(int btn);
9292
void iGetLastMouseDelta(Ivector2& p) { p.set(offs[0], offs[1]); }
93+
void ClipCursor(bool clip);
9394

9495
CInput(BOOL bExclusive = true, int deviceForInit = default_key);
9596
~CInput();

src/xrGame/UICursor.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ui/UIStatic.h"
55
#include "ui/UIBtnHint.h"
66
#include "xrEngine/IInputReceiver.h"
7+
#include "xrEngine/xr_input.h"
78

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

@@ -31,34 +32,16 @@ void CUICursor::OnScreenResolutionChanged()
3132
InitInternal ();
3233
}
3334

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-
5235
void CUICursor::Show()
5336
{
5437
bVisible = true;
55-
Clip(false);
38+
pInput->ClipCursor(false);
5639
}
5740

5841
void CUICursor::Hide()
5942
{
6043
bVisible = false;
61-
Clip(true);
44+
pInput->ClipCursor(true);
6245
}
6346

6447
void CUICursor::InitInternal()

src/xrGame/UICursor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ class CUICursor: public pureRender,
2727
bool IsVisible () {return bVisible;}
2828
void Show();
2929
void Hide();
30-
void Clip(bool clip);
3130
};

0 commit comments

Comments
 (0)