Browse Source

♻️ Leverage 'Point' in 'InvDrawSlotBack' implementation

pull/2203/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
572c3e632e
  1. 23
      Source/inv.cpp

23
Source/inv.cpp

@ -161,19 +161,18 @@ void InitInv()
drawsbarflag = false; drawsbarflag = false;
} }
static void InvDrawSlotBack(const CelOutputBuffer &out, int x, int y, int w, int h) static void InvDrawSlotBack(const CelOutputBuffer &out, Point targetPosition, Size size)
{ {
SDL_Rect srcRect = MakeSdlRect(0, 0, w, h); SDL_Rect srcRect = MakeSdlRect(0, 0, size.width, size.height);
Point targetPosition { x, y };
out.Clip(&srcRect, &targetPosition); out.Clip(&srcRect, &targetPosition);
if (srcRect.w <= 0 || srcRect.h <= 0) if (size.width <= 0 || size.height <= 0)
return; return;
std::uint8_t *dst = &out[targetPosition]; std::uint8_t *dst = &out[targetPosition];
const auto dstPitch = out.pitch(); const auto dstPitch = out.pitch();
for (int hgt = srcRect.h; hgt != 0; hgt--, dst -= dstPitch + w) { for (int hgt = size.height; hgt != 0; hgt--, dst -= dstPitch + size.width) {
for (int wdt = srcRect.w; wdt != 0; wdt--) { for (int wdt = size.width; wdt != 0; wdt--) {
std::uint8_t pix = *dst; std::uint8_t pix = *dst;
if (pix >= PAL16_BLUE) { if (pix >= PAL16_BLUE) {
if (pix <= PAL16_BLUE + 15) if (pix <= PAL16_BLUE + 15)
@ -216,7 +215,7 @@ void DrawInv(const CelOutputBuffer &out)
if (!myPlayer.InvBody[slot].isEmpty()) { if (!myPlayer.InvBody[slot].isEmpty()) {
int screenX = slotPos[slot].x; int screenX = slotPos[slot].x;
int screenY = slotPos[slot].y; int screenY = slotPos[slot].y;
InvDrawSlotBack(out, RIGHT_PANEL_X + screenX, screenY, slotSize[slot].width * InventorySlotSizeInPixels.width, slotSize[slot].height * InventorySlotSizeInPixels.height); InvDrawSlotBack(out, { RIGHT_PANEL_X + screenX, screenY }, { slotSize[slot].width * InventorySlotSizeInPixels.width, slotSize[slot].height * InventorySlotSizeInPixels.height });
int frame = myPlayer.InvBody[slot]._iCurs + CURSOR_FIRSTITEM; int frame = myPlayer.InvBody[slot]._iCurs + CURSOR_FIRSTITEM;
@ -248,7 +247,7 @@ void DrawInv(const CelOutputBuffer &out)
if (myPlayer._pClass != HeroClass::Barbarian if (myPlayer._pClass != HeroClass::Barbarian
|| (myPlayer.InvBody[slot]._itype != ITYPE_SWORD || (myPlayer.InvBody[slot]._itype != ITYPE_SWORD
&& myPlayer.InvBody[slot]._itype != ITYPE_MACE)) { && myPlayer.InvBody[slot]._itype != ITYPE_MACE)) {
InvDrawSlotBack(out, RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].x, slotPos[INVLOC_HAND_RIGHT].y, slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height); InvDrawSlotBack(out, { RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].x, slotPos[INVLOC_HAND_RIGHT].y }, { slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height });
light_table_index = 0; light_table_index = 0;
cel_transparency_active = true; cel_transparency_active = true;
@ -267,10 +266,8 @@ void DrawInv(const CelOutputBuffer &out)
if (myPlayer.InvGrid[i] != 0) { if (myPlayer.InvGrid[i] != 0) {
InvDrawSlotBack( InvDrawSlotBack(
out, out,
InvRect[i + SLOTXY_INV_FIRST].x + RIGHT_PANEL_X, InvRect[i + SLOTXY_INV_FIRST] + Point { RIGHT_PANEL_X, -1 },
InvRect[i + SLOTXY_INV_FIRST].y - 1, InventorySlotSizeInPixels);
InventorySlotSizeInPixels.width,
InventorySlotSizeInPixels.height);
} }
} }
@ -315,7 +312,7 @@ void DrawInvBelt(const CelOutputBuffer &out)
} }
const Point position { InvRect[i + SLOTXY_BELT_FIRST].x + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].y + PANEL_Y - 1 }; const Point position { InvRect[i + SLOTXY_BELT_FIRST].x + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].y + PANEL_Y - 1 };
InvDrawSlotBack(out, position.x, position.y, InventorySlotSizeInPixels.width, InventorySlotSizeInPixels.height); InvDrawSlotBack(out, position, InventorySlotSizeInPixels);
int frame = myPlayer.SpdList[i]._iCurs + CURSOR_FIRSTITEM; int frame = myPlayer.SpdList[i]._iCurs + CURSOR_FIRSTITEM;
const auto &cel = GetInvItemSprite(frame); const auto &cel = GetInvItemSprite(frame);

Loading…
Cancel
Save