fix mouse centering not working correctly with non-native fullscreen resolutions

This commit is contained in:
pierow 2023-10-01 17:48:57 -04:00
parent dfd82fcec5
commit 61f3c7be61
7 changed files with 59 additions and 10 deletions

View file

@ -34,6 +34,7 @@ public:
int m_iRes; int m_iRes;
cvar_t *m_pCvarStealMouse; cvar_t *m_pCvarStealMouse;
cvar_t *m_pCvarDraw; cvar_t *m_pCvarDraw;
bool m_bWindowed;
int m_iFontHeight; int m_iFontHeight;
int DrawHudNumber(int x, int y, int iFlags, int iNumber, int r, int g, int b ); int DrawHudNumber(int x, int y, int iFlags, int iNumber, int r, int g, int b );

View file

@ -326,6 +326,21 @@ void CHud :: VidInit( void )
gHUD.SetViewport(theViewPort); gHUD.SetViewport(theViewPort);
//Determine if we're playing in windowed mode so we can do mouse centering correctly later.
for (Uint32 id = 0; id < UINT32_MAX; ++id)
{
SDL_Window* theWindow = SDL_GetWindowFromID(id);
if (theWindow)
{
if (!(SDL_GetWindowFlags(theWindow) & SDL_WINDOW_FULLSCREEN))
{
m_bWindowed = true;
}
break;
}
}
if (CVAR_GET_FLOAT("hud_style") == 2.0f) if (CVAR_GET_FLOAT("hud_style") == 2.0f)
{ {
mFont.Load("sprites/nl/font_arial"); mFont.Load("sprites/nl/font_arial");

View file

@ -185,9 +185,16 @@ void ScorePanel::HitTestPanel::internalMousePressed(MouseCode code)
if (SDL_GetRelativeMouseMode() == SDL_TRUE) if (SDL_GetRelativeMouseMode() == SDL_TRUE)
{ {
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
//gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
//Fix for windowed mode centering being incorrect. //Fix for windowed mode centering being incorrect.
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2); if (gHUD.m_bWindowed)
{
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2);
}
else
{
gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
//#ifdef WIN32 //#ifdef WIN32
//ShowCursor(FALSE); //ShowCursor(FALSE);

View file

@ -1524,8 +1524,14 @@ void TeamFortressViewport::HideOptionsMenu()
gHUD.GetManager().SetMouseVisibility(false); gHUD.GetManager().SetMouseVisibility(false);
//gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); if (gHUD.m_bWindowed)
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2); {
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2);
}
else
{
gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
} }
} }

View file

@ -2892,8 +2892,15 @@ int AvHHud::MsgFunc_SetTopDown(const char* pszName, int iSize, void* pbuf)
if (CVAR_GET_FLOAT("m_rawinput") != 0) if (CVAR_GET_FLOAT("m_rawinput") != 0)
{ {
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
//gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2); if (gHUD.m_bWindowed)
{
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2);
}
else
{
gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
#ifdef WIN32 #ifdef WIN32
//Hide windows OS cursor while raw input is momentarily off. //Hide windows OS cursor while raw input is momentarily off.

View file

@ -90,8 +90,14 @@ void AvHParticleEditorHandler::ToggleEdit()
gHUD.ToggleMouse(); gHUD.ToggleMouse();
// Set mouse position to center so it doesn't jar our view // Set mouse position to center so it doesn't jar our view
//gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); if (gHUD.m_bWindowed)
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2); {
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2);
}
else
{
gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
sInEditMode = false; sInEditMode = false;
} }

View file

@ -203,8 +203,15 @@ void AvHPieMenuHandler::OpenPieMenu(void)
if (CVAR_GET_FLOAT("m_rawinput") != 0 && !sPieMenuOpen) if (CVAR_GET_FLOAT("m_rawinput") != 0 && !sPieMenuOpen)
{ {
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
//gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2); if (gHUD.m_bWindowed)
{
gEngfuncs.pfnSetMousePos(ScreenWidth() / 2, ScreenHeight() / 2);
}
else
{
gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
}
} }
// Only do this when in full screen // Only do this when in full screen