From fd9f2099d04ad1bcb5209932f4160f1041e12feb Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Sat, 5 Jun 2021 22:15:15 -0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Leverage=20'Point'=20to=20?= =?UTF-8?q?represent=20mouse=20position?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/DiabloUI/diabloui.cpp | 5 +-- Source/control.cpp | 80 ++++++++++++++++++------------------ Source/controls/plrctrls.cpp | 34 +++++++-------- Source/cursor.cpp | 14 +++---- Source/diablo.cpp | 69 +++++++++++++++---------------- Source/diablo.h | 3 +- Source/gmenu.cpp | 20 ++++----- Source/inv.cpp | 18 ++++---- Source/miniwin/misc_msg.cpp | 7 ++-- Source/movie.cpp | 4 +- Source/player.cpp | 6 +-- Source/qol/itemlabels.cpp | 8 ++-- Source/qol/xpbar.cpp | 2 +- Source/quests.cpp | 2 +- Source/scrollrt.cpp | 16 ++++---- Source/stores.cpp | 10 ++--- Source/trigs.cpp | 2 +- 17 files changed, 147 insertions(+), 153 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index ec9370ebd..7c7ba6606 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -374,8 +374,7 @@ void UiHandleEvents(SDL_Event *event) #ifdef USE_SDL1 OutputToLogical(&event->motion.x, &event->motion.y); #endif - MouseX = event->motion.x; - MouseY = event->motion.y; + MousePosition = { event->motion.x, event->motion.y }; return; } @@ -969,6 +968,6 @@ void DrawMouse() if (IsHardwareCursor() || sgbControllerActive) return; - DrawArt(MouseX, MouseY, &ArtCursor); + DrawArt(MousePosition.x, MousePosition.y, &ArtCursor); } } // namespace devilution diff --git a/Source/control.cpp b/Source/control.cpp index e9bc4fc2b..bd284d39c 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -389,7 +389,7 @@ void DrawSpellList(const CelOutputBuffer &out) DrawSpellCel(out, location, *pSpellCels, SpellITbl[j]); int lx = x; int ly = y - SPLICONLENGTH; - if (MouseX >= lx && MouseX < lx + SPLICONLENGTH && MouseY >= ly && MouseY < ly + SPLICONLENGTH) { + if (MousePosition.x >= lx && MousePosition.x < lx + SPLICONLENGTH && MousePosition.y >= ly && MousePosition.y < ly + SPLICONLENGTH) { pSpell = (spell_id)j; pSplType = (spell_type)i; if (myPlayer._pClass == HeroClass::Monk && j == SPL_SEARCH) @@ -843,15 +843,15 @@ void DoPanBtn() for (int i = 0; i < numpanbtns; i++) { int x = PanBtnPos[i].x + PANEL_LEFT + PanBtnPos[i].w; int y = PanBtnPos[i].y + PANEL_TOP + PanBtnPos[i].h; - if (MouseX >= PanBtnPos[i].x + PANEL_LEFT && MouseX <= x) { - if (MouseY >= PanBtnPos[i].y + PANEL_TOP && MouseY <= y) { + if (MousePosition.x >= PanBtnPos[i].x + PANEL_LEFT && MousePosition.x <= x) { + if (MousePosition.y >= PanBtnPos[i].y + PANEL_TOP && MousePosition.y <= y) { panbtns[i] = true; drawbtnflag = true; panbtndown = true; } } } - if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) { + if (!spselflag && MousePosition.x >= 565 + PANEL_LEFT && MousePosition.x < 621 + PANEL_LEFT && MousePosition.y >= 64 + PANEL_TOP && MousePosition.y < 120 + PANEL_TOP) { if ((SDL_GetModState() & KMOD_SHIFT) != 0) { auto &myPlayer = plr[myplr]; myPlayer._pRSpell = SPL_INVALID; @@ -875,18 +875,18 @@ void control_check_btn_press() { int x = PanBtnPos[3].x + PANEL_LEFT + PanBtnPos[3].w; int y = PanBtnPos[3].y + PANEL_TOP + PanBtnPos[3].h; - if (MouseX >= PanBtnPos[3].x + PANEL_LEFT - && MouseX <= x - && MouseY >= PanBtnPos[3].y + PANEL_TOP - && MouseY <= y) { + if (MousePosition.x >= PanBtnPos[3].x + PANEL_LEFT + && MousePosition.x <= x + && MousePosition.y >= PanBtnPos[3].y + PANEL_TOP + && MousePosition.y <= y) { control_set_button_down(3); } x = PanBtnPos[6].x + PANEL_LEFT + PanBtnPos[6].w; y = PanBtnPos[6].y + PANEL_TOP + PanBtnPos[6].h; - if (MouseX >= PanBtnPos[6].x + PANEL_LEFT - && MouseX <= x - && MouseY >= PanBtnPos[6].y + PANEL_TOP - && MouseY <= y) { + if (MousePosition.x >= PanBtnPos[6].x + PANEL_LEFT + && MousePosition.x <= x + && MousePosition.y >= PanBtnPos[6].y + PANEL_TOP + && MousePosition.y <= y) { control_set_button_down(6); } } @@ -914,7 +914,7 @@ void CheckPanelInfo() for (int i = 0; i < numpanbtns; i++) { int xend = PanBtnPos[i].x + PANEL_LEFT + PanBtnPos[i].w; int yend = PanBtnPos[i].y + PANEL_TOP + PanBtnPos[i].h; - if (MouseX >= PanBtnPos[i].x + PANEL_LEFT && MouseX <= xend && MouseY >= PanBtnPos[i].y + PANEL_TOP && MouseY <= yend) { + if (MousePosition.x >= PanBtnPos[i].x + PANEL_LEFT && MousePosition.x <= xend && MousePosition.y >= PanBtnPos[i].y + PANEL_TOP && MousePosition.y <= yend) { if (i != 7) { strcpy(infostr, _(PanBtnStr[i])); } else { @@ -932,7 +932,7 @@ void CheckPanelInfo() pinfoflag = true; } } - if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) { + if (!spselflag && MousePosition.x >= 565 + PANEL_LEFT && MousePosition.x < 621 + PANEL_LEFT && MousePosition.y >= 64 + PANEL_TOP && MousePosition.y < 120 + PANEL_TOP) { strcpy(infostr, _("Select current spell button")); infoclr = UIS_SILVER; panelflag = true; @@ -991,7 +991,7 @@ void CheckPanelInfo() } } } - if (MouseX > 190 + PANEL_LEFT && MouseX < 437 + PANEL_LEFT && MouseY > 4 + PANEL_TOP && MouseY < 33 + PANEL_TOP) + if (MousePosition.x > 190 + PANEL_LEFT && MousePosition.x < 437 + PANEL_LEFT && MousePosition.y > 4 + PANEL_TOP && MousePosition.y < 33 + PANEL_TOP) pcursinvitem = CheckInvHLight(); if (CheckXPBarInfo()) { @@ -1017,10 +1017,10 @@ void CheckBtnUp() panbtns[i] = false; - if (MouseX < PanBtnPos[i].x + PANEL_LEFT - || MouseX > PanBtnPos[i].x + PANEL_LEFT + PanBtnPos[i].w - || MouseY < PanBtnPos[i].y + PANEL_TOP - || MouseY > PanBtnPos[i].y + PANEL_TOP + PanBtnPos[i].h) { + if (MousePosition.x < PanBtnPos[i].x + PANEL_LEFT + || MousePosition.x > PanBtnPos[i].x + PANEL_LEFT + PanBtnPos[i].w + || MousePosition.y < PanBtnPos[i].y + PANEL_TOP + || MousePosition.y > PanBtnPos[i].y + PANEL_TOP + PanBtnPos[i].h) { continue; } @@ -1388,13 +1388,13 @@ void DrawChr(const CelOutputBuffer &out) void CheckLvlBtn() { - if (!lvlbtndown && MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP) + if (!lvlbtndown && MousePosition.x >= 40 + PANEL_LEFT && MousePosition.x <= 81 + PANEL_LEFT && MousePosition.y >= -39 + PANEL_TOP && MousePosition.y <= -17 + PANEL_TOP) lvlbtndown = true; } void ReleaseLvlBtn() { - if (MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP) + if (MousePosition.x >= 40 + PANEL_LEFT && MousePosition.x <= 81 + PANEL_LEFT && MousePosition.y >= -39 + PANEL_TOP && MousePosition.y <= -17 + PANEL_TOP) chrflag = true; lvlbtndown = false; } @@ -1440,10 +1440,10 @@ void CheckChrBtns() auto buttonId = static_cast(attribute); int x = ChrBtnsRect[buttonId].position.x + ChrBtnsRect[buttonId].size.width; int y = ChrBtnsRect[buttonId].position.y + ChrBtnsRect[buttonId].size.height; - if (MouseX >= ChrBtnsRect[buttonId].position.x - && MouseX <= x - && MouseY >= ChrBtnsRect[buttonId].position.y - && MouseY <= y) { + if (MousePosition.x >= ChrBtnsRect[buttonId].position.x + && MousePosition.x <= x + && MousePosition.y >= ChrBtnsRect[buttonId].position.y + && MousePosition.y <= y) { chrbtn[buttonId] = true; chrbtnactive = true; } @@ -1466,10 +1466,10 @@ void ReleaseChrBtns(bool addAllStatPoints) continue; chrbtn[buttonId] = false; - if (MouseX >= ChrBtnsRect[buttonId].position.x - && MouseX <= ChrBtnsRect[buttonId].position.x + ChrBtnsRect[buttonId].size.width - && MouseY >= ChrBtnsRect[buttonId].position.y - && MouseY <= ChrBtnsRect[buttonId].position.y + ChrBtnsRect[buttonId].size.height) { + if (MousePosition.x >= ChrBtnsRect[buttonId].position.x + && MousePosition.x <= ChrBtnsRect[buttonId].position.x + ChrBtnsRect[buttonId].size.width + && MousePosition.y >= ChrBtnsRect[buttonId].position.y + && MousePosition.y <= ChrBtnsRect[buttonId].position.y + ChrBtnsRect[buttonId].size.height) { auto &myPlayer = plr[myplr]; int statPointsToAdd = 1; if (addAllStatPoints) @@ -1668,8 +1668,8 @@ void DrawSpellBook(const CelOutputBuffer &out) void CheckSBook() { - if (MouseX >= RIGHT_PANEL + 11 && MouseX < RIGHT_PANEL + 48 && MouseY >= 18 && MouseY < 314) { - spell_id sn = SpellPages[sbooktab][(MouseY - 18) / 43]; + if (MousePosition.x >= RIGHT_PANEL + 11 && MousePosition.x < RIGHT_PANEL + 48 && MousePosition.y >= 18 && MousePosition.y < 314) { + spell_id sn = SpellPages[sbooktab][(MousePosition.y - 18) / 43]; auto &myPlayer = plr[myplr]; uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells; if (sn != SPL_INVALID && (spl & GetSpellBitmask(sn)) != 0) { @@ -1685,8 +1685,8 @@ void CheckSBook() force_redraw = 255; } } - if (MouseX >= RIGHT_PANEL + 7 && MouseX < RIGHT_PANEL + 311 && MouseY >= SPANEL_WIDTH && MouseY < 349) { - sbooktab = (MouseX - (RIGHT_PANEL + 7)) / (gbIsHellfire ? 61 : 76); + if (MousePosition.x >= RIGHT_PANEL + 7 && MousePosition.x < RIGHT_PANEL + 311 && MousePosition.y >= SPANEL_WIDTH && MousePosition.y < 349) { + sbooktab = (MousePosition.x - (RIGHT_PANEL + 7)) / (gbIsHellfire ? 61 : 76); } } @@ -1851,20 +1851,20 @@ bool control_check_talk_btn() if (!talkflag) return false; - if (MouseX < 172 + PANEL_LEFT) + if (MousePosition.x < 172 + PANEL_LEFT) return false; - if (MouseY < 69 + PANEL_TOP) + if (MousePosition.y < 69 + PANEL_TOP) return false; - if (MouseX > 233 + PANEL_LEFT) + if (MousePosition.x > 233 + PANEL_LEFT) return false; - if (MouseY > 123 + PANEL_TOP) + if (MousePosition.y > 123 + PANEL_TOP) return false; for (bool &talkButtonDown : talkButtonsDown) { talkButtonDown = false; } - talkButtonsDown[(MouseY - (69 + PANEL_TOP)) / 18] = true; + talkButtonsDown[(MousePosition.y - (69 + PANEL_TOP)) / 18] = true; return true; } @@ -1877,10 +1877,10 @@ void control_release_talk_btn() for (bool &talkButtonDown : talkButtonsDown) talkButtonDown = false; - if (MouseX < 172 + PANEL_LEFT || MouseY < 69 + PANEL_TOP || MouseX > 233 + PANEL_LEFT || MouseY > 123 + PANEL_TOP) + if (MousePosition.x < 172 + PANEL_LEFT || MousePosition.y < 69 + PANEL_TOP || MousePosition.x > 233 + PANEL_LEFT || MousePosition.y > 123 + PANEL_TOP) return; - int off = (MouseY - (69 + PANEL_TOP)) / 18; + int off = (MousePosition.y - (69 + PANEL_TOP)) / 18; int p = 0; for (; p < MAX_PLRS && off != -1; p++) { diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 5172c1182..d17a6ebf6 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -465,10 +465,10 @@ void AttrIncBtnSnap(AxisDirection dir) // first, find our cursor location int slot = 0; for (int i = 0; i < 4; i++) { - if (MouseX >= ChrBtnsRect[i].position.x - && MouseX <= ChrBtnsRect[i].position.x + ChrBtnsRect[i].size.width - && MouseY >= ChrBtnsRect[i].position.y - && MouseY <= ChrBtnsRect[i].size.height + ChrBtnsRect[i].position.y) { + if (MousePosition.x >= ChrBtnsRect[i].position.x + && MousePosition.x <= ChrBtnsRect[i].position.x + ChrBtnsRect[i].size.width + && MousePosition.y >= ChrBtnsRect[i].position.y + && MousePosition.y <= ChrBtnsRect[i].size.height + ChrBtnsRect[i].position.y) { slot = i; break; } @@ -654,7 +654,7 @@ void InvMove(AxisDirection dir) char itemInvId; auto itemSize = GetItemSizeOnSlot(slot, itemInvId); - Point mousePos { MouseX, MouseY }; + Point mousePos { MousePosition.x, MousePosition.y }; const bool isHoldingItem = pcurs > 1; @@ -925,7 +925,7 @@ void InvMove(AxisDirection dir) mousePos.y -= (InventorySlotSizeInPixels.height / 2); } - if (mousePos.x == MouseX && mousePos.y == MouseY) { + if (mousePos == MousePosition) { return; // Avoid wobeling when scalled } @@ -957,10 +957,10 @@ void HotSpellMove(AxisDirection dir) int spbslot = plr[myplr]._pRSpell; for (int r = 0; r < speedspellcount; r++) { - if (MouseX >= speedspellscoords[r].x - SPLICONLENGTH / 2 - && MouseX < speedspellscoords[r].x + SPLICONLENGTH / 2 - && MouseY >= speedspellscoords[r].y - SPLICONLENGTH / 2 - && MouseY < speedspellscoords[r].y + SPLICONLENGTH / 2) { + if (MousePosition.x >= speedspellscoords[r].x - SPLICONLENGTH / 2 + && MousePosition.x < speedspellscoords[r].x + SPLICONLENGTH / 2 + && MousePosition.y >= speedspellscoords[r].y - SPLICONLENGTH / 2 + && MousePosition.y < speedspellscoords[r].y + SPLICONLENGTH / 2) { spbslot = r; break; } @@ -991,7 +991,7 @@ void HotSpellMove(AxisDirection dir) } } - if (x != MouseX || y != MouseY) { + if (Point { x, y } != MousePosition) { SetCursorPos(x, y); } } @@ -1277,8 +1277,8 @@ void HandleRightStickMotion() { // move cursor sgbControllerActive = false; - int x = MouseX; - int y = MouseY; + int x = MousePosition.x; + int y = MousePosition.y; acc.Pool(&x, &y, 2); x = std::min(std::max(x, 0), gnScreenWidth - 1); y = std::min(std::max(y, 0), gnScreenHeight - 1); @@ -1382,10 +1382,10 @@ void PerformPrimaryAction() if (chrflag && !chrbtnactive && plr[myplr]._pStatPts > 0) { CheckChrBtns(); for (int i = 0; i < 4; i++) { - if (MouseX >= ChrBtnsRect[i].position.x - && MouseX <= ChrBtnsRect[i].position.x + ChrBtnsRect[i].size.width - && MouseY >= ChrBtnsRect[i].position.y - && MouseY <= ChrBtnsRect[i].size.height + ChrBtnsRect[i].position.y) { + if (MousePosition.x >= ChrBtnsRect[i].position.x + && MousePosition.x <= ChrBtnsRect[i].position.x + ChrBtnsRect[i].size.width + && MousePosition.y >= ChrBtnsRect[i].position.y + && MousePosition.y <= ChrBtnsRect[i].size.height + ChrBtnsRect[i].position.y) { chrbtn[i] = true; chrbtnactive = true; ReleaseChrBtns(false); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 63fcc0e4b..67497f18b 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -277,8 +277,8 @@ void CheckCursMove() if (IsItemLabelHighlighted()) return; - sx = MouseX; - sy = MouseY; + sx = MousePosition.x; + sy = MousePosition.y; if (CanPanelsCoverView()) { if (chrflag || questlog) { @@ -295,7 +295,7 @@ void CheckCursMove() } } } - if (sy > PANEL_TOP - 1 && MouseX >= PANEL_LEFT && MouseX < PANEL_LEFT + PANEL_WIDTH && track_isscrolling()) { + if (sy > PANEL_TOP - 1 && MousePosition.x >= PANEL_LEFT && MousePosition.x < PANEL_LEFT + PANEL_WIDTH && track_isscrolling()) { sy = PANEL_TOP - 1; } @@ -400,21 +400,21 @@ void CheckCursMove() cursmy = my; return; } - if (MouseY > PANEL_TOP && MouseX >= PANEL_LEFT && MouseX <= PANEL_LEFT + PANEL_WIDTH) { + if (MousePosition.y > PANEL_TOP && MousePosition.x >= PANEL_LEFT && MousePosition.x <= PANEL_LEFT + PANEL_WIDTH) { CheckPanelInfo(); return; } if (DoomFlag) { return; } - if (invflag && MouseX > RIGHT_PANEL && MouseY <= SPANEL_HEIGHT) { + if (invflag && MousePosition.x > RIGHT_PANEL && MousePosition.y <= SPANEL_HEIGHT) { pcursinvitem = CheckInvHLight(); return; } - if (sbookflag && MouseX > RIGHT_PANEL && MouseY <= SPANEL_HEIGHT) { + if (sbookflag && MousePosition.x > RIGHT_PANEL && MousePosition.y <= SPANEL_HEIGHT) { return; } - if ((chrflag || questlog) && MouseX < SPANEL_WIDTH && MouseY <= SPANEL_HEIGHT) { + if ((chrflag || questlog) && MousePosition.x < SPANEL_WIDTH && MousePosition.y <= SPANEL_HEIGHT) { return; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 7c69237c9..8fe88eeb7 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -81,8 +81,7 @@ uint32_t glMid1Seed[NUMLEVELS]; uint32_t glMid2Seed[NUMLEVELS]; uint32_t glMid3Seed[NUMLEVELS]; -int MouseX; -int MouseY; +Point MousePosition; bool gbGameLoopStartup; bool gbRunGame; bool gbRunGameResult; @@ -346,7 +345,7 @@ static bool ProcessInput() if (!gmenu_is_active() && sgnTimeoutCurs == CURSOR_NONE) { #ifndef USE_SDL1 - finish_simulated_mouse_clicks(MouseX, MouseY); + finish_simulated_mouse_clicks(MousePosition.x, MousePosition.y); #endif CheckCursMove(); plrctrls_after_check_curs_move(); @@ -472,10 +471,9 @@ bool StartGame(bool bNewGame, bool bSinglePlayer) static void diablo_init_screen() { - MouseX = gnScreenWidth / 2; - MouseY = gnScreenHeight / 2; + MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 }; if (!sgbControllerActive) - SetCursorPos(MouseX, MouseY); + SetCursorPos(MousePosition.x, MousePosition.y); ScrollInfo.tile = { 0, 0 }; ScrollInfo.offset = { 0, 0 }; ScrollInfo._sdir = SDIR_NONE; @@ -613,7 +611,7 @@ static bool LeftMouseCmd(bool bShift) { bool bNear; - assert(MouseY < PANEL_TOP || MouseX < PANEL_LEFT || MouseX >= PANEL_LEFT + PANEL_WIDTH); + assert(MousePosition.y < PANEL_TOP || MousePosition.x < PANEL_LEFT || MousePosition.x >= PANEL_LEFT + PANEL_WIDTH); if (leveltype == DTYPE_TOWN) { if (pcursitem != -1 && pcurs == CURSOR_HAND) @@ -770,19 +768,19 @@ static bool LeftMouseDown(int wParam) bool isShiftHeld = (wParam & DVL_MK_SHIFT) != 0; - if (MouseY < PANEL_TOP || MouseX < PANEL_LEFT || MouseX >= PANEL_LEFT + PANEL_WIDTH) { + if (MousePosition.y < PANEL_TOP || MousePosition.x < PANEL_LEFT || MousePosition.x >= PANEL_LEFT + PANEL_WIDTH) { if (!gmenu_is_active() && !TryIconCurs()) { - if (questlog && MouseX > 32 && MouseX < 288 && MouseY > 32 && MouseY < 308) { + if (questlog && MousePosition.x > 32 && MousePosition.x < 288 && MousePosition.y > 32 && MousePosition.y < 308) { QuestlogESC(); } else if (qtextflag) { qtextflag = false; stream_stop(); - } else if (chrflag && MouseX < SPANEL_WIDTH && MouseY < SPANEL_HEIGHT) { + } else if (chrflag && MousePosition.x < SPANEL_WIDTH && MousePosition.y < SPANEL_HEIGHT) { CheckChrBtns(); - } else if (invflag && MouseX > RIGHT_PANEL && MouseY < SPANEL_HEIGHT) { + } else if (invflag && MousePosition.x > RIGHT_PANEL && MousePosition.y < SPANEL_HEIGHT) { if (!dropGoldFlag) CheckInvItem(isShiftHeld); - } else if (sbookflag && MouseX > RIGHT_PANEL && MouseY < SPANEL_HEIGHT) { + } else if (sbookflag && MousePosition.x > RIGHT_PANEL && MousePosition.y < SPANEL_HEIGHT) { CheckSBook(); } else if (pcurs >= CURSOR_FIRSTITEM) { if (TryInvPut()) { @@ -838,8 +836,8 @@ static void RightMouseDown() SetSpell(); return; } - if (MouseY >= SPANEL_HEIGHT - || ((!sbookflag || MouseX <= RIGHT_PANEL) + if (MousePosition.y >= SPANEL_HEIGHT + || ((!sbookflag || MousePosition.x <= RIGHT_PANEL) && !TryIconCurs() && (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)))) { if (pcurs == CURSOR_HAND) { @@ -897,10 +895,10 @@ static void ReleaseKey(int vkey) static void ClosePanels() { if (CanPanelsCoverView()) { - if (!chrflag && !questlog && (invflag || sbookflag) && MouseX < 480 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX + 160, MouseY); - } else if (!invflag && !sbookflag && (chrflag || questlog) && MouseX > 160 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX - 160, MouseY); + if (!chrflag && !questlog && (invflag || sbookflag) && MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); + } else if (!invflag && !sbookflag && (chrflag || questlog) && MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); } } invflag = false; @@ -1200,8 +1198,7 @@ static void PressChar(int32_t vkey) static void GetMousePos(int32_t lParam) { - MouseX = (short)(lParam & 0xffff); - MouseY = (short)((lParam >> 16) & 0xffff); + MousePosition = { (short)(lParam & 0xffff), (short)((lParam >> 16) & 0xffff) }; } void DisableInputWndProc(uint32_t uMsg, int32_t wParam, int32_t lParam) @@ -1857,12 +1854,12 @@ void inventoryKeyPressed() invflag = !invflag; if (!chrflag && !questlog && CanPanelsCoverView()) { if (!invflag) { // We closed the invetory - if (MouseX < 480 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX + 160, MouseY); + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } } else if (!sbookflag) { // We opened the invetory - if (MouseX > 160 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX - 160, MouseY); + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); } } } @@ -1876,12 +1873,12 @@ void characterSheetKeyPressed() chrflag = !chrflag; if (!invflag && !sbookflag && CanPanelsCoverView()) { if (!chrflag) { // We closed the character sheet - if (MouseX > 160 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX - 160, MouseY); + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); } } else if (!questlog) { // We opened the character sheet - if (MouseX < 480 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX + 160, MouseY); + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } } } @@ -1899,12 +1896,12 @@ void questLogKeyPressed() } if (!invflag && !sbookflag && CanPanelsCoverView()) { if (!questlog) { // We closed the quest log - if (MouseX > 160 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX - 160, MouseY); + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); } } else if (!chrflag) { // We opened the character quest log - if (MouseX < 480 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX + 160, MouseY); + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } } } @@ -1934,12 +1931,12 @@ void spellBookKeyPressed() sbookflag = !sbookflag; if (!chrflag && !questlog && CanPanelsCoverView()) { if (!sbookflag) { // We closed the invetory - if (MouseX < 480 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX + 160, MouseY); + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } } else if (!invflag) { // We opened the invetory - if (MouseX > 160 && MouseY < PANEL_TOP) { - SetCursorPos(MouseX - 160, MouseY); + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); } } } diff --git a/Source/diablo.h b/Source/diablo.h index e4f1c73cb..25d8bb6ab 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -31,8 +31,7 @@ enum clicktype : int8_t { extern SDL_Window *ghMainWnd; extern DWORD glSeedTbl[NUMLEVELS]; extern dungeon_type gnLevelTypeTbl[NUMLEVELS]; -extern int MouseX; -extern int MouseY; +extern Point MousePosition; extern bool gbRunGame; extern bool gbRunGameResult; extern bool zoomflag; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 178a9cfb3..6fe263155 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -257,10 +257,10 @@ bool gmenu_presskeys(int vkey) static bool GmenuMouseNavigation() { - if (MouseX < 282 + PANEL_LEFT) { + if (MousePosition.x < 282 + PANEL_LEFT) { return false; } - if (MouseX > 538 + PANEL_LEFT) { + if (MousePosition.x > 538 + PANEL_LEFT) { return false; } return true; @@ -268,13 +268,13 @@ static bool GmenuMouseNavigation() static int GmenuGetMouseSlider() { - if (MouseX < 282 + PANEL_LEFT) { + if (MousePosition.x < 282 + PANEL_LEFT) { return 0; } - if (MouseX > 538 + PANEL_LEFT) { + if (MousePosition.x > 538 + PANEL_LEFT) { return 256; } - return MouseX - 282 - PANEL_LEFT; + return MousePosition.x - 282 - PANEL_LEFT; } bool gmenu_on_mouse_move() @@ -306,13 +306,13 @@ bool gmenu_left_mouse(bool isDown) if (sgpCurrentMenu == nullptr) { return false; } - if (MouseY >= PANEL_TOP) { + if (MousePosition.y >= PANEL_TOP) { return false; } - if (MouseY - (117 + UI_OFFSET_Y) < 0) { + if (MousePosition.y - (117 + UI_OFFSET_Y) < 0) { return true; } - int i = (MouseY - (117 + UI_OFFSET_Y)) / 45; + int i = (MousePosition.y - (117 + UI_OFFSET_Y)) / 45; if (i >= sgCurrentMenuIdx) { return true; } @@ -321,10 +321,10 @@ bool gmenu_left_mouse(bool isDown) return true; } int w = GmenuGetLfont(pItem); - if (MouseX < gnScreenWidth / 2 - w / 2) { + if (MousePosition.x < gnScreenWidth / 2 - w / 2) { return true; } - if (MouseX > gnScreenWidth / 2 + w / 2) { + if (MousePosition.x > gnScreenWidth / 2 + w / 2) { return true; } sgpCurrItem = pItem; diff --git a/Source/inv.cpp b/Source/inv.cpp index 6bb7128bb..94f556ebf 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1168,7 +1168,7 @@ void CheckInvPaste(int pnum, Point cursorPosition) CalcPlrInv(pnum, true); if (pnum == myplr) { if (cn == CURSOR_HAND && !IsHardwareCursor()) - SetCursorPos(MouseX + (cursW / 2), MouseY + (cursH / 2)); + SetCursorPos(MousePosition.x + (cursW / 2), MousePosition.y + (cursH / 2)); NewCursor(cn); } } @@ -1429,9 +1429,9 @@ void inv_update_rem_item(int pnum, BYTE iv) void CheckInvItem(bool isShiftHeld) { if (pcurs >= CURSOR_FIRSTITEM) { - CheckInvPaste(myplr, { MouseX, MouseY }); + CheckInvPaste(myplr, MousePosition); } else { - CheckInvCut(myplr, { MouseX, MouseY }, isShiftHeld); + CheckInvCut(myplr, MousePosition, isShiftHeld); } } @@ -1440,8 +1440,8 @@ void CheckInvItem(bool isShiftHeld) */ void CheckInvScrn(bool isShiftHeld) { - if (MouseX > 190 + PANEL_LEFT && MouseX < 437 + PANEL_LEFT - && MouseY > PANEL_TOP && MouseY < 33 + PANEL_TOP) { + if (MousePosition.x > 190 + PANEL_LEFT && MousePosition.x < 437 + PANEL_LEFT + && MousePosition.y > PANEL_TOP && MousePosition.y < 33 + PANEL_TOP) { CheckInvItem(isShiftHeld); } } @@ -1907,10 +1907,10 @@ char CheckInvHLight() yo = PANEL_TOP; } - if (MouseX >= InvRect[r].x + xo - && MouseX < InvRect[r].x + xo + (InventorySlotSizeInPixels.width + 1) - && MouseY >= InvRect[r].y + yo - (InventorySlotSizeInPixels.height + 1) - && MouseY < InvRect[r].y + yo) { + if (MousePosition.x >= InvRect[r].x + xo + && MousePosition.x < InvRect[r].x + xo + (InventorySlotSizeInPixels.width + 1) + && MousePosition.y >= InvRect[r].y + yo - (InventorySlotSizeInPixels.height + 1) + && MousePosition.y < InvRect[r].y + yo) { break; } } diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index ccbd43783..81ce6b115 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -326,7 +326,7 @@ bool FetchMessage(tagMSG *lpMsg) } #ifndef USE_SDL1 - handle_touch(&e, MouseX, MouseY); + handle_touch(&e, MousePosition.x, MousePosition.y); #endif #ifdef USE_SDL1 @@ -444,7 +444,7 @@ bool FetchMessage(tagMSG *lpMsg) lpMsg->message = action.send_mouse_click.up ? DVL_WM_RBUTTONUP : DVL_WM_RBUTTONDOWN; break; } - lpMsg->lParam = PositionForMouse(MouseX, MouseY); + lpMsg->lParam = PositionForMouse(MousePosition.x, MousePosition.y); break; } return true; @@ -562,8 +562,7 @@ bool FetchMessage(tagMSG *lpMsg) // and SDL_GetMouseState gives previous location if mouse was // outside window (observed on Ubuntu 19.04) if (mouseWarping) { - MouseX = mouseWarpingX; - MouseY = mouseWarpingY; + MousePosition = { mouseWarpingX, mouseWarpingY }; mouseWarping = false; } break; diff --git a/Source/movie.cpp b/Source/movie.cpp index 1110db73a..49bff53e1 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -67,8 +67,8 @@ void play_movie(const char *pszMovie, bool user_can_close) movie_playing = false; - SDL_GetMouseState(&MouseX, &MouseY); - OutputToLogical(&MouseX, &MouseY); + SDL_GetMouseState(&MousePosition.x, &MousePosition.y); + OutputToLogical(&MousePosition.x, &MousePosition.y); } } // namespace devilution diff --git a/Source/player.cpp b/Source/player.cpp index 3b8d4868c..a7979097d 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3625,12 +3625,12 @@ void CheckPlrSpell() if (pcurs != CURSOR_HAND) return; - if (MouseY >= PANEL_TOP && MouseX >= PANEL_LEFT && MouseX <= RIGHT_PANEL) // inside main panel + if (MousePosition.y >= PANEL_TOP && MousePosition.x >= PANEL_LEFT && MousePosition.x <= RIGHT_PANEL) // inside main panel return; if ( - ((chrflag || questlog) && MouseX < SPANEL_WIDTH && MouseY < SPANEL_HEIGHT) // inside left panel - || ((invflag || sbookflag) && MouseX > RIGHT_PANEL && MouseY < SPANEL_HEIGHT) // inside right panel + ((chrflag || questlog) && MousePosition.x < SPANEL_WIDTH && MousePosition.y < SPANEL_HEIGHT) // inside left panel + || ((invflag || sbookflag) && MousePosition.x > RIGHT_PANEL && MousePosition.y < SPANEL_HEIGHT) // inside right panel ) { if (rspell != SPL_HEAL && rspell != SPL_IDENTIFY diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index 7309abfc4..010f442b2 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -93,11 +93,11 @@ void AddItemToLabelQueue(int id, int x, int y) bool IsMouseOverGameArea() { - if ((invflag || sbookflag) && MouseX > RIGHT_PANEL && MouseY <= SPANEL_HEIGHT) + if ((invflag || sbookflag) && MousePosition.x > RIGHT_PANEL && MousePosition.y <= SPANEL_HEIGHT) return false; - if ((chrflag || questlog) && MouseX < SPANEL_WIDTH && MouseY <= SPANEL_HEIGHT) + if ((chrflag || questlog) && MousePosition.x < SPANEL_WIDTH && MousePosition.y <= SPANEL_HEIGHT) return false; - if (MouseY >= PANEL_TOP && MouseX >= PANEL_LEFT && MouseX <= PANEL_LEFT + PANEL_WIDTH) + if (MousePosition.y >= PANEL_TOP && MousePosition.x >= PANEL_LEFT && MousePosition.x <= PANEL_LEFT + PANEL_WIDTH) return false; return true; @@ -147,7 +147,7 @@ void DrawItemNameLabels(const CelOutputBuffer &out) for (const itemLabel &label : labelQueue) { ItemStruct &itm = items[label.id]; - if (MouseX >= label.pos.x && MouseX < label.pos.x + label.width && MouseY >= label.pos.y - height + marginY && MouseY < label.pos.y + marginY) { + if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width && MousePosition.y >= label.pos.y - height + marginY && MousePosition.y < label.pos.y + marginY) { if (!gmenu_is_active() && PauseMode == 0 && !deathflag && IsMouseOverGameArea()) { isLabelHighlighted = true; cursmx = itm.position.x; diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index f26509223..0aec723bf 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -118,7 +118,7 @@ bool CheckXPBarInfo() const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155; const int backY = PANEL_TOP + PANEL_HEIGHT - 11; - if (MouseX < backX || MouseX >= backX + BACK_WIDTH || MouseY < backY || MouseY >= backY + BACK_HEIGHT) + if (MousePosition.x < backX || MousePosition.x >= backX + BACK_WIDTH || MousePosition.y < backY || MousePosition.y >= backY + BACK_HEIGHT) return false; const auto &player = plr[myplr]; diff --git a/Source/quests.cpp b/Source/quests.cpp index cfbd88319..2a9b64301 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -801,7 +801,7 @@ void QuestlogEnter() void QuestlogESC() { - int y = (MouseY - 32) / 12; + int y = (MousePosition.y - 32) / 12; for (int i = 0; i < numqlines; i++) { if (y == qtopline + 2 * i) { qline = y; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 276a8eb02..4499fd295 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -208,7 +208,7 @@ static void DrawCursor(const CelOutputBuffer &out) // Copy the buffer before the item cursor and its 1px outline are drawn to a temporary buffer. const int outlineWidth = IsItemSprite(pcurs) ? 1 : 0; - if (MouseX < -cursW - outlineWidth || MouseX - outlineWidth >= out.w() || MouseY < -cursH - outlineWidth || MouseY - outlineWidth >= out.h()) + if (MousePosition.x < -cursW - outlineWidth || MousePosition.x - outlineWidth >= out.w() || MousePosition.y < -cursH - outlineWidth || MousePosition.y - outlineWidth >= out.h()) return; constexpr auto Clip = [](int &pos, std::uint32_t &length, std::uint32_t posEnd) { @@ -220,16 +220,16 @@ static void DrawCursor(const CelOutputBuffer &out) } }; - sgdwCursX = MouseX - outlineWidth; + sgdwCursX = MousePosition.x - outlineWidth; sgdwCursWdt = cursW + 2 * outlineWidth; Clip(sgdwCursX, sgdwCursWdt, out.w()); - sgdwCursY = MouseY - outlineWidth; + sgdwCursY = MousePosition.y - outlineWidth; sgdwCursHgt = cursH + 2 * outlineWidth; Clip(sgdwCursY, sgdwCursHgt, out.h()); BlitCursor(sgSaveBack, sgdwCursWdt, out.at(sgdwCursX, sgdwCursY), out.pitch()); - CelDrawCursor(out, Point { MouseX, MouseY + cursH - 1 }, pcurs); + CelDrawCursor(out, MousePosition + Point { 0, cursH - 1 }, pcurs); } /** @@ -1349,7 +1349,7 @@ void ScrollView() scroll = false; - if (MouseX < 20) { + if (MousePosition.x < 20) { if (dmaxy - 1 <= ViewY || dminx >= ViewX) { if (dmaxy - 1 > ViewY) { ViewY++; @@ -1365,7 +1365,7 @@ void ScrollView() scroll = true; } } - if (MouseX > gnScreenWidth - 20) { + if (MousePosition.x > gnScreenWidth - 20) { if (dmaxx - 1 <= ViewX || dminy >= ViewY) { if (dmaxx - 1 > ViewX) { ViewX++; @@ -1381,7 +1381,7 @@ void ScrollView() scroll = true; } } - if (MouseY < 20) { + if (MousePosition.y < 20) { if (dminy >= ViewY || dminx >= ViewX) { if (dminy < ViewY) { ViewY--; @@ -1397,7 +1397,7 @@ void ScrollView() scroll = true; } } - if (MouseY > gnScreenHeight - 20) { + if (MousePosition.y > gnScreenHeight - 20) { if (dmaxy - 1 <= ViewY || dmaxx - 1 <= ViewX) { if (dmaxy - 1 > ViewY) { ViewY++; diff --git a/Source/stores.cpp b/Source/stores.cpp index 42d8712e8..0c30e3bbe 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2757,16 +2757,16 @@ void CheckStoreBtn() qtextflag = false; if (leveltype == DTYPE_TOWN) stream_stop(); - } else if (stextsel != -1 && MouseY >= (32 + UI_OFFSET_Y) && MouseY <= (320 + UI_OFFSET_Y)) { + } else if (stextsel != -1 && MousePosition.y >= (32 + UI_OFFSET_Y) && MousePosition.y <= (320 + UI_OFFSET_Y)) { if (!stextsize) { - if (MouseX < 344 + PANEL_LEFT || MouseX > 616 + PANEL_LEFT) + if (MousePosition.x < 344 + PANEL_LEFT || MousePosition.x > 616 + PANEL_LEFT) return; } else { - if (MouseX < 24 + PANEL_LEFT || MouseX > 616 + PANEL_LEFT) + if (MousePosition.x < 24 + PANEL_LEFT || MousePosition.x > 616 + PANEL_LEFT) return; } - y = (MouseY - (32 + UI_OFFSET_Y)) / 12; - if (stextscrl && MouseX > 600 + PANEL_LEFT) { + y = (MousePosition.y - (32 + UI_OFFSET_Y)) / 12; + if (stextscrl && MousePosition.x > 600 + PANEL_LEFT) { if (y == 4) { if (stextscrlubtn <= 0) { STextUp(); diff --git a/Source/trigs.cpp b/Source/trigs.cpp index ffa721081..cdc40c7e5 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -768,7 +768,7 @@ void CheckTrigForce() { trigflag = false; - if (!sgbControllerActive && MouseY > PANEL_TOP - 1) { + if (!sgbControllerActive && MousePosition.y > PANEL_TOP - 1) { return; }