Skip to content

Commit c61cf4c

Browse files
authored
Tweak mouse cursor startup behaviour (#2855)
1 parent 08e1f85 commit c61cf4c

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

Client/core/CCore.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,30 @@ void CCore::SetCenterCursor(bool bEnabled)
894894
m_pSetCursorPosHook->DisableSetCursorPos();
895895
}
896896

897+
// Changes visibility of the system mouse cursor within application window
898+
void CCore::SetSystemCursorVisible(bool bVisible)
899+
{
900+
if (m_pMultiplayer)
901+
{
902+
m_pMultiplayer->AllowWindowsCursorShowing(bVisible);
903+
ShowCursor(bVisible);
904+
}
905+
}
906+
907+
////////////////////////////////////////////////////////////////////////
908+
//
909+
// ShouldShowSystemCursorDuringLoad
910+
//
911+
// Whenever system cursor should be shown during game load.
912+
// It should be if game is being launched in windowed mode or user has multiple monitors and full screen minimize is disabled.
913+
//
914+
////////////////////////////////////////////////////////////////////////
915+
bool CCore::ShouldShowSystemCursorDuringLoad()
916+
{
917+
CVideoModeManagerInterface* pVidMan = GetVideoModeManager();
918+
return pVidMan->IsDisplayModeWindowed() || (pVidMan->IsMultiMonitor() && !pVidMan->IsMinimizeEnabled());
919+
}
920+
897921
////////////////////////////////////////////////////////////////////////
898922
//
899923
// LoadModule
@@ -1020,6 +1044,11 @@ void CCore::DeinitGUI()
10201044
void CCore::InitGUI(IDirect3DDevice9* pDevice)
10211045
{
10221046
m_pGUI = InitModule<CGUI>(m_GUIModule, "GUI", "InitGUIInterface", pDevice);
1047+
1048+
SetSystemCursorVisible(ShouldShowSystemCursorDuringLoad());
1049+
1050+
// Hide GUI mouse cursor during game startup
1051+
m_pGUI->SetCursorEnabled(false);
10231052
}
10241053

10251054
void CCore::CreateGUI()
@@ -1261,6 +1290,9 @@ void CCore::DoPostFramePulse()
12611290
{
12621291
m_bFirstFrame = false;
12631292

1293+
// Make sure system mouse cursor is not visible
1294+
CCore::GetSingletonPtr()->SetSystemCursorVisible(false);
1295+
12641296
// Disable vsync while it's all dark
12651297
m_pGame->DisableVSync();
12661298

Client/core/CCore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
143143
bool IsCursorControlsToggled() { return m_bCursorToggleControls; }
144144
void HideMainMenu();
145145
void SetCenterCursor(bool bEnabled);
146+
void SetSystemCursorVisible(bool bVisible);
147+
bool ShouldShowSystemCursorDuringLoad();
146148

147149
void ShowServerInfo(unsigned int WindowType);
148150

Client/core/CGUI.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ CLocalGUI::CLocalGUI()
4444

4545
m_LastSettingsRevision = -1;
4646
m_LocaleChangeCounter = 0;
47+
48+
m_StoredMousePosition = {-1, -1};
4749
}
4850

4951
CLocalGUI::~CLocalGUI()
@@ -711,8 +713,7 @@ bool CLocalGUI::InputGoesToGUI()
711713

712714
// Here we're supposed to check if things like menues are up, console is up or the chatbox is expecting input
713715
// If the console is visible OR the chat is expecting input OR the mainmenu is visible
714-
return (IsConsoleVisible() || IsMainMenuVisible() || IsChatBoxInputEnabled() || m_bForceCursorVisible || pGUI->GetGUIInputEnabled() ||
715-
!CCore::GetSingleton().IsFocused() || IsWebRequestGUIVisible());
716+
return (IsConsoleVisible() || IsMainMenuVisible() || IsChatBoxInputEnabled() || m_bForceCursorVisible || pGUI->GetGUIInputEnabled() || IsWebRequestGUIVisible());
716717
}
717718

718719
void CLocalGUI::ForceCursorVisible(bool bVisible)
@@ -726,14 +727,18 @@ void CLocalGUI::UpdateCursor()
726727

727728
static DWORD dwWidth = CDirect3DData::GetSingleton().GetViewportWidth();
728729
static DWORD dwHeight = CDirect3DData::GetSingleton().GetViewportHeight();
729-
static bool bFirstRun = true;
730+
static bool bFirstRun = true;
730731

731732
if (bFirstRun)
732733
{
733-
m_StoredMousePosition.x = dwWidth / 2;
734-
m_StoredMousePosition.y = dwHeight / 2;
734+
if (!CCore::GetSingleton().ShouldShowSystemCursorDuringLoad())
735+
{
736+
m_StoredMousePosition.x = dwWidth / 2;
737+
m_StoredMousePosition.y = dwHeight / 2;
738+
}
735739
bFirstRun = false;
736740
}
741+
737742
// Called in each frame to make sure the mouse is only visible when a GUI control that uses the
738743
// mouse requires it.
739744
if (InputGoesToGUI())
@@ -746,7 +751,8 @@ void CLocalGUI::UpdateCursor()
746751
CCore::GetSingleton ().GetGame ()->GetPad ()->Clear ();*/
747752

748753
// Restore the mouse cursor to its old position
749-
SetCursorPos(m_StoredMousePosition.x, m_StoredMousePosition.y);
754+
if (m_StoredMousePosition.x != -1 && m_StoredMousePosition.y != -1)
755+
SetCursorPos(m_StoredMousePosition.x, m_StoredMousePosition.y);
750756

751757
// Enable our mouse cursor
752758
CSetCursorPosHook::GetSingleton().DisableSetCursorPos();

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,9 @@ void CMultiplayerSA::InitHooks()
15581558
// by skipping some entity flag check in CShadows::CastPlayerShadowSectorList()
15591559
MemSet((void*)0x70A4CB, 0x90, 6);
15601560

1561+
// Disable setting system mouse cursor position to the center on game init
1562+
MemSet((void*)0x748A01, 0x90, 0x748A23 - 0x748A01);
1563+
15611564
// Allow vertical camera movement during a camera fade (#411)
15621565
MemPut<BYTE>(0x524084, 0xFF);
15631566
MemPut<BYTE>(0x524089, 0xFF);

0 commit comments

Comments
 (0)