♻️ Leverage 'Point' in 'SetCursorPos' function
This commit is contained in:
parent
f90d3239e5
commit
6c21638bee
6 changed files with 28 additions and 27 deletions
|
|
@ -1088,7 +1088,7 @@ void DoSpeedBook()
|
|||
}
|
||||
}
|
||||
|
||||
SetCursorPos(x, y);
|
||||
SetCursorPos({ x, y });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#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);
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ static std::deque<tagMSG> 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue