Skip to content

Commit e24169e

Browse files
committed
Full fix of cursor clipping in all situations
1 parent 18ef7a0 commit e24169e

File tree

8 files changed

+29
-45
lines changed

8 files changed

+29
-45
lines changed

src/Layers/xrRender/HW.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "stdafx.h"
22

33
#include "Layers/xrRender/HW.h"
4+
#include "xrEngine/xr_input.h"
45
#include "xrEngine/XR_IOConsole.h"
56
#include "xrCore/xr_token.h"
67

@@ -539,13 +540,8 @@ void CHW::updateWindowProps(HWND m_hWnd)
539540
SetWindowLong(m_hWnd, GWL_EXSTYLE, WS_EX_TOPMOST);
540541
}
541542

542-
#ifndef _EDITOR
543543
if (!GEnv.isDedicatedServer)
544-
{
545-
ShowCursor(FALSE);
546544
SetForegroundWindow(m_hWnd);
547-
}
548-
#endif
549545
}
550546

551547
struct uniqueRenderingMode

src/Layers/xrRenderDX10/dx10HW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "stdafx.h"
22

33
#include "Layers/xrRender/HW.h"
4+
#include "xrEngine/xr_input.h"
45
#include "xrEngine/XR_IOConsole.h"
56
#include "xrCore/xr_token.h"
67

@@ -404,7 +405,6 @@ void CHW::updateWindowProps(HWND m_hWnd)
404405
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
405406
}
406407

407-
ShowCursor(FALSE);
408408
SetForegroundWindow(m_hWnd);
409409
}
410410

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma hdrstop
66

77
#include "Layers/xrRender/HW.h"
8+
#include "xrEngine/xr_input.h"
89
#include "xrEngine/XR_IOConsole.h"
910
#include "Include/xrAPI/xrAPI.h"
1011
#include "xrCore/xr_token.h"
@@ -242,7 +243,6 @@ void CHW::updateWindowProps(HWND m_hWnd)
242243
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
243244
}
244245

245-
ShowCursor(FALSE);
246246
SetForegroundWindow(m_hWnd);
247247
}
248248

src/xrEngine/Device_destroy.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
#include "Render.h"
44
#include "IGame_Persistent.h"
55
#include "xr_IOConsole.h"
6+
#include "xr_input.h"
67

78
void CRenderDevice::Destroy()
89
{
910
if (!b_is_Ready)
1011
return;
1112
Log("Destroying Direct3D...");
12-
ShowCursor(true);
13+
pInput->ClipCursor(false);
1314
GEnv.Render->ValidateHW();
1415
GEnv.DU->OnDeviceDestroy();
1516
b_is_Ready = false;
@@ -36,27 +37,33 @@ extern BOOL bNeed_re_create_env;
3637

3738
void CRenderDevice::Reset(bool precache)
3839
{
39-
u32 dwWidth_before = dwWidth;
40-
u32 dwHeight_before = dwHeight;
40+
const auto dwWidth_before = dwWidth;
41+
const auto dwHeight_before = dwHeight;
42+
pInput->ClipCursor(false);
43+
44+
const auto tm_start = TimerAsync();
45+
46+
GEnv.Render->Reset(m_hWnd, dwWidth, dwHeight, fWidth_2, fHeight_2);
4147
GetWindowRect(m_hWnd, &m_rcWindowBounds);
4248
GetClientRect(m_hWnd, &m_rcWindowClient);
43-
ShowCursor(true);
44-
u32 tm_start = TimerAsync();
45-
GEnv.Render->Reset(m_hWnd, dwWidth, dwHeight, fWidth_2, fHeight_2);
49+
4650
if (g_pGamePersistent)
4751
g_pGamePersistent->Environment().bNeed_re_create_env = true;
4852
_SetupStates();
53+
4954
if (precache)
5055
PreCache(20, true, false);
51-
u32 tm_end = TimerAsync();
56+
57+
const auto tm_end = TimerAsync();
5258
Msg("*** RESET [%d ms]", tm_end - tm_start);
59+
5360
// TODO: Remove this! It may hide crash
5461
Memory.mem_compact();
5562

56-
if (!GEnv.isDedicatedServer)
57-
ShowCursor(false);
58-
5963
seqDeviceReset.Process(rp_DeviceReset);
6064
if (dwWidth_before != dwWidth || dwHeight_before != dwHeight)
6165
seqResolutionChanged.Process(rp_ScreenResolutionChanged);
66+
67+
if (!GEnv.isDedicatedServer)
68+
pInput->ClipCursor(true);
6269
}

src/xrEngine/Xr_input.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,15 @@ BOOL CInput::iGetAsyncKeyState(int dik)
345345
BOOL CInput::iGetAsyncBtnState(int btn) { return !!mouseState[btn]; }
346346
void CInput::ClipCursor(bool clip)
347347
{
348-
HWND hwnd = Device.m_hWnd;
349-
if (hwnd)
348+
if (clip)
350349
{
351-
if (clip)
352-
{
353-
RECT clientRect;
354-
::GetClientRect(hwnd, &clientRect);
355-
::ClientToScreen(hwnd, (LPPOINT)&clientRect.left);
356-
::ClientToScreen(hwnd, (LPPOINT)&clientRect.right);
357-
::ClipCursor(&clientRect);
358-
}
359-
else
360-
::ClipCursor(nullptr);
350+
::ClipCursor(&Device.m_rcWindowClient);
351+
while (ShowCursor(FALSE) >= 0) {}
352+
}
353+
else
354+
{
355+
::ClipCursor(nullptr);
356+
while (ShowCursor(TRUE) <= 0) {}
361357
}
362358
}
363359

src/xrEngine/device.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ void CRenderDevice::Run()
368368
GEnv.Render->ClearTarget();
369369
splash::hide();
370370
ShowWindow(m_hWnd, SW_SHOWNORMAL);
371+
pInput->ClipCursor(true);
371372
message_loop();
372373
seqAppEnd.Process(rp_AppEnd);
373374
// Stop Balance-Thread
@@ -493,15 +494,9 @@ void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/)
493494

494495
const BOOL isWndActive = (fActive != WA_INACTIVE && !fMinimized) ? TRUE : FALSE;
495496
if (!editor() && !GEnv.isDedicatedServer && isWndActive)
496-
{
497497
pInput->ClipCursor(true);
498-
ShowCursor(FALSE);
499-
}
500498
else
501-
{
502499
pInput->ClipCursor(false);
503-
ShowCursor(TRUE);
504-
}
505500

506501
extern int ps_always_active;
507502
const BOOL isGameActive = ps_always_active || isWndActive;

src/xrGame/GamePersistent.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,11 @@ void CGamePersistent::OnAppActivate()
745745
bIsMP &= !Device.Paused();
746746

747747
if (!bIsMP)
748-
{
749748
Device.Pause(FALSE, !bRestorePause, TRUE, "CGP::OnAppActivate");
750-
}
751749
else
752-
{
753750
Device.Pause(FALSE, TRUE, TRUE, "CGP::OnAppActivate MP");
754-
}
755751

756752
bEntryFlag = TRUE;
757-
if (!GEnv.isDedicatedServer)
758-
pInput->ClipCursor(GetUICursor().IsVisible());
759753
}
760754

761755
void CGamePersistent::OnAppDeactivate()
@@ -777,7 +771,6 @@ void CGamePersistent::OnAppDeactivate()
777771
Device.Pause(TRUE, FALSE, TRUE, "CGP::OnAppDeactivate MP");
778772
}
779773
bEntryFlag = FALSE;
780-
pInput->ClipCursor(false);
781774
}
782775

783776
bool CGamePersistent::OnRenderPPUI_query()

src/xrGame/UICursor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,16 @@ void CUICursor::OnScreenResolutionChanged()
2929
{
3030
xr_delete(m_static);
3131
InitInternal();
32-
pInput->ClipCursor(IsVisible());
3332
}
3433

3534
void CUICursor::Show()
3635
{
3736
bVisible = true;
38-
pInput->ClipCursor(true);
3937
}
4038

4139
void CUICursor::Hide()
4240
{
4341
bVisible = false;
44-
pInput->ClipCursor(false);
4542
}
4643

4744
void CUICursor::InitInternal()

0 commit comments

Comments
 (0)