From dbc91ae036f6cb69bd7656837b3faa5d0c00337f Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 4 Nov 2019 23:45:50 +0100 Subject: [PATCH] Correct mouse interactions for game controller --- Source/control.cpp | 4 ++-- SourceS/miniwin/misc.h | 1 + SourceX/controls/plrctrls.cpp | 20 ++++++++++---------- SourceX/miniwin/misc_msg.cpp | 19 ++++++++++++++++--- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 815c8f1e1..b1e4feba5 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1158,7 +1158,7 @@ void DrawInfoBox() } else { if (pcursitem != -1) GetItemStr(pcursitem); - if (pcursobj != -1) + else if (pcursobj != -1) GetObjectStr(pcursobj); if (pcursmonst != -1) { if (leveltype != DTYPE_TOWN) { @@ -1171,7 +1171,7 @@ void DrawInfoBox() } else { PrintMonstHistory(monster[pcursmonst].MType->mtype); } - } else { + } else if (pcursitem == -1) { strcpy(infostr, towner[pcursmonst]._tName); } } diff --git a/SourceS/miniwin/misc.h b/SourceS/miniwin/misc.h index 7a1c8c7ef..42fe67115 100644 --- a/SourceS/miniwin/misc.h +++ b/SourceS/miniwin/misc.h @@ -513,6 +513,7 @@ constexpr auto DVL_WM_PAINT = 0x000F; constexpr auto DVL_WM_CLOSE = 0x0010; constexpr auto DVL_WM_QUERYENDSESSION = 0x0011; constexpr auto DVL_WM_ERASEBKGND = 0x0014; +constexpr auto DVL_WM_MOUSEHOVER = 0x02A1; constexpr auto DVL_WM_QUERYNEWPALETTE = 0x030F; constexpr auto DVL_WM_PALETTECHANGED = 0x0311; diff --git a/SourceX/controls/plrctrls.cpp b/SourceX/controls/plrctrls.cpp index 8f94ea4fe..46a568dbd 100644 --- a/SourceX/controls/plrctrls.cpp +++ b/SourceX/controls/plrctrls.cpp @@ -503,21 +503,21 @@ void plrctrls_after_check_curs_move() // check for monsters first, then items, then towners. if (sgbControllerActive) { // Clear focuse set by cursor - if (!invflag) { - *infostr = '\0'; - ClearPanel(); - } pcursplr = -1; pcursmonst = -1; pcursitem = -1; pcursobj = -1; + if (!invflag) { + *infostr = '\0'; + ClearPanel(); - // TODO target players if !FriendlyMode - if (leveltype != DTYPE_TOWN) - CheckMonstersNearby(); - else - CheckTownersNearby(); - CheckItemsNearby(); + // TODO target players if !FriendlyMode + if (leveltype != DTYPE_TOWN) + CheckMonstersNearby(); + else + CheckTownersNearby(); + CheckItemsNearby(); + } } } diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index 30dc53ce0..3edca66fd 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -19,9 +19,14 @@ namespace dvl { static std::deque message_queue; bool mouseWarping = false; +int mouseWarpingX; +int mouseWarpingY; void SetCursorPos(int X, int Y) { + mouseWarpingX = X; + mouseWarpingY = Y; + #ifndef USE_SDL1 if (renderer) { SDL_Rect view; @@ -37,7 +42,7 @@ void SetCursorPos(int X, int Y) #endif mouseWarping = true; - SDL_WarpMouseInWindow(nullptr, X, Y); + SDL_WarpMouseInWindow(window, X, Y); } // Moves the mouse to the first attribute "+" button. @@ -293,8 +298,6 @@ void SetMouseLMBMessage(const SDL_Event &event, LPMSG lpMsg) // Moves the mouse to the first inventory slot. void FocusOnInventory() { - if (!invflag) - return; SetCursorPos(InvRect[25].X + (INV_SLOT_SIZE_PX / 2), InvRect[25].Y - (INV_SLOT_SIZE_PX / 2)); } @@ -551,6 +554,16 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_CLOSE) { lpMsg->message = DVL_WM_QUERYENDSESSION; + } else if (e.window.event == SDL_WINDOWEVENT_ENTER) { + lpMsg->message = DVL_WM_MOUSEHOVER; + // Bug in SDL, SDL_WarpMouseInWindow doesn't emit SDL_MOUSEMOTION + // and SDL_GetMouseState gives previous location if mouse was + // outside window (observed on Ubuntu 19.04) + if (mouseWarping) { + MouseX = mouseWarpingX; + MouseY = mouseWarpingY; + mouseWarping = false; + } } else { return false_avail(); }