diff --git a/main/source/cl_dll/chud.h b/main/source/cl_dll/chud.h index a3715e1b..c3d26efc 100644 --- a/main/source/cl_dll/chud.h +++ b/main/source/cl_dll/chud.h @@ -34,6 +34,7 @@ public: int m_iRes; cvar_t *m_pCvarStealMouse; cvar_t *m_pCvarDraw; + bool m_bWindowed; int m_iFontHeight; int DrawHudNumber(int x, int y, int iFlags, int iNumber, int r, int g, int b ); diff --git a/main/source/cl_dll/hud.cpp b/main/source/cl_dll/hud.cpp index ddeab237..7e480d85 100644 --- a/main/source/cl_dll/hud.cpp +++ b/main/source/cl_dll/hud.cpp @@ -326,6 +326,21 @@ void CHud :: VidInit( void ) 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) { mFont.Load("sprites/nl/font_arial"); diff --git a/main/source/cl_dll/vgui_ScorePanel.cpp b/main/source/cl_dll/vgui_ScorePanel.cpp index 8cb3b1f8..bd9fa8c6 100644 --- a/main/source/cl_dll/vgui_ScorePanel.cpp +++ b/main/source/cl_dll/vgui_ScorePanel.cpp @@ -185,9 +185,16 @@ void ScorePanel::HitTestPanel::internalMousePressed(MouseCode code) if (SDL_GetRelativeMouseMode() == SDL_TRUE) { SDL_SetRelativeMouseMode(SDL_FALSE); - //gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); + //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 //ShowCursor(FALSE); diff --git a/main/source/cl_dll/vgui_TeamFortressViewport.cpp b/main/source/cl_dll/vgui_TeamFortressViewport.cpp index afd4f627..16f288f0 100644 --- a/main/source/cl_dll/vgui_TeamFortressViewport.cpp +++ b/main/source/cl_dll/vgui_TeamFortressViewport.cpp @@ -1524,8 +1524,14 @@ void TeamFortressViewport::HideOptionsMenu() gHUD.GetManager().SetMouseVisibility(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()); + } } } diff --git a/main/source/mod/AvHHud.cpp b/main/source/mod/AvHHud.cpp index e5c6ca30..f400937c 100644 --- a/main/source/mod/AvHHud.cpp +++ b/main/source/mod/AvHHud.cpp @@ -2892,8 +2892,15 @@ int AvHHud::MsgFunc_SetTopDown(const char* pszName, int iSize, void* pbuf) if (CVAR_GET_FLOAT("m_rawinput") != 0) { 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 //Hide windows OS cursor while raw input is momentarily off. diff --git a/main/source/mod/AvHParticleEditorHandler.cpp b/main/source/mod/AvHParticleEditorHandler.cpp index 663e18ce..fb122af1 100644 --- a/main/source/mod/AvHParticleEditorHandler.cpp +++ b/main/source/mod/AvHParticleEditorHandler.cpp @@ -90,8 +90,14 @@ void AvHParticleEditorHandler::ToggleEdit() gHUD.ToggleMouse(); // Set mouse position to center so it doesn't jar our view - //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()); + } sInEditMode = false; } diff --git a/main/source/mod/AvHPieMenuHandler.cpp b/main/source/mod/AvHPieMenuHandler.cpp index 7c5f2780..ef25c164 100644 --- a/main/source/mod/AvHPieMenuHandler.cpp +++ b/main/source/mod/AvHPieMenuHandler.cpp @@ -203,8 +203,15 @@ void AvHPieMenuHandler::OpenPieMenu(void) if (CVAR_GET_FLOAT("m_rawinput") != 0 && !sPieMenuOpen) { 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