Lock the mouse cursor to the rendering window when the user presses F3 key

This commit is contained in:
ergo720 2020-09-20 14:58:11 +02:00
parent cd11b34415
commit 01382d7e1d
3 changed files with 45 additions and 2 deletions

View File

@ -675,6 +675,18 @@ void DrawUEM(HWND hWnd)
EndPaint(hWnd, &ps);
}
void CxbxClipCursor(HWND hWnd)
{
RECT wnd_rect;
GetWindowRect(hWnd, &wnd_rect);
ClipCursor(&wnd_rect);
}
void CxbxReleaseCursor()
{
ClipCursor(nullptr);
}
inline DWORD GetXboxCommonResourceType(const xbox::DWORD XboxResource_Common)
{
DWORD dwCommonType = XboxResource_Common & X_D3DCOMMON_TYPE_MASK;
@ -1928,6 +1940,17 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
{
VertexBufferConverter.PrintStats();
}
else if (wParam == VK_F3)
{
g_bClipCursor = !g_bClipCursor;
if (g_bClipCursor) {
CxbxClipCursor(hWnd);
}
else {
CxbxReleaseCursor();
}
}
else if (wParam == VK_F6)
{
// For some unknown reason, F6 isn't handled in WndMain::WndProc
@ -1990,6 +2013,26 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
}
break;
}
if (g_bClipCursor) {
CxbxClipCursor(hWnd);
}
}
break;
case WM_MOVE:
{
if (g_bClipCursor) {
CxbxClipCursor(hWnd);
}
}
break;
case WM_MOUSEMOVE:
{
if (g_bClipCursor) {
CxbxClipCursor(hWnd);
}
}
break;

View File

@ -112,7 +112,7 @@ size_t g_SystemMaxMemory = 0;
HANDLE g_CurrentProcessHandle = 0; // Set in CxbxKrnlMain
bool g_bIsWine = false;
bool g_bClipCursor = false;
bool g_CxbxPrintUEM = false;
ULONG g_CxbxFatalErrorCode = FATAL_ERROR_NONE;

View File

@ -200,7 +200,7 @@ bool CxbxIsElevated();
extern uint32_t CxbxKrnl_KernelThunkTable[379];
extern bool g_bIsWine;
extern bool g_bClipCursor;
extern bool g_CxbxPrintUEM;
extern ULONG g_CxbxFatalErrorCode;