diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 824f37355..b24b2a414 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -101,10 +101,8 @@ const int InvItemHeight2[] = { } // namespace -/** Pixel width of the current cursor image */ -int cursW; -/** Pixel height of the current cursor image */ -int cursH; +/** Pixel size of the current cursor image */ +Size cursSize; /** Current highlighted monster */ int pcursmonst = -1; /** Width of current cursor in inventory cells */ @@ -178,9 +176,7 @@ void SetICursor(int cursId) void NewCursor(int cursId) { pcurs = cursId; - auto size = GetInvItemSize(cursId); - cursW = size.width; - cursH = size.height; + cursSize = GetInvItemSize(cursId); SetICursor(cursId); if (IsHardwareCursorEnabled() && GetCurrentCursorInfo() != CursorInfo::GameCursor(cursId) && cursId != CURSOR_NONE) { SetHardwareCursor(CursorInfo::GameCursor(cursId)); diff --git a/Source/cursor.h b/Source/cursor.h index b2cd67ea6..8645d0d37 100644 --- a/Source/cursor.h +++ b/Source/cursor.h @@ -31,8 +31,7 @@ enum cursor_id : uint8_t { CURSOR_FIRSTITEM, }; -extern int cursW; -extern int cursH; +extern Size cursSize; extern int pcursmonst; extern int icursW28; extern int icursH28; diff --git a/Source/inv.cpp b/Source/inv.cpp index d0e68e930..83acf6cf4 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 + Displacement(Size { cursW, cursH } / 2)); + SetCursorPos(MousePosition + Displacement(cursSize / 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 - Displacement(Size { cursW, cursH } / 2)); + SetCursorPos(cursorPosition - Displacement(cursSize / 2)); } } } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 8d013cf32..c514cda4d 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -277,14 +277,14 @@ bool ShouldShowCursor() */ void DrawCursor(const Surface &out) { - if (pcurs <= CURSOR_NONE || cursW == 0 || cursH == 0 || !ShouldShowCursor()) { + if (pcurs <= CURSOR_NONE || cursSize.width == 0 || cursSize.height == 0 || !ShouldShowCursor()) { return; } // 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 (MousePosition.x < -cursW - outlineWidth || MousePosition.x - outlineWidth >= out.w() || MousePosition.y < -cursH - outlineWidth || MousePosition.y - outlineWidth >= out.h()) + if (MousePosition.x < -cursSize.width - outlineWidth || MousePosition.x - outlineWidth >= out.w() || MousePosition.y < -cursSize.height - outlineWidth || MousePosition.y - outlineWidth >= out.h()) return; constexpr auto Clip = [](int &pos, std::uint32_t &length, std::uint32_t posEnd) { @@ -297,15 +297,15 @@ void DrawCursor(const Surface &out) }; sgdwCursX = MousePosition.x - outlineWidth; - sgdwCursWdt = cursW + 2 * outlineWidth; + sgdwCursWdt = cursSize.width + 2 * outlineWidth; Clip(sgdwCursX, sgdwCursWdt, out.w()); sgdwCursY = MousePosition.y - outlineWidth; - sgdwCursHgt = cursH + 2 * outlineWidth; + sgdwCursHgt = cursSize.height + 2 * outlineWidth; Clip(sgdwCursY, sgdwCursHgt, out.h()); BlitCursor(sgSaveBack, sgdwCursWdt, out.at(sgdwCursX, sgdwCursY), out.pitch()); - CelDrawCursor(out, MousePosition + Displacement { 0, cursH - 1 }, pcurs); + CelDrawCursor(out, MousePosition + Displacement { 0, cursSize.height - 1 }, pcurs); } /** diff --git a/Source/stores.cpp b/Source/stores.cpp index 75f37999d..d037c6008 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -1429,7 +1429,7 @@ bool StoreGoldFit(int idx) sz++; NewCursor(storehold[idx]._iCurs + CURSOR_FIRSTITEM); - int numsqrs = cursW / 28 * (cursH / 28); + int numsqrs = cursSize.width / 28 * (cursSize.height / 28); NewCursor(CURSOR_HAND); if (numsqrs >= sz) diff --git a/test/cursor_test.cpp b/test/cursor_test.cpp index e3cf71a2d..d00e37b94 100644 --- a/test/cursor_test.cpp +++ b/test/cursor_test.cpp @@ -10,8 +10,8 @@ TEST(Cursor, SetCursor) int i = ICURS_SPIKED_CLUB + CURSOR_FIRSTITEM; NewCursor(i); EXPECT_EQ(pcurs, i); - EXPECT_EQ(cursW, 1 * 28); - EXPECT_EQ(cursH, 3 * 28); + EXPECT_EQ(cursSize.width, 1 * 28); + EXPECT_EQ(cursSize.height, 3 * 28); EXPECT_EQ(icursW, 1 * 28); EXPECT_EQ(icursH, 3 * 28); EXPECT_EQ(icursW28, 1);