Skip to content

Commit

Permalink
Full fix of cursor clipping in all situations
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed May 1, 2018
1 parent 18ef7a0 commit e24169e
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 45 deletions.
6 changes: 1 addition & 5 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"

#include "Layers/xrRender/HW.h"
#include "xrEngine/xr_input.h"
#include "xrEngine/XR_IOConsole.h"
#include "xrCore/xr_token.h"

Expand Down Expand Up @@ -539,13 +540,8 @@ void CHW::updateWindowProps(HWND m_hWnd)
SetWindowLong(m_hWnd, GWL_EXSTYLE, WS_EX_TOPMOST);
}

#ifndef _EDITOR
if (!GEnv.isDedicatedServer)
{
ShowCursor(FALSE);
SetForegroundWindow(m_hWnd);
}
#endif
}

struct uniqueRenderingMode
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"

#include "Layers/xrRender/HW.h"
#include "xrEngine/xr_input.h"
#include "xrEngine/XR_IOConsole.h"
#include "xrCore/xr_token.h"

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

ShowCursor(FALSE);
SetForegroundWindow(m_hWnd);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma hdrstop

#include "Layers/xrRender/HW.h"
#include "xrEngine/xr_input.h"
#include "xrEngine/XR_IOConsole.h"
#include "Include/xrAPI/xrAPI.h"
#include "xrCore/xr_token.h"
Expand Down Expand Up @@ -242,7 +243,6 @@ void CHW::updateWindowProps(HWND m_hWnd)
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
}

ShowCursor(FALSE);
SetForegroundWindow(m_hWnd);
}

Expand Down
27 changes: 17 additions & 10 deletions src/xrEngine/Device_destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#include "Render.h"
#include "IGame_Persistent.h"
#include "xr_IOConsole.h"
#include "xr_input.h"

void CRenderDevice::Destroy()
{
if (!b_is_Ready)
return;
Log("Destroying Direct3D...");
ShowCursor(true);
pInput->ClipCursor(false);
GEnv.Render->ValidateHW();
GEnv.DU->OnDeviceDestroy();
b_is_Ready = false;
Expand All @@ -36,27 +37,33 @@ extern BOOL bNeed_re_create_env;

void CRenderDevice::Reset(bool precache)
{
u32 dwWidth_before = dwWidth;
u32 dwHeight_before = dwHeight;
const auto dwWidth_before = dwWidth;
const auto dwHeight_before = dwHeight;
pInput->ClipCursor(false);

const auto tm_start = TimerAsync();

GEnv.Render->Reset(m_hWnd, dwWidth, dwHeight, fWidth_2, fHeight_2);
GetWindowRect(m_hWnd, &m_rcWindowBounds);
GetClientRect(m_hWnd, &m_rcWindowClient);
ShowCursor(true);
u32 tm_start = TimerAsync();
GEnv.Render->Reset(m_hWnd, dwWidth, dwHeight, fWidth_2, fHeight_2);

if (g_pGamePersistent)
g_pGamePersistent->Environment().bNeed_re_create_env = true;
_SetupStates();

if (precache)
PreCache(20, true, false);
u32 tm_end = TimerAsync();

const auto tm_end = TimerAsync();
Msg("*** RESET [%d ms]", tm_end - tm_start);

// TODO: Remove this! It may hide crash
Memory.mem_compact();

if (!GEnv.isDedicatedServer)
ShowCursor(false);

seqDeviceReset.Process(rp_DeviceReset);
if (dwWidth_before != dwWidth || dwHeight_before != dwHeight)
seqResolutionChanged.Process(rp_ScreenResolutionChanged);

if (!GEnv.isDedicatedServer)
pInput->ClipCursor(true);
}
20 changes: 8 additions & 12 deletions src/xrEngine/Xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,15 @@ BOOL CInput::iGetAsyncKeyState(int dik)
BOOL CInput::iGetAsyncBtnState(int btn) { return !!mouseState[btn]; }
void CInput::ClipCursor(bool clip)
{
HWND hwnd = Device.m_hWnd;
if (hwnd)
if (clip)
{
if (clip)
{
RECT clientRect;
::GetClientRect(hwnd, &clientRect);
::ClientToScreen(hwnd, (LPPOINT)&clientRect.left);
::ClientToScreen(hwnd, (LPPOINT)&clientRect.right);
::ClipCursor(&clientRect);
}
else
::ClipCursor(nullptr);
::ClipCursor(&Device.m_rcWindowClient);
while (ShowCursor(FALSE) >= 0) {}
}
else
{
::ClipCursor(nullptr);
while (ShowCursor(TRUE) <= 0) {}
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ void CRenderDevice::Run()
GEnv.Render->ClearTarget();
splash::hide();
ShowWindow(m_hWnd, SW_SHOWNORMAL);
pInput->ClipCursor(true);
message_loop();
seqAppEnd.Process(rp_AppEnd);
// Stop Balance-Thread
Expand Down Expand Up @@ -493,15 +494,9 @@ void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/)

const BOOL isWndActive = (fActive != WA_INACTIVE && !fMinimized) ? TRUE : FALSE;
if (!editor() && !GEnv.isDedicatedServer && isWndActive)
{
pInput->ClipCursor(true);
ShowCursor(FALSE);
}
else
{
pInput->ClipCursor(false);
ShowCursor(TRUE);
}

extern int ps_always_active;
const BOOL isGameActive = ps_always_active || isWndActive;
Expand Down
7 changes: 0 additions & 7 deletions src/xrGame/GamePersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,11 @@ void CGamePersistent::OnAppActivate()
bIsMP &= !Device.Paused();

if (!bIsMP)
{
Device.Pause(FALSE, !bRestorePause, TRUE, "CGP::OnAppActivate");
}
else
{
Device.Pause(FALSE, TRUE, TRUE, "CGP::OnAppActivate MP");
}

bEntryFlag = TRUE;
if (!GEnv.isDedicatedServer)
pInput->ClipCursor(GetUICursor().IsVisible());
}

void CGamePersistent::OnAppDeactivate()
Expand All @@ -777,7 +771,6 @@ void CGamePersistent::OnAppDeactivate()
Device.Pause(TRUE, FALSE, TRUE, "CGP::OnAppDeactivate MP");
}
bEntryFlag = FALSE;
pInput->ClipCursor(false);
}

bool CGamePersistent::OnRenderPPUI_query()
Expand Down
3 changes: 0 additions & 3 deletions src/xrGame/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ void CUICursor::OnScreenResolutionChanged()
{
xr_delete(m_static);
InitInternal();
pInput->ClipCursor(IsVisible());
}

void CUICursor::Show()
{
bVisible = true;
pInput->ClipCursor(true);
}

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

void CUICursor::InitInternal()
Expand Down

0 comments on commit e24169e

Please sign in to comment.