Browse Source

♻️ Replace 'cursW' and 'cursH' globals with single 'cursSize'

pull/2753/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
a469f7906e
  1. 10
      Source/cursor.cpp
  2. 3
      Source/cursor.h
  3. 4
      Source/inv.cpp
  4. 10
      Source/scrollrt.cpp
  5. 2
      Source/stores.cpp
  6. 4
      test/cursor_test.cpp

10
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));

3
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;

4
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));
}
}
}

10
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);
}
/**

2
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)

4
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);

Loading…
Cancel
Save