diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 8788e30f4..1e9dfd380 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -713,7 +713,7 @@ void UiAddLogo(std::vector> *vecDialog, int size, in { SDL_Rect rect = MakeSdlRect(0, GetUIRectangle().position.y + y, 0, 0); vecDialog->push_back(std::make_unique( - CelSpriteWithFrameHeight { ArtLogos[size]->sprite, ArtLogos[size]->frameHeight }, rect, UiFlags::AlignCenter, /*bAnimated=*/true)); + CelSpriteWithFrameHeight { CelSprite { ArtLogos[size]->sprite }, ArtLogos[size]->frameHeight }, rect, UiFlags::AlignCenter, /*bAnimated=*/true)); } void UiFadeIn() @@ -756,7 +756,7 @@ void DrawSelector(const SDL_Rect &rect) size = FOCUS_BIG; else if (rect.h >= 30) size = FOCUS_MED; - CelSpriteWithFrameHeight sprite { ArtFocus[size]->sprite, ArtFocus[size]->frameHeight }; + CelSpriteWithFrameHeight sprite { CelSprite { ArtFocus[size]->sprite }, ArtFocus[size]->frameHeight }; // TODO FOCUS_MED appares higher than the box const int y = rect.y + (rect.h - static_cast(sprite.frameHeight)) / 2; diff --git a/Source/control.cpp b/Source/control.cpp index 34549e92f..03a7b217b 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -314,7 +314,7 @@ int DrawDurIcon4Item(const Surface &out, Item &pItem, int x, int c) } if (pItem._iDurability > 2) c += 8; - CelDrawTo(out, { x, -17 + GetMainPanel().position.y }, *pDurIcons, c); + CelDrawTo(out, { x, -17 + GetMainPanel().position.y }, CelSprite { *pDurIcons }, c); return x - 32 - 8; } @@ -548,16 +548,22 @@ void InitControlPan() LoadCharPanel(); LoadSpellIcons(); - CelDrawUnsafeTo(*pBtmBuff, { 0, (GetMainPanel().size.height + 16) - 1 }, LoadCel("CtrlPan\\Panel8.CEL", GetMainPanel().size.width), 0); + { + const OwnedCelSprite sprite = LoadCel("CtrlPan\\Panel8.CEL", GetMainPanel().size.width); + CelDrawUnsafeTo(*pBtmBuff, { 0, (GetMainPanel().size.height + 16) - 1 }, CelSprite { sprite }, 0); + } { const Point bulbsPosition { 0, 87 }; const OwnedCelSprite statusPanel = LoadCel("CtrlPan\\P8Bulbs.CEL", 88); - CelDrawUnsafeTo(*pLifeBuff, bulbsPosition, statusPanel, 0); - CelDrawUnsafeTo(*pManaBuff, bulbsPosition, statusPanel, 1); + CelDrawUnsafeTo(*pLifeBuff, bulbsPosition, CelSprite { statusPanel }, 0); + CelDrawUnsafeTo(*pManaBuff, bulbsPosition, CelSprite { statusPanel }, 1); } talkflag = false; if (IsChatAvailable()) { - CelDrawUnsafeTo(*pBtmBuff, { 0, (GetMainPanel().size.height + 16) * 2 - 1 }, LoadCel("CtrlPan\\TalkPanl.CEL", GetMainPanel().size.width), 0); + { + const OwnedCelSprite sprite = LoadCel("CtrlPan\\TalkPanl.CEL", GetMainPanel().size.width); + CelDrawUnsafeTo(*pBtmBuff, { 0, (GetMainPanel().size.height + 16) * 2 - 1 }, CelSprite { sprite }, 0); + } multiButtons = LoadCel("CtrlPan\\P8But2.CEL", 33); talkButtons = LoadCel("CtrlPan\\TalkButt.CEL", 61); sgbPlrTalkTbl = 0; @@ -617,16 +623,17 @@ void DrawCtrlBtns(const Surface &out) DrawPanelBox(out, MakeSdlRect(PanBtnPos[i].x, PanBtnPos[i].y + 16, 71, 20), mainPanelPosition + Displacement { PanBtnPos[i].x, PanBtnPos[i].y }); } else { Point position = mainPanelPosition + Displacement { PanBtnPos[i].x, PanBtnPos[i].y + 18 }; - CelDrawTo(out, position, *pPanelButtons, i); + CelDrawTo(out, position, CelSprite { *pPanelButtons }, i); DrawArt(out, position + Displacement { 4, -18 }, &PanelButtonDown, i); } } if (PanelButtonIndex == 8) { - CelDrawTo(out, mainPanelPosition + Displacement { 87, 122 }, *multiButtons, PanelButtons[6] ? 1 : 0); + CelSprite sprite { *multiButtons }; + CelDrawTo(out, mainPanelPosition + Displacement { 87, 122 }, sprite, PanelButtons[6] ? 1 : 0); if (MyPlayer->friendlyMode) - CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, *multiButtons, PanelButtons[7] ? 3 : 2); + CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, sprite, PanelButtons[7] ? 3 : 2); else - CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, *multiButtons, PanelButtons[7] ? 5 : 4); + CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, sprite, PanelButtons[7] ? 5 : 4); } } @@ -951,7 +958,7 @@ void DrawLevelUpIcon(const Surface &out) if (IsLevelUpButtonVisible()) { int nCel = lvlbtndown ? 2 : 1; DrawString(out, _("Level Up"), { GetMainPanel().position + Displacement { 0, -62 }, { 120, 0 } }, UiFlags::ColorWhite | UiFlags::AlignCenter); - CelDrawTo(out, GetMainPanel().position + Displacement { 40, -17 }, *pChrButtons, nCel); + CelDrawTo(out, GetMainPanel().position + Displacement { 40, -17 }, CelSprite { *pChrButtons }, nCel); } } @@ -1053,7 +1060,7 @@ void DrawGoldSplit(const Surface &out, int amount) { const int dialogX = 30; - CelDrawTo(out, GetPanelPosition(UiPanels::Inventory, { dialogX, 178 }), *pGBoxBuff, 0); + CelDrawTo(out, GetPanelPosition(UiPanels::Inventory, { dialogX, 178 }), CelSprite { *pGBoxBuff }, 0); const std::string description = fmt::format( fmt::runtime(ngettext( @@ -1142,14 +1149,14 @@ void DrawTalkPan(const Surface &out) if (WhisperList[i]) { if (TalkButtonsDown[talkBtn]) { int nCel = talkBtn != 0 ? 3 : 2; - CelDrawTo(out, talkPanPosition, *talkButtons, nCel); + CelDrawTo(out, talkPanPosition, CelSprite { *talkButtons }, nCel); DrawArt(out, talkPanPosition + Displacement { 4, -15 }, &TalkButton, 2); } } else { int nCel = talkBtn != 0 ? 1 : 0; if (TalkButtonsDown[talkBtn]) nCel += 4; - CelDrawTo(out, talkPanPosition, *talkButtons, nCel); + CelDrawTo(out, talkPanPosition, CelSprite { *talkButtons }, nCel); DrawArt(out, talkPanPosition + Displacement { 4, -15 }, &TalkButton, TalkButtonsDown[talkBtn] ? 1 : 0); } if (player.plractive) { diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 26b7244a7..06d4c3fec 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -141,7 +141,7 @@ void LoadPotionArt(Art *potionArt, SDL_Renderer *renderer) for (item_cursor_graphic graphic : potionGraphics) { const int cursorID = static_cast(CURSOR_FIRSTITEM) + graphic; const int frame = GetInvItemFrame(cursorID); - const OwnedCelSprite &potionSprite = GetInvItemSprite(cursorID); + const CelSprite potionSprite { GetInvItemSprite(cursorID) }; position.y += potionSize.height; CelClippedDrawTo(Surface(surface.get()), position, potionSprite, frame); } diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 0acf62015..1ccb86b16 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -195,7 +195,7 @@ void NewCursor(int cursId) void CelDrawCursor(const Surface &out, Point position, int cursId) { - const auto &sprite = GetInvItemSprite(cursId); + const CelSprite sprite { GetInvItemSprite(cursId) }; const int frame = GetInvItemFrame(cursId); if (!MyPlayer->HoldItem.isEmpty()) { const auto &heldItem = MyPlayer->HoldItem; diff --git a/Source/doom.cpp b/Source/doom.cpp index d9f008b53..ab8522473 100644 --- a/Source/doom.cpp +++ b/Source/doom.cpp @@ -37,7 +37,7 @@ void doom_draw(const Surface &out) return; } - CelDrawTo(out, GetUIRectangle().position + Displacement { 0, 352 }, *DoomCel, 0); + CelDrawTo(out, GetUIRectangle().position + Displacement { 0, 352 }, CelSprite { *DoomCel }, 0); } } // namespace devilution diff --git a/Source/engine/cel_sprite.hpp b/Source/engine/cel_sprite.hpp index 6788bdf11..2161a16d5 100644 --- a/Source/engine/cel_sprite.hpp +++ b/Source/engine/cel_sprite.hpp @@ -28,6 +28,12 @@ public: { } + CelSprite(const byte *data, PointerOrValue widths) + : data_ptr_(data) + , width_(widths) + { + } + explicit CelSprite(const OwnedCelSprite &owned); CelSprite(const CelSprite &) = default; @@ -63,17 +69,17 @@ private: * Stores a CEL or CL2 sprite and its width(s). * Owns the data. */ -class OwnedCelSprite : public CelSprite { +class OwnedCelSprite { public: OwnedCelSprite(std::unique_ptr data, uint16_t width) - : CelSprite(data.get(), width) - , data_(std::move(data)) + : data_(std::move(data)) + , width_(width) { } OwnedCelSprite(std::unique_ptr data, const uint16_t *widths) - : CelSprite(data.get(), widths) - , data_(std::move(data)) + : data_(std::move(data)) + , width_(widths) { } @@ -87,10 +93,13 @@ public: private: std::unique_ptr data_; + PointerOrValue width_; + + friend class CelSprite; }; inline CelSprite::CelSprite(const OwnedCelSprite &owned) - : CelSprite(static_cast(owned)) + : CelSprite(owned.data_.get(), owned.width_) { } diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index b7f2f1acc..08c6e9348 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -650,7 +650,7 @@ uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect, const int bytesDrawn = DoDrawString(out, text, rect, characterPosition, spacing, lineHeight, lineWidth, rightMargin, bottomMargin, flags, size, color); if (HasAnyOf(flags, UiFlags::PentaCursor)) { - CelDrawTo(out, characterPosition + Displacement { 0, lineHeight - BaseLineOffset[size] }, *pSPentSpn2Cels, PentSpn2Spin()); + CelDrawTo(out, characterPosition + Displacement { 0, lineHeight - BaseLineOffset[size] }, CelSprite { *pSPentSpn2Cels }, PentSpn2Spin()); } else if (HasAnyOf(flags, UiFlags::TextCursor) && GetAnimationFrame(2, 500) != 0) { DrawFont(out, characterPosition, LoadFont(size, color, 0), color, '|'); } @@ -758,7 +758,7 @@ void DrawStringWithColors(const Surface &out, string_view fmt, DrawStringFormatA } if (HasAnyOf(flags, UiFlags::PentaCursor)) { - CelDrawTo(out, characterPosition + Displacement { 0, lineHeight - BaseLineOffset[size] }, *pSPentSpn2Cels, PentSpn2Spin()); + CelDrawTo(out, characterPosition + Displacement { 0, lineHeight - BaseLineOffset[size] }, CelSprite { *pSPentSpn2Cels }, PentSpn2Spin()); } else if (HasAnyOf(flags, UiFlags::TextCursor) && GetAnimationFrame(2, 500) != 0) { DrawFont(out, characterPosition, LoadFont(size, color, 0), color, '|'); } diff --git a/Source/error.cpp b/Source/error.cpp index a96f10fe0..d88e24ae3 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -144,21 +144,22 @@ void DrawDiabloMsg(const Surface &out) auto &uiRectanglePosition = GetUIRectangle().position; int dialogStartY = ((gnScreenHeight - GetMainPanel().size.height) / 2) - (ErrorWindowHeight / 2) + 9; - CelDrawTo(out, { uiRectanglePosition.x + 101, dialogStartY }, *pSTextSlidCels, 0); - CelDrawTo(out, { uiRectanglePosition.x + 101, dialogStartY + ErrorWindowHeight - 6 }, *pSTextSlidCels, 1); - CelDrawTo(out, { uiRectanglePosition.x + 527, dialogStartY + ErrorWindowHeight - 6 }, *pSTextSlidCels, 2); - CelDrawTo(out, { uiRectanglePosition.x + 527, dialogStartY }, *pSTextSlidCels, 3); + CelSprite sprite { *pSTextSlidCels }; + CelDrawTo(out, { uiRectanglePosition.x + 101, dialogStartY }, sprite, 0); + CelDrawTo(out, { uiRectanglePosition.x + 101, dialogStartY + ErrorWindowHeight - 6 }, sprite, 1); + CelDrawTo(out, { uiRectanglePosition.x + 527, dialogStartY + ErrorWindowHeight - 6 }, sprite, 2); + CelDrawTo(out, { uiRectanglePosition.x + 527, dialogStartY }, sprite, 3); int sx = uiRectanglePosition.x + 109; for (int i = 0; i < 35; i++) { - CelDrawTo(out, { sx, dialogStartY }, *pSTextSlidCels, 4); - CelDrawTo(out, { sx, dialogStartY + ErrorWindowHeight - 6 }, *pSTextSlidCels, 6); + CelDrawTo(out, { sx, dialogStartY }, sprite, 4); + CelDrawTo(out, { sx, dialogStartY + ErrorWindowHeight - 6 }, sprite, 6); sx += 12; } int drawnYborder = 12; while ((drawnYborder + 12) < ErrorWindowHeight) { - CelDrawTo(out, { uiRectanglePosition.x + 101, dialogStartY + drawnYborder }, *pSTextSlidCels, 5); - CelDrawTo(out, { uiRectanglePosition.x + 527, dialogStartY + drawnYborder }, *pSTextSlidCels, 7); + CelDrawTo(out, { uiRectanglePosition.x + 101, dialogStartY + drawnYborder }, sprite, 5); + CelDrawTo(out, { uiRectanglePosition.x + 527, dialogStartY + drawnYborder }, sprite, 7); drawnYborder += 12; } diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 64ba28542..22336a8f9 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -107,20 +107,21 @@ void GmenuDrawMenuItem(const Surface &out, TMenuItem *pItem, int y) if ((pItem->dwFlags & GMENU_SLIDER) != 0) { int uiPositionX = GetUIRectangle().position.x; int x = 16 + w / 2; - CelDrawTo(out, { x + uiPositionX, y + 40 }, *optbar_cel, 0); + CelDrawTo(out, { x + uiPositionX, y + 40 }, CelSprite { *optbar_cel }, 0); uint16_t step = pItem->dwFlags & 0xFFF; uint16_t steps = std::max((pItem->dwFlags & 0xFFF000) >> 12, 2); uint16_t pos = step * 256 / steps; GmenuClearBuffer(out, x + 2 + uiPositionX, y + 38, pos + 13, 28); - CelDrawTo(out, { x + 2 + pos + uiPositionX, y + 38 }, *option_cel, 0); + CelDrawTo(out, { x + 2 + pos + uiPositionX, y + 38 }, CelSprite { *option_cel }, 0); } int x = (gnScreenWidth - w) / 2; UiFlags style = (pItem->dwFlags & GMENU_ENABLED) != 0 ? UiFlags::ColorGold : UiFlags::ColorBlack; DrawString(out, _(pItem->pszStr), Point { x, y }, style | UiFlags::FontSize46, 2); if (pItem == sgpCurrItem) { - CelDrawTo(out, { x - 54, y + 51 }, *PentSpin_cel, PentSpn2Spin()); - CelDrawTo(out, { x + 4 + w, y + 51 }, *PentSpin_cel, PentSpn2Spin()); + CelSprite sprite { *PentSpin_cel }; + CelDrawTo(out, { x - 54, y + 51 }, sprite, PentSpn2Spin()); + CelDrawTo(out, { x + 4 + w, y + 51 }, sprite, PentSpn2Spin()); } } @@ -240,7 +241,8 @@ void gmenu_draw(const Surface &out) } } int uiPositionY = GetUIRectangle().position.y; - CelDrawTo(out, { (gnScreenWidth - sgpLogo->Width()) / 2, 102 + uiPositionY }, *sgpLogo, LogoAnim_frame); + CelSprite sprite { *sgpLogo }; + CelDrawTo(out, { (gnScreenWidth - sprite.Width()) / 2, 102 + uiPositionY }, sprite, LogoAnim_frame); int y = 110 + uiPositionY; TMenuItem *i = sgpCurrentMenu; if (sgpCurrentMenu->fnMenu != nullptr) { diff --git a/Source/interfac.cpp b/Source/interfac.cpp index e03a6617a..eacb38db4 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -180,7 +180,7 @@ void DrawCutsceneBackground() const PcxSprite sprite { *ArtCutsceneWidescreen }; RenderPcxSprite(out, sprite, { uiRectangle.position.x - (sprite.width() - uiRectangle.size.width) / 2, uiRectangle.position.y }); } - CelDrawTo(out, { uiRectangle.position.x, 480 - 1 + uiRectangle.position.y }, *sgpBackCel, 0); + CelDrawTo(out, { uiRectangle.position.x, 480 - 1 + uiRectangle.position.y }, CelSprite { *sgpBackCel }, 0); } void DrawCutsceneForeground() diff --git a/Source/inv.cpp b/Source/inv.cpp index 234ae98d4..08c026266 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1130,7 +1130,7 @@ void InitInv() void DrawInv(const Surface &out) { - CelDrawTo(out, GetPanelPosition(UiPanels::Inventory, { 0, 351 }), *pInvCels, 0); + CelDrawTo(out, GetPanelPosition(UiPanels::Inventory, { 0, 351 }), CelSprite { *pInvCels }, 0); Size slotSize[] = { { 2, 2 }, // head @@ -1173,7 +1173,7 @@ void DrawInv(const Surface &out) screenY += frameSize.height == (3 * InventorySlotSizeInPixels.height) ? 0 : -INV_SLOT_HALF_SIZE_PX; } - const auto &cel = GetInvItemSprite(cursId); + const CelSprite cel { GetInvItemSprite(cursId) }; const int celFrame = GetInvItemFrame(cursId); const Point position = GetPanelPosition(UiPanels::Inventory, { screenX, screenY }); @@ -1213,7 +1213,7 @@ void DrawInv(const Surface &out) int ii = myPlayer.InvGrid[j] - 1; int cursId = myPlayer.InvList[ii]._iCurs + CURSOR_FIRSTITEM; - const auto &cel = GetInvItemSprite(cursId); + const CelSprite cel { GetInvItemSprite(cursId) }; const int celFrame = GetInvItemFrame(cursId); const Point position = GetPanelPosition(UiPanels::Inventory, InvRect[j + SLOTXY_INV_FIRST]) + Displacement { 0, -1 }; if (pcursinvitem == ii + INVITEM_INV_FIRST) { @@ -1254,7 +1254,7 @@ void DrawInvBelt(const Surface &out) InvDrawSlotBack(out, position, InventorySlotSizeInPixels); const int cursId = myPlayer.SpdList[i]._iCurs + CURSOR_FIRSTITEM; - const auto &cel = GetInvItemSprite(cursId); + const CelSprite cel { GetInvItemSprite(cursId) }; const int celFrame = GetInvItemFrame(cursId); if (pcursinvitem == i + INVITEM_BELT_FIRST) { diff --git a/Source/items.cpp b/Source/items.cpp index d4a480452..daa913d3b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1775,7 +1775,7 @@ void PrintItemOil(char iDidx) void DrawUniqueInfoWindow(const Surface &out) { - CelDrawTo(out, GetPanelPosition(UiPanels::Inventory, { 24 - SidePanelSize.width, 327 }), *pSTextBoxCels, 0); + CelDrawTo(out, GetPanelPosition(UiPanels::Inventory, { 24 - SidePanelSize.width, 327 }), CelSprite { *pSTextBoxCels }, 0); DrawHalfTransparentRectTo(out, GetRightPanel().position.x - SidePanelSize.width + 27, GetRightPanel().position.y + 28, 265, 297); } diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 110a6b8d4..0cd332094 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -146,7 +146,7 @@ void InitQTextMsg(_speech_id m) void DrawQTextBack(const Surface &out) { const Point uiPosition = GetUIRectangle().position; - CelDrawTo(out, uiPosition + Displacement { 24, 327 }, *pTextBoxCels, 0); + CelDrawTo(out, uiPosition + Displacement { 24, 327 }, CelSprite { *pTextBoxCels }, 0); DrawHalfTransparentRectTo(out, uiPosition.x + 27, uiPosition.y + 28, 585, 297); } diff --git a/Source/panels/charpanel.cpp b/Source/panels/charpanel.cpp index a54c8308d..c4276382d 100644 --- a/Source/panels/charpanel.cpp +++ b/Source/panels/charpanel.cpp @@ -252,14 +252,15 @@ void DrawShadowString(const Surface &out, const PanelEntry &entry) void DrawStatButtons(const Surface &out) { if (MyPlayer->_pStatPts > 0) { + CelSprite sprite { *pChrButtons }; if (MyPlayer->_pBaseStr < MyPlayer->GetMaximumAttributeValue(CharacterAttribute::Strength)) - CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 157 }), *pChrButtons, chrbtn[static_cast(CharacterAttribute::Strength)] ? 2 : 1); + CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 157 }), sprite, chrbtn[static_cast(CharacterAttribute::Strength)] ? 2 : 1); if (MyPlayer->_pBaseMag < MyPlayer->GetMaximumAttributeValue(CharacterAttribute::Magic)) - CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 185 }), *pChrButtons, chrbtn[static_cast(CharacterAttribute::Magic)] ? 4 : 3); + CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 185 }), sprite, chrbtn[static_cast(CharacterAttribute::Magic)] ? 4 : 3); if (MyPlayer->_pBaseDex < MyPlayer->GetMaximumAttributeValue(CharacterAttribute::Dexterity)) - CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 214 }), *pChrButtons, chrbtn[static_cast(CharacterAttribute::Dexterity)] ? 6 : 5); + CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 214 }), sprite, chrbtn[static_cast(CharacterAttribute::Dexterity)] ? 6 : 5); if (MyPlayer->_pBaseVit < MyPlayer->GetMaximumAttributeValue(CharacterAttribute::Vitality)) - CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 242 }), *pChrButtons, chrbtn[static_cast(CharacterAttribute::Vitality)] ? 8 : 7); + CelDrawTo(out, GetPanelPosition(UiPanels::Character, { 137, 242 }), sprite, chrbtn[static_cast(CharacterAttribute::Vitality)] ? 8 : 7); } } diff --git a/Source/panels/spell_book.cpp b/Source/panels/spell_book.cpp index 41edda860..706db9b89 100644 --- a/Source/panels/spell_book.cpp +++ b/Source/panels/spell_book.cpp @@ -116,16 +116,16 @@ void FreeSpellBook() void DrawSpellBook(const Surface &out) { - CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { 0, 351 }), *pSpellBkCel, 0); + CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { 0, 351 }), CelSprite { *pSpellBkCel }, 0); if (gbIsHellfire && sbooktab < 5) { - CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { 61 * sbooktab + 7, 348 }), *pSBkBtnCel, sbooktab); + CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { 61 * sbooktab + 7, 348 }), CelSprite { *pSBkBtnCel }, sbooktab); } else { // BUGFIX: rendering of page 3 and page 4 buttons are both off-by-one pixel (fixed). int sx = 76 * sbooktab + 7; if (sbooktab == 2 || sbooktab == 3) { sx++; } - CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { sx, 348 }), *pSBkBtnCel, sbooktab); + CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { sx, 348 }), CelSprite { *pSBkBtnCel }, sbooktab); } Player &player = *MyPlayer; uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells; diff --git a/Source/panels/spell_icons.cpp b/Source/panels/spell_icons.cpp index 9da446e08..785ee1e29 100644 --- a/Source/panels/spell_icons.cpp +++ b/Source/panels/spell_icons.cpp @@ -89,7 +89,7 @@ void DrawSpellCel(const Surface &out, Point position, int nCel) void DrawSpellCel(const Surface &out, Point position, const OwnedCelSprite &sprite, int nCel) { - CelDrawLightTo(out, position, sprite, nCel, SplTransTbl); + CelDrawLightTo(out, position, CelSprite { sprite }, nCel, SplTransTbl); } void SetSpellTrans(spell_type t) diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index 1ecd62f84..1c8faa6e5 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -366,7 +366,7 @@ void DrawStash(const Surface &out) int frame = item._iCurs + CURSOR_FIRSTITEM; const Point position = GetStashSlotCoord(item.position) + offset; - const auto &cel = GetInvItemSprite(frame); + const CelSprite cel { GetInvItemSprite(frame) }; const int celFrame = GetInvItemFrame(frame); if (pcursstashitem == itemId) { @@ -617,7 +617,7 @@ void DrawGoldWithdraw(const Surface &out, int amount) const int dialogX = 30; - CelDrawTo(out, GetPanelPosition(UiPanels::Stash, { dialogX, 178 }), *pGBoxBuff, 0); + CelDrawTo(out, GetPanelPosition(UiPanels::Stash, { dialogX, 178 }), CelSprite { *pGBoxBuff }, 0); // Pre-wrap the string at spaces, otherwise DrawString would hard wrap in the middle of words const std::string wrapped = WordWrapString(_("How many gold pieces do you want to withdraw?"), 200); diff --git a/Source/quests.cpp b/Source/quests.cpp index e8cf7f5b3..c73730cc3 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -215,11 +215,11 @@ void PrintQLString(const Surface &out, int x, int y, string_view str, bool marke int width = GetLineWidth(str); x += std::max((257 - width) / 2, 0); if (marked) { - CelDrawTo(out, GetPanelPosition(UiPanels::Quest, { x - 20, y + 13 }), *pSPentSpn2Cels, PentSpn2Spin()); + CelDrawTo(out, GetPanelPosition(UiPanels::Quest, { x - 20, y + 13 }), CelSprite { *pSPentSpn2Cels }, PentSpn2Spin()); } DrawString(out, str, { GetPanelPosition(UiPanels::Quest, { x, y }), { 257, 0 } }, disabled ? UiFlags::ColorWhitegold : UiFlags::ColorWhite); if (marked) { - CelDrawTo(out, GetPanelPosition(UiPanels::Quest, { x + width + 7, y + 13 }), *pSPentSpn2Cels, PentSpn2Spin()); + CelDrawTo(out, GetPanelPosition(UiPanels::Quest, { x + width + 7, y + 13 }), CelSprite { *pSPentSpn2Cels }, PentSpn2Spin()); } } @@ -678,7 +678,7 @@ void DrawQuestLog(const Surface &out) SelectedQuest = l; } const auto x = InnerPanel.position.x; - CelDrawTo(out, GetPanelPosition(UiPanels::Quest, { 0, 351 }), *pQLogCel, 0); + CelDrawTo(out, GetPanelPosition(UiPanels::Quest, { 0, 351 }), CelSprite { *pQLogCel }, 0); int y = InnerPanel.position.y + ListYOffset; for (int i = 0; i < EncounteredQuestCount; i++) { if (i == FirstFinishedQuest) { diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 3ce1c6acc..c12119a94 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -843,7 +843,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit #ifdef _DEBUG if (DebugVision && IsTileLit(tilePosition)) { - CelClippedDrawTo(out, targetBufferPosition, *pSquareCel, 1); + CelClippedDrawTo(out, targetBufferPosition, CelSprite { *pSquareCel }, 1); } #endif @@ -896,7 +896,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit cel_transparency_active = false; // Turn transparency off here for debugging } #endif - CelClippedBlitLightTransTo(out, targetBufferPosition, *pSpecialCels, bArch - 1); + CelClippedBlitLightTransTo(out, targetBufferPosition, CelSprite { *pSpecialCels }, bArch - 1); #ifdef _DEBUG if (GetAsyncKeyState(DVL_VK_MENU)) { cel_transparency_active = TransList[bMap]; // Turn transparency back to its normal state @@ -910,7 +910,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit if (tilePosition.x > 0 && tilePosition.y > 0 && targetBufferPosition.y > TILE_HEIGHT) { char bArch = dSpecial[tilePosition.x - 1][tilePosition.y - 1]; if (bArch != 0) { - CelDrawTo(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, *pSpecialCels, bArch - 1); + CelDrawTo(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, CelSprite { *pSpecialCels }, bArch - 1); } } } diff --git a/Source/stores.cpp b/Source/stores.cpp index e93f2efff..73dd80cd2 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -164,7 +164,7 @@ void CalculateLineHeights() void DrawSTextBack(const Surface &out) { const Point uiPosition = GetUIRectangle().position; - CelDrawTo(out, { uiPosition.x + 320 + 24, 327 + uiPosition.y }, *pSTextBoxCels, 0); + CelDrawTo(out, { uiPosition.x + 320 + 24, 327 + uiPosition.y }, CelSprite { *pSTextBoxCels }, 0); DrawHalfTransparentRectTo(out, uiPosition.x + 347, uiPosition.y + 28, 265, 297); } @@ -173,18 +173,19 @@ void DrawSSlider(const Surface &out, int y1, int y2) const Point uiPosition = GetUIRectangle().position; int yd1 = y1 * 12 + 44 + uiPosition.y; int yd2 = y2 * 12 + 44 + uiPosition.y; + CelSprite sprite { *pSTextSlidCels }; if (stextscrlubtn != -1) - CelDrawTo(out, { uiPosition.x + 601, yd1 }, *pSTextSlidCels, 11); + CelDrawTo(out, { uiPosition.x + 601, yd1 }, sprite, 11); else - CelDrawTo(out, { uiPosition.x + 601, yd1 }, *pSTextSlidCels, 9); + CelDrawTo(out, { uiPosition.x + 601, yd1 }, sprite, 9); if (stextscrldbtn != -1) - CelDrawTo(out, { uiPosition.x + 601, yd2 }, *pSTextSlidCels, 10); + CelDrawTo(out, { uiPosition.x + 601, yd2 }, sprite, 10); else - CelDrawTo(out, { uiPosition.x + 601, yd2 }, *pSTextSlidCels, 8); + CelDrawTo(out, { uiPosition.x + 601, yd2 }, sprite, 8); yd1 += 12; int yd3 = yd1; for (; yd3 < yd2; yd3 += 12) { - CelDrawTo(out, { uiPosition.x + 601, yd3 }, *pSTextSlidCels, 13); + CelDrawTo(out, { uiPosition.x + 601, yd3 }, sprite, 13); } if (stextsel == BackButtonLine()) yd3 = stextlhold; @@ -194,7 +195,7 @@ void DrawSSlider(const Surface &out, int y1, int y2) yd3 = 1000 * (stextsval + ((yd3 - stextup) / 4)) / (storenumh - 1) * (y2 * 12 - y1 * 12 - 24) / 1000; else yd3 = 0; - CelDrawTo(out, { uiPosition.x + 601, (y1 + 1) * 12 + 44 + uiPosition.y + yd3 }, *pSTextSlidCels, 12); + CelDrawTo(out, { uiPosition.x + 601, (y1 + 1) * 12 + 44 + uiPosition.y + yd3 }, sprite, 12); } void AddSLine(int y) @@ -2140,13 +2141,13 @@ void DrawSelector(const Surface &out, const Rectangle &rect, const char *text, U if (HasAnyOf(flags, UiFlags::AlignCenter)) x1 += (rect.size.width - lineWidth) / 2; - CelDrawTo(out, { x1, rect.position.y + 13 }, *pSPentSpn2Cels, PentSpn2Spin()); + CelDrawTo(out, { x1, rect.position.y + 13 }, CelSprite { *pSPentSpn2Cels }, PentSpn2Spin()); int x2 = rect.position.x + rect.size.width + 5; if (HasAnyOf(flags, UiFlags::AlignCenter)) x2 = rect.position.x + (rect.size.width - lineWidth) / 2 + lineWidth + 5; - CelDrawTo(out, { x2, rect.position.y + 13 }, *pSPentSpn2Cels, PentSpn2Spin()); + CelDrawTo(out, { x2, rect.position.y + 13 }, CelSprite { *pSPentSpn2Cels }, PentSpn2Spin()); } } // namespace