From 90b005a44ae5e719fa7be21e5b62a77440cc903d Mon Sep 17 00:00:00 2001 From: nukeykt Date: Sat, 14 Sep 2019 23:33:22 +0900 Subject: [PATCH] Fix mouse centering in menu --- source/blood/src/gamemenu.cpp | 10 +++------- source/blood/src/gamemenu.h | 1 - source/build/src/sdlayer.cpp | 5 ++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/source/blood/src/gamemenu.cpp b/source/blood/src/gamemenu.cpp index 45af3c6c1..cb125e259 100644 --- a/source/blood/src/gamemenu.cpp +++ b/source/blood/src/gamemenu.cpp @@ -62,7 +62,6 @@ void CMenuTextMgr::GetFontInfo(int nFont, const char *pString, int *pXSize, int bool CGameMenuMgr::m_bInitialized = false; bool CGameMenuMgr::m_bActive = false; -bool CGameMenuMgr::m_bFirstPush = true; CGameMenuMgr::CGameMenuMgr() { @@ -103,14 +102,11 @@ bool CGameMenuMgr::Push(CGameMenu *pMenu, int nItem) { if (nMenuPointer == 0) { - mouseReadAbs(&m_prevmousepos, &g_mouseAbs); m_mouselastactivity = -M_MOUSETIMEOUT; m_mousewake_watchpoint = 0; mouseLockToWindow(0); - if (m_bFirstPush) - m_bFirstPush = false; - else - mouseMoveToCenter(); + mouseMoveToCenter(); + mouseReadAbs(&m_prevmousepos, &g_mouseAbs); } dassert(pMenu != NULL); if (nMenuPointer == 8) @@ -190,7 +186,7 @@ void CGameMenuMgr::Draw(void) } // Display the mouse cursor, except on touch devices. - if (MOUSEACTIVECONDITION && !m_bFirstPush) + if (MOUSEACTIVECONDITION) { vec2_t cursorpos = { m_mousepos.x + (7 << 16), m_mousepos.y + (6 << 16) }; diff --git a/source/blood/src/gamemenu.h b/source/blood/src/gamemenu.h index 275dcca69..9a245918f 100644 --- a/source/blood/src/gamemenu.h +++ b/source/blood/src/gamemenu.h @@ -462,7 +462,6 @@ class CGameMenuMgr public: static bool m_bInitialized; static bool m_bActive; - static bool m_bFirstPush; CGameMenu *pTempMenu; CGameMenu *pActiveMenu; CGameMenu *pMenuStack[8]; diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 9a6921f38..dee2f9dfd 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -1109,7 +1109,10 @@ void mouseLockToWindow(char a) void mouseMoveToCenter(void) { if (sdl_window) - SDL_WarpMouseInWindow(sdl_window, xdim / 2, ydim / 2); + { + g_mouseAbs = { xdim >> 1, ydim >> 1 }; + SDL_WarpMouseInWindow(sdl_window, g_mouseAbs.x, g_mouseAbs.y); + } } //