From 14ef2146a5727e75a792dd685c38fae39624d770 Mon Sep 17 00:00:00 2001 From: nitrocaster Date: Mon, 25 Jan 2016 21:22:29 +0300 Subject: [PATCH] Move cursor clipping function to CInput. --- src/xrEngine/Xr_input.cpp | 18 ++++++++++++++++++ src/xrEngine/xr_input.h | 1 + src/xrGame/UICursor.cpp | 23 +++-------------------- src/xrGame/UICursor.h | 1 - 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/xrEngine/Xr_input.cpp b/src/xrEngine/Xr_input.cpp index b7adcdf0074..edfe82b6611 100644 --- a/src/xrEngine/Xr_input.cpp +++ b/src/xrEngine/Xr_input.cpp @@ -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; diff --git a/src/xrEngine/xr_input.h b/src/xrEngine/xr_input.h index bcc830d1e7d..6fe5d9ed4ff 100644 --- a/src/xrEngine/xr_input.h +++ b/src/xrEngine/xr_input.h @@ -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(); diff --git a/src/xrGame/UICursor.cpp b/src/xrGame/UICursor.cpp index 2a1d0f4d738..1388ebe2fd7 100644 --- a/src/xrGame/UICursor.cpp +++ b/src/xrGame/UICursor.cpp @@ -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) @@ -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() diff --git a/src/xrGame/UICursor.h b/src/xrGame/UICursor.h index 6500da6a5f4..adc0c7d65e0 100644 --- a/src/xrGame/UICursor.h +++ b/src/xrGame/UICursor.h @@ -27,5 +27,4 @@ class CUICursor: public pureRender, bool IsVisible () {return bVisible;} void Show(); void Hide(); - void Clip(bool clip); };