diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index e36196c54..37ce185c1 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -494,7 +494,7 @@ void AttrIncBtnSnap(AxisDirection dir) Point InvGetEquipSlotCoord(const inv_body_loc invSlot) { Point result = GetPanelPosition(UiPanels::Inventory); - result.x -= (icursW28 - 1) * (InventorySlotSizeInPixels.width / 2); + result.x -= (icursSize28.width - 1) * (InventorySlotSizeInPixels.width / 2); switch (invSlot) { case INVLOC_HEAD: result.x += ((InvRect[SLOTXY_HEAD_FIRST].x + InvRect[SLOTXY_HEAD_LAST].x) / 2); @@ -683,7 +683,7 @@ void InvMove(AxisDirection dir) if (isHoldingItem) { if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { if (Slot == SLOTXY_INV_ROW1_FIRST || Slot == SLOTXY_INV_ROW2_FIRST || Slot == SLOTXY_INV_ROW3_FIRST || Slot == SLOTXY_INV_ROW4_FIRST) { - Slot += INV_ROW_SLOT_SIZE - icursW28; + Slot += INV_ROW_SLOT_SIZE - icursSize28.width; } else { Slot -= 1; } @@ -732,8 +732,8 @@ void InvMove(AxisDirection dir) if (isHoldingItem) { if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { if ( - Slot == SLOTXY_INV_ROW1_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW2_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW3_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW4_LAST + 1 - icursW28) { - Slot -= INV_ROW_SLOT_SIZE - icursW28; + Slot == SLOTXY_INV_ROW1_LAST + 1 - icursSize28.width || Slot == SLOTXY_INV_ROW2_LAST + 1 - icursSize28.width || Slot == SLOTXY_INV_ROW3_LAST + 1 - icursSize28.width || Slot == SLOTXY_INV_ROW4_LAST + 1 - icursSize28.width) { + Slot -= INV_ROW_SLOT_SIZE - icursSize28.width; } else { Slot += 1; } @@ -849,10 +849,10 @@ void InvMove(AxisDirection dir) } else if (Slot == SLOTXY_RING_RIGHT || Slot == SLOTXY_HAND_RIGHT_FIRST || Slot == SLOTXY_AMULET) { Slot = SLOTXY_INV_ROW1_LAST - 1; mousePos = InvGetSlotCoord(Slot); - } else if (Slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) { + } else if (Slot <= (SLOTXY_INV_ROW4_LAST - (icursSize28.height * INV_ROW_SLOT_SIZE))) { Slot += INV_ROW_SLOT_SIZE; mousePos = InvGetSlotCoord(Slot); - } else if (Slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items + } else if (Slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursSize28 == Size { 1, 1 }) { // forcing only 1x1 misc items Slot += INV_ROW_SLOT_SIZE; if (Slot > SLOTXY_BELT_LAST) Slot = SLOTXY_BELT_LAST; @@ -922,7 +922,7 @@ void InvMove(AxisDirection dir) if (Slot >= SLOTXY_INV_FIRST) mousePos.y -= InventorySlotSizeInPixels.height; else - mousePos.y -= (int)((icursH28 / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2); + mousePos.y -= (int)((icursSize28.height / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2); } else { mousePos.x += (InventorySlotSizeInPixels.width / 2); mousePos.y -= (InventorySlotSizeInPixels.height / 2); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index b24b2a414..a574a0a7d 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -105,10 +105,8 @@ const int InvItemHeight2[] = { Size cursSize; /** Current highlighted monster */ int pcursmonst = -1; -/** Width of current cursor in inventory cells */ -int icursW28; -/** Height of current cursor in inventory cells */ -int icursH28; +/** Size of current cursor in inventory cells */ +Size icursSize28; /** inv_item value */ int8_t pcursinvitem; @@ -169,8 +167,7 @@ void SetICursor(int cursId) auto size = GetInvItemSize(cursId); icursW = size.width; icursH = size.height; - icursW28 = icursW / 28; - icursH28 = icursH / 28; + icursSize28 = Size { icursW, icursH } / 28; } void NewCursor(int cursId) diff --git a/Source/cursor.h b/Source/cursor.h index 8645d0d37..35e751bbf 100644 --- a/Source/cursor.h +++ b/Source/cursor.h @@ -33,8 +33,7 @@ enum cursor_id : uint8_t { extern Size cursSize; extern int pcursmonst; -extern int icursW28; -extern int icursH28; +extern Size icursSize28; extern int icursH; extern int8_t pcursinvitem; extern int icursW; diff --git a/Source/inv.cpp b/Source/inv.cpp index 83acf6cf4..11dac3a0f 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -360,7 +360,7 @@ void CheckInvPaste(int pnum, Point cursorPosition) SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); int i = cursorPosition.x + (IsHardwareCursor() ? 0 : (icursW / 2)); int j = cursorPosition.y + (IsHardwareCursor() ? 0 : (icursH / 2)); - Size itemSize { icursW28, icursH28 }; + Size itemSize { icursSize28 }; bool done = false; int r = 0; for (; r < NUM_XY_SLOTS && !done; r++) { diff --git a/test/cursor_test.cpp b/test/cursor_test.cpp index d00e37b94..97ee8a6d9 100644 --- a/test/cursor_test.cpp +++ b/test/cursor_test.cpp @@ -14,6 +14,6 @@ TEST(Cursor, SetCursor) EXPECT_EQ(cursSize.height, 3 * 28); EXPECT_EQ(icursW, 1 * 28); EXPECT_EQ(icursH, 3 * 28); - EXPECT_EQ(icursW28, 1); - EXPECT_EQ(icursH28, 3); + EXPECT_EQ(icursSize28.width, 1); + EXPECT_EQ(icursSize28.height, 3); }