diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index ba4f0ad6a..150fe4526 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -580,7 +580,7 @@ Point BeltGetSlotCoord(int slot) /** * Get item size (grid size) on the slot specified. Returns 1x1 if none exists. */ -std::pair GetItemSizeOnSlot(int slot, char &itemInvId) +Size GetItemSizeOnSlot(int slot, char &itemInvId) { if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { int ig = slot - SLOTXY_INV_FIRST; @@ -594,9 +594,9 @@ std::pair GetItemSizeOnSlot(int slot, char &itemInvId) ItemStruct &item = myPlayer.InvList[iv - 1]; if (!item.isEmpty()) { - std::pair size = GetInvItemSize(item._iCurs + CURSOR_FIRSTITEM); - size.first /= InventorySlotSizeInPixels.width; - size.second /= InventorySlotSizeInPixels.height; + auto size = GetInvItemSize(item._iCurs + CURSOR_FIRSTITEM); + size.width /= InventorySlotSizeInPixels.width; + size.height /= InventorySlotSizeInPixels.height; itemInvId = ii; return size; @@ -616,10 +616,8 @@ void ResetInvCursorPosition() if (slot < SLOTXY_INV_FIRST) { mousePos = InvGetEquipSlotCoordFromInvSlot((inv_xy_slot)slot); } else if (slot < SLOTXY_BELT_FIRST) { - int itemSizeX; - int itemSizeY; char itemInvId; - std::tie(itemSizeX, itemSizeY) = GetItemSizeOnSlot(slot, itemInvId); + auto itemSize = GetItemSizeOnSlot(slot, itemInvId); // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId if (itemInvId < 0) { @@ -632,10 +630,10 @@ void ResetInvCursorPosition() } // offset the slot to always move to the top-left most slot of that item - slot -= ((itemSizeY - 1) * INV_ROW_SLOT_SIZE); + slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); mousePos = InvGetSlotCoord(slot); - mousePos.x += ((itemSizeX - 1) * InventorySlotSizeInPixels.width) / 2; - mousePos.y += ((itemSizeY - 1) * InventorySlotSizeInPixels.height) / 2; + mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2; + mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2; } else { mousePos = BeltGetSlotCoord(slot); } @@ -658,10 +656,8 @@ void InvMove(AxisDirection dir) if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) return; - int itemSizeX; - int itemSizeY; char itemInvId; - std::tie(itemSizeX, itemSizeY) = GetItemSizeOnSlot(slot, itemInvId); + auto itemSize = GetItemSizeOnSlot(slot, itemInvId); Point mousePos { MouseX, MouseY }; @@ -774,10 +770,10 @@ void InvMove(AxisDirection dir) mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); } else if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { if ( - slot == SLOTXY_INV_ROW1_LAST + 1 - itemSizeX || slot == SLOTXY_INV_ROW2_LAST + 1 - itemSizeX || slot == SLOTXY_INV_ROW3_LAST + 1 - itemSizeX || slot == SLOTXY_INV_ROW4_LAST + 1 - itemSizeX) { - slot -= INV_ROW_SLOT_SIZE - itemSizeX; + slot == SLOTXY_INV_ROW1_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW2_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW3_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW4_LAST + 1 - itemSize.width) { + slot -= INV_ROW_SLOT_SIZE - itemSize.width; } else { - slot += itemSizeX; + slot += itemSize.width; } mousePos = InvGetSlotCoord(slot); } else if (slot >= SLOTXY_BELT_FIRST && slot < SLOTXY_BELT_LAST) { @@ -886,11 +882,11 @@ void InvMove(AxisDirection dir) } else if (slot == SLOTXY_HAND_RIGHT_FIRST) { slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); - } else if (slot <= (SLOTXY_INV_ROW4_LAST - (itemSizeY * INV_ROW_SLOT_SIZE))) { - slot += itemSizeY * INV_ROW_SLOT_SIZE; + } else if (slot <= (SLOTXY_INV_ROW4_LAST - (itemSize.height * INV_ROW_SLOT_SIZE))) { + slot += itemSize.height * INV_ROW_SLOT_SIZE; mousePos = InvGetSlotCoord(slot); } else if (slot <= SLOTXY_INV_LAST) { - slot += itemSizeY * INV_ROW_SLOT_SIZE; + slot += itemSize.height * INV_ROW_SLOT_SIZE; if (slot > SLOTXY_BELT_LAST) slot = SLOTXY_BELT_LAST; mousePos = BeltGetSlotCoord(slot); @@ -904,7 +900,7 @@ void InvMove(AxisDirection dir) // get item under new slot if navigating on the inventory if (!isHoldingItem && slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { - std::tie(itemSizeX, itemSizeY) = GetItemSizeOnSlot(slot, itemInvId); + itemSize = GetItemSizeOnSlot(slot, itemInvId); // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId if (itemInvId < 0) { @@ -917,10 +913,10 @@ void InvMove(AxisDirection dir) } // offset the slot to always move to the top-left most slot of that item - slot -= ((itemSizeY - 1) * INV_ROW_SLOT_SIZE); + slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); mousePos = InvGetSlotCoord(slot); - mousePos.x += ((itemSizeX - 1) * InventorySlotSizeInPixels.width) / 2; - mousePos.y += ((itemSizeY - 1) * InventorySlotSizeInPixels.height) / 2; + mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2; + mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2; } // move cursor to the center of the slot if not holding anything or top left is holding an object diff --git a/Source/cursor.cpp b/Source/cursor.cpp index f6a0dc67d..4b53afd9f 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -157,7 +157,7 @@ int GetInvItemFrame(int i) return i < InvItems1Size ? i : i - (InvItems1Size - 1); } -std::pair GetInvItemSize(int i) +Size GetInvItemSize(int i) { if (i >= InvItems1Size) return { InvItemWidth2[i - (InvItems1Size - 1)], InvItemHeight2[i - (InvItems1Size - 1)] }; @@ -166,7 +166,9 @@ std::pair GetInvItemSize(int i) void SetICursor(int i) { - std::tie(icursW, icursH) = GetInvItemSize(i); + auto size = GetInvItemSize(i); + icursW = size.width; + icursH = size.height; icursW28 = icursW / 28; icursH28 = icursH / 28; } @@ -174,7 +176,9 @@ void SetICursor(int i) void NewCursor(int i) { pcurs = i; - std::tie(cursW, cursH) = GetInvItemSize(i); + auto size = GetInvItemSize(i); + cursW = size.width; + cursH = size.height; SetICursor(i); if (IsHardwareCursorEnabled() && GetCurrentCursorInfo() != CursorInfo::GameCursor(pcurs) && pcurs != CURSOR_NONE) { SetHardwareCursor(CursorInfo::GameCursor(pcurs)); diff --git a/Source/cursor.h b/Source/cursor.h index a5153647e..6d02f486a 100644 --- a/Source/cursor.h +++ b/Source/cursor.h @@ -68,6 +68,6 @@ const CelSprite &GetInvItemSprite(int i); int GetInvItemFrame(int i); /** Returns the width and height for an inventory index. */ -std::pair GetInvItemSize(int i); +Size GetInvItemSize(int i); } // namespace devilution diff --git a/Source/hwcursor.cpp b/Source/hwcursor.cpp index 7697d6fe8..87d7deb41 100644 --- a/Source/hwcursor.cpp +++ b/Source/hwcursor.cpp @@ -75,13 +75,11 @@ bool SetHardwareCursorFromSprite(int pcurs) const bool isItem = IsItemSprite(pcurs); const int outlineWidth = isItem ? 1 : 0; - int width; - int height; - std::tie(width, height) = GetInvItemSize(pcurs); - width += 2 * outlineWidth; - height += 2 * outlineWidth; + auto size = GetInvItemSize(pcurs); + size.width += 2 * outlineWidth; + size.height += 2 * outlineWidth; - auto out = CelOutputBuffer::Alloc(width, height); + auto out = CelOutputBuffer::Alloc(size.width, size.height); SDL_SetSurfacePalette(out.surface, palette); // Transparent color must not be used in the sprite itself. @@ -89,7 +87,7 @@ bool SetHardwareCursorFromSprite(int pcurs) constexpr std::uint8_t TransparentColor = 1; SDL_FillRect(out.surface, nullptr, TransparentColor); SDL_SetColorKey(out.surface, 1, TransparentColor); - CelDrawCursor(out, { outlineWidth, height - outlineWidth }, pcurs); + CelDrawCursor(out, { outlineWidth, size.height - outlineWidth }, pcurs); const bool result = SetHardwareCursor(out.surface, isItem ? HotpointPosition::Center : HotpointPosition::TopLeft); out.Free(); diff --git a/Source/inv.cpp b/Source/inv.cpp index 6f27281e2..cb6095b6d 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -219,17 +219,15 @@ void DrawInv(const CelOutputBuffer &out) int frame = myPlayer.InvBody[slot]._iCurs + CURSOR_FIRSTITEM; - int frameW; - int frameH; - std::tie(frameW, frameH) = GetInvItemSize(frame); + auto frameSize = GetInvItemSize(frame); // calc item offsets for weapons smaller than 2x3 slots if (slot == INVLOC_HAND_LEFT) { - screenX += frameW == InventorySlotSizeInPixels.width ? 14 : 0; - screenY += frameH == (3 * InventorySlotSizeInPixels.height) ? 0 : -14; + screenX += frameSize.width == InventorySlotSizeInPixels.width ? 14 : 0; + screenY += frameSize.height == (3 * InventorySlotSizeInPixels.height) ? 0 : -14; } else if (slot == INVLOC_HAND_RIGHT) { - screenX += frameW == InventorySlotSizeInPixels.width ? 13 : 1; - screenY += frameH == (3 * InventorySlotSizeInPixels.height) ? 0 : -14; + screenX += frameSize.width == InventorySlotSizeInPixels.width ? 13 : 1; + screenY += frameSize.height == (3 * InventorySlotSizeInPixels.height) ? 0 : -14; } const auto &cel = GetInvItemSprite(frame); @@ -251,7 +249,7 @@ void DrawInv(const CelOutputBuffer &out) light_table_index = 0; cel_transparency_active = true; - const int dstX = RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].x + (frameW == InventorySlotSizeInPixels.width ? 13 : -1); + const int dstX = RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].x + (frameSize.width == InventorySlotSizeInPixels.width ? 13 : -1); const int dstY = slotPos[INVLOC_HAND_RIGHT].y; CelClippedBlitLightTransTo(out, { dstX, dstY }, cel, celFrame); @@ -369,10 +367,9 @@ static void AddItemToInvGrid(PlayerStruct &player, int invGridIndex, int invList Size GetInventorySize(const ItemStruct &item) { int itemSizeIndex = item._iCurs + CURSOR_FIRSTITEM; - int w; - int h; - std::tie(w, h) = GetInvItemSize(itemSizeIndex); - return { w / InventorySlotSizeInPixels.width, h / InventorySlotSizeInPixels.height }; + auto size = GetInvItemSize(itemSizeIndex); + + return { size.width / InventorySlotSizeInPixels.width, size.height / InventorySlotSizeInPixels.height }; } /**