From 6c21638beea0cd11f054e0d825774d050fea3ee7 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Sun, 27 Jun 2021 00:34:13 -0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Leverage=20'Point'=20in=20?= =?UTF-8?q?'SetCursorPos'=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/control.cpp | 2 +- Source/controls/plrctrls.cpp | 13 ++++++------- Source/diablo.cpp | 22 +++++++++++----------- Source/inv.cpp | 4 ++-- Source/miniwin/miniwin.h | 4 +++- Source/miniwin/misc_msg.cpp | 10 +++++----- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 0f72dc181..6892ab6ab 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1088,7 +1088,7 @@ void DoSpeedBook() } } - SetCursorPos(x, y); + SetCursorPos({ x, y }); } /** diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index fa8b5100a..f208168f6 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -488,9 +488,8 @@ void AttrIncBtnSnap(AxisDirection dir) // move cursor to our new location button = ChrBtnsRect[slot]; button.position = GetPanelPosition(UiPanels::Character, button.position); - int x = button.position.x + (button.size.width / 2); - int y = button.position.y + (button.size.height / 2); - SetCursorPos(x, y); + Point position = { button.position.x + (button.size.width / 2), button.position.y + (button.size.height / 2) }; + SetCursorPos(position); } Point InvGetEquipSlotCoord(const inv_body_loc invSlot) @@ -641,7 +640,7 @@ void ResetInvCursorPosition() mousePos.x += (InventorySlotSizeInPixels.width / 2); mousePos.y -= (InventorySlotSizeInPixels.height / 2); - SetCursorPos(mousePos.x, mousePos.y); + SetCursorPos(mousePos); } /** @@ -934,7 +933,7 @@ void InvMove(AxisDirection dir) return; // Avoid wobeling when scalled } - SetCursorPos(mousePos.x, mousePos.y); + SetCursorPos(mousePos); } /** @@ -994,7 +993,7 @@ void HotSpellMove(AxisDirection dir) } if (newMousePosition != MousePosition) { - SetCursorPos(newMousePosition.x, newMousePosition.y); + SetCursorPos(newMousePosition); } } @@ -1283,7 +1282,7 @@ void HandleRightStickMotion() static int lastMouseSetTick = 0; const int now = SDL_GetTicks(); if (now - lastMouseSetTick > 0) { - SetCursorPos(x, y); + SetCursorPos({ x, y }); lastMouseSetTick = now; } } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index d190eed66..f764064d3 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -412,9 +412,9 @@ void ClosePanels() { if (CanPanelsCoverView()) { if (!chrflag && !QuestLogIsOpen && (invflag || sbookflag) && MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); + SetCursorPos(MousePosition + Displacement { 160, 0 }); } else if (!invflag && !sbookflag && (chrflag || QuestLogIsOpen) && MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); + SetCursorPos(MousePosition - Displacement { 160, 0 }); } } invflag = false; @@ -911,7 +911,7 @@ void DiabloInitScreen() { MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 }; if (!sgbControllerActive) - SetCursorPos(MousePosition.x, MousePosition.y); + SetCursorPos(MousePosition); ScrollInfo.tile = { 0, 0 }; ScrollInfo.offset = { 0, 0 }; ScrollInfo._sdir = SDIR_NONE; @@ -1272,11 +1272,11 @@ void InventoryKeyPressed() if (!chrflag && !QuestLogIsOpen && CanPanelsCoverView()) { if (!invflag) { // We closed the invetory if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); + SetCursorPos(MousePosition + Displacement { 160, 0 }); } } else if (!sbookflag) { // We opened the invetory if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); + SetCursorPos(MousePosition - Displacement { 160, 0 }); } } } @@ -1291,11 +1291,11 @@ void CharacterSheetKeyPressed() if (!invflag && !sbookflag && CanPanelsCoverView()) { if (!chrflag) { // We closed the character sheet if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); + SetCursorPos(MousePosition - Displacement { 160, 0 }); } } else if (!QuestLogIsOpen) { // We opened the character sheet if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); + SetCursorPos(MousePosition + Displacement { 160, 0 }); } } } @@ -1314,11 +1314,11 @@ void QuestLogKeyPressed() if (!invflag && !sbookflag && CanPanelsCoverView()) { if (!QuestLogIsOpen) { // We closed the quest log if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); + SetCursorPos(MousePosition - Displacement { 160, 0 }); } } else if (!chrflag) { // We opened the character quest log if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); + SetCursorPos(MousePosition + Displacement { 160, 0 }); } } } @@ -1349,11 +1349,11 @@ void SpellBookKeyPressed() if (!chrflag && !QuestLogIsOpen && CanPanelsCoverView()) { if (!sbookflag) { // We closed the invetory if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); + SetCursorPos(MousePosition + Displacement { 160, 0 }); } } else if (!invflag) { // We opened the invetory if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); + SetCursorPos(MousePosition - Displacement { 160, 0 }); } } } diff --git a/Source/inv.cpp b/Source/inv.cpp index c1d1dfe9d..d0e68e930 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -675,7 +675,7 @@ void CheckInvPaste(int pnum, Point cursorPosition) CalcPlrInv(player, true); if (pnum == MyPlayerId) { if (cn == CURSOR_HAND && !IsHardwareCursor()) - SetCursorPos(MousePosition.x + (cursW / 2), MousePosition.y + (cursH / 2)); + SetCursorPos(MousePosition + Displacement(Size { cursW, cursH } / 2)); NewCursor(cn); } } @@ -889,7 +889,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove) NewCursor(holdItem._iCurs + CURSOR_FIRSTITEM); if (!IsHardwareCursor()) { // For a hardware cursor, we set the "hot point" to the center of the item instead. - SetCursorPos(cursorPosition.x - (cursW / 2), cursorPosition.y - (cursH / 2)); + SetCursorPos(cursorPosition - Displacement(Size { cursW, cursH } / 2)); } } } diff --git a/Source/miniwin/miniwin.h b/Source/miniwin/miniwin.h index fc3c51039..70bd1be10 100644 --- a/Source/miniwin/miniwin.h +++ b/Source/miniwin/miniwin.h @@ -9,6 +9,8 @@ #include #include +#include "engine/point.hpp" + namespace devilution { #ifndef MAX_PATH @@ -35,7 +37,7 @@ struct tagMSG { // Everything else // -void SetCursorPos(int X, int Y); +void SetCursorPos(Point position); void FocusOnCharInfo(); bool GetAsyncKeyState(int vKey); diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index 014f1023e..f20698f55 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -41,13 +41,13 @@ static std::deque message_queue; bool mouseWarping = false; Point mousePositionWarping; -void SetCursorPos(int x, int y) +void SetCursorPos(Point position) { - mousePositionWarping = { x, y }; + mousePositionWarping = position; mouseWarping = true; - LogicalToOutput(&x, &y); + LogicalToOutput(&position.x, &position.y); if (!demo::IsRunning()) - SDL_WarpMouseInWindow(ghMainWnd, x, y); + SDL_WarpMouseInWindow(ghMainWnd, position.x, position.y); } // Moves the mouse to the first attribute "+" button. @@ -68,7 +68,7 @@ void FocusOnCharInfo() if (stat == -1) return; const Rectangle &rect = ChrBtnsRect[stat]; - SetCursorPos(rect.position.x + (rect.size.width / 2), rect.position.y + (rect.size.height / 2)); + SetCursorPos({ rect.position.x + (rect.size.width / 2), rect.position.y + (rect.size.height / 2) }); } static int TranslateSdlKey(SDL_Keysym key)