From 9c6f780336b79633e6ab5e1ac07af40d25d31af5 Mon Sep 17 00:00:00 2001 From: RGreenlees Date: Sun, 10 Sep 2023 22:18:36 +0100 Subject: [PATCH] Fixed pop-up menu and commander UI cursor centering --- main/source/mod/AvHHud.cpp | 34 +++++++++++++++++++++++++++ main/source/mod/AvHHud.h | 1 + main/source/mod/AvHPieMenuHandler.cpp | 7 ++++++ 3 files changed, 42 insertions(+) diff --git a/main/source/mod/AvHHud.cpp b/main/source/mod/AvHHud.cpp index 1804aed2..17ba2b87 100644 --- a/main/source/mod/AvHHud.cpp +++ b/main/source/mod/AvHHud.cpp @@ -2237,6 +2237,27 @@ void AvHHud::ResetComponentsForUser3() this->GetManager().UnhideComponent(kSelectAllImpulsePanel); //this->GetManager().UnhideComponent(kTopDownHUDTopSpritePanel); //this->GetManager().UnhideComponent(kTopDownHUDBottomSpritePanel); + + if (this->mFramesSinceEnteredTopdownMode > 2) + { + // Workaround for not being able to center mouse with raw input enabled. + if (CVAR_GET_FLOAT("m_rawinput") != 0) + { + if (SDL_GetRelativeMouseMode() != SDL_TRUE) + { + SDL_SetRelativeMouseMode(SDL_TRUE); +#ifdef WIN32 + ShowCursor(TRUE); +#endif + } + } + } + else + { + this->mFramesSinceEnteredTopdownMode++; + } + + } //this->GetManager().UnhideComponent(kReinforcementsLabel); break; @@ -2853,6 +2874,19 @@ int AvHHud::MsgFunc_SetTopDown(const char* pszName, int iSize, void* pbuf) // Switch to top down mode! this->mInTopDownMode = true; this->ShowMouse(); + + // Workaround for not being able to center mouse with raw input enabled. + if (CVAR_GET_FLOAT("m_rawinput") != 0) + { + SDL_SetRelativeMouseMode(SDL_FALSE); + gEngfuncs.pfnSetMousePos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); + } + + this->mFramesSinceEnteredTopdownMode = 0; +#ifdef WIN32 + ShowCursor(FALSE); +#endif + } if(is_top_down) diff --git a/main/source/mod/AvHHud.h b/main/source/mod/AvHHud.h index 17023699..5090f5c3 100644 --- a/main/source/mod/AvHHud.h +++ b/main/source/mod/AvHHud.h @@ -673,6 +673,7 @@ private: float mTimeLastOverwatchPulse; bool mInTopDownMode; + int mFramesSinceEnteredTopdownMode; int mNumLocalSelectEvents; AvHMapMode mMapMode; //@2014 make this work for linux diff --git a/main/source/mod/AvHPieMenuHandler.cpp b/main/source/mod/AvHPieMenuHandler.cpp index cf705879..65e70f09 100644 --- a/main/source/mod/AvHPieMenuHandler.cpp +++ b/main/source/mod/AvHPieMenuHandler.cpp @@ -291,6 +291,13 @@ void AvHPieMenuHandler::cursorMoved(int x,int y,Panel* panel) // char theMessage[128]; // sprintf(theMessage, "AvHPieMenuHandler::cursorMoved %d, %d (panel ptr: %d).\n", x, y, (int)panel); // CenterPrint(theMessage); + if (sPieMenuOpen && CVAR_GET_FLOAT("m_rawinput") != 0) + { + if (SDL_GetRelativeMouseMode() != SDL_TRUE) + { + SDL_SetRelativeMouseMode(SDL_TRUE); + } + } } void AvHPieMenuHandler::cursorEntered(Panel* panel)