diff --git a/Source/DiabloUI/art_draw.cpp b/Source/DiabloUI/art_draw.cpp index e60905af5..7559792e8 100644 --- a/Source/DiabloUI/art_draw.cpp +++ b/Source/DiabloUI/art_draw.cpp @@ -6,9 +6,9 @@ namespace devilution { -void DrawArt(Sint16 screenX, Sint16 screenY, Art *art, int nFrame, Uint16 srcW, Uint16 srcH) +void DrawArt(Point screenPosition, Art *art, int nFrame, Uint16 srcW, Uint16 srcH) { - if (screenY >= gnScreenHeight || screenX >= gnScreenWidth || art->surface == nullptr) + if (screenPosition.y >= gnScreenHeight || screenPosition.x >= gnScreenWidth || art->surface == nullptr) return; SDL_Rect srcRect; @@ -23,7 +23,7 @@ void DrawArt(Sint16 screenX, Sint16 screenY, Art *art, int nFrame, Uint16 srcW, srcRect.w = srcW; if (srcH != 0 && srcH < srcRect.h) srcRect.h = srcH; - SDL_Rect dstRect = { screenX, screenY, srcRect.w, srcRect.h }; + SDL_Rect dstRect = MakeSdlRect(screenPosition.x, screenPosition.y, srcRect.w, srcRect.h); ScaleOutputRect(&dstRect); if (art->surface->format->BitsPerPixel == 8 && art->palette_version != pal_surface_palette_version) { @@ -36,9 +36,9 @@ void DrawArt(Sint16 screenX, Sint16 screenY, Art *art, int nFrame, Uint16 srcW, ErrSdl(); } -void DrawArt(const Surface &out, Sint16 screenX, Sint16 screenY, Art *art, int nFrame, Uint16 srcW, Uint16 srcH) +void DrawArt(const Surface &out, Point screenPosition, Art *art, int nFrame, Uint16 srcW, Uint16 srcH) { - if (screenY >= gnScreenHeight || screenX >= gnScreenWidth || art->surface == nullptr) + if (screenPosition.y >= gnScreenHeight || screenPosition.x >= gnScreenWidth || art->surface == nullptr) return; SDL_Rect srcRect; @@ -51,11 +51,7 @@ void DrawArt(const Surface &out, Sint16 screenX, Sint16 screenY, Art *art, int n srcRect.w = srcW; if (srcH != 0 && srcH < srcRect.h) srcRect.h = srcH; - SDL_Rect dstRect; - dstRect.x = screenX; - dstRect.y = screenY; - dstRect.w = srcRect.w; - dstRect.h = srcRect.h; + SDL_Rect dstRect = MakeSdlRect(screenPosition.x, screenPosition.y, srcRect.w, srcRect.h); if (art->surface->format->BitsPerPixel == 8 && art->palette_version != pal_surface_palette_version) { if (SDLC_SetSurfaceColors(art->surface.get(), out.surface->format->palette) <= -1) @@ -67,9 +63,9 @@ void DrawArt(const Surface &out, Sint16 screenX, Sint16 screenY, Art *art, int n ErrSdl(); } -void DrawAnimatedArt(Art *art, int screenX, int screenY) +void DrawAnimatedArt(Art *art, Point screenPosition) { - DrawArt(screenX, screenY, art, GetAnimationFrame(art->frames)); + DrawArt(screenPosition, art, GetAnimationFrame(art->frames)); } int GetAnimationFrame(int frames, int fps) diff --git a/Source/DiabloUI/art_draw.h b/Source/DiabloUI/art_draw.h index f70bdb2a7..daadc84f5 100644 --- a/Source/DiabloUI/art_draw.h +++ b/Source/DiabloUI/art_draw.h @@ -5,11 +5,11 @@ namespace devilution { -void DrawArt(Sint16 screenX, Sint16 screenY, Art *art, int nFrame = 0, Uint16 srcW = 0, Uint16 srcH = 0); +void DrawArt(Point screenPosition, Art *art, int nFrame = 0, Uint16 srcW = 0, Uint16 srcH = 0); -void DrawArt(const Surface &out, Sint16 screenX, Sint16 screenY, Art *art, int nFrame = 0, Uint16 srcW = 0, Uint16 srcH = 0); +void DrawArt(const Surface &out, Point screenPosition, Art *art, int nFrame = 0, Uint16 srcW = 0, Uint16 srcH = 0); -void DrawAnimatedArt(Art *art, int screenX, int screenY); +void DrawAnimatedArt(Art *art, Point screenPosition); int GetAnimationFrame(int frames, int fps = 60); diff --git a/Source/DiabloUI/button.cpp b/Source/DiabloUI/button.cpp index 6bffa152d..3631b8b6c 100644 --- a/Source/DiabloUI/button.cpp +++ b/Source/DiabloUI/button.cpp @@ -21,7 +21,7 @@ void RenderButton(UiButton *button) } else { frame = UiButton::DEFAULT; } - DrawArt(button->m_rect.x, button->m_rect.y, button->m_art, frame, button->m_rect.w, button->m_rect.h); + DrawArt({ button->m_rect.x, button->m_rect.y }, button->m_art, frame, button->m_rect.w, button->m_rect.h); SDL_Rect textRect = button->m_rect; if (!button->m_pressed) diff --git a/Source/DiabloUI/credits.cpp b/Source/DiabloUI/credits.cpp index 392ada76d..442ef46ca 100644 --- a/Source/DiabloUI/credits.cpp +++ b/Source/DiabloUI/credits.cpp @@ -146,8 +146,8 @@ void CreditsRenderer::Render() prev_offset_y_ = offsetY; SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000); - DrawArt(PANEL_LEFT - 320, UI_OFFSET_Y, &ArtBackgroundWidescreen); - DrawArt(PANEL_LEFT, UI_OFFSET_Y, &ArtBackground); + DrawArt({ PANEL_LEFT - 320, UI_OFFSET_Y }, &ArtBackgroundWidescreen); + DrawArt({ PANEL_LEFT, UI_OFFSET_Y }, &ArtBackground); if (font == nullptr) return; diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index ff7acaa06..d2d91cd50 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -681,8 +681,8 @@ void DrawSelector(const SDL_Rect &rect) int frame = GetAnimationFrame(art->frames); int y = rect.y + (rect.h - art->h()) / 2; // TODO FOCUS_MED appares higher than the box - DrawArt(rect.x, y, art, frame); - DrawArt(rect.x + rect.w - art->w(), y, art, frame); + DrawArt({ rect.x, y }, art, frame); + DrawArt({ rect.x + rect.w - art->w(), y }, art, frame); } void UiClearScreen() @@ -739,9 +739,9 @@ void Render(const UiImage *uiImage) x += xOffset; } if (uiImage->m_animated) { - DrawAnimatedArt(uiImage->m_art, x, uiImage->m_rect.y); + DrawAnimatedArt(uiImage->m_art, { x, uiImage->m_rect.y }); } else { - DrawArt(x, uiImage->m_rect.y, uiImage->m_art, uiImage->m_frame, uiImage->m_rect.w); + DrawArt({ x, uiImage->m_rect.y }, uiImage->m_art, uiImage->m_frame, uiImage->m_rect.w); } } @@ -765,11 +765,11 @@ void Render(const UiScrollbar *uiSb) { // Bar background (tiled): { - const std::size_t bgYEnd = DownArrowRect(uiSb).y; - std::size_t bgY = uiSb->m_rect.y + uiSb->m_arrow->h(); + const int bgYEnd = DownArrowRect(uiSb).y; + int bgY = uiSb->m_rect.y + uiSb->m_arrow->h(); while (bgY < bgYEnd) { std::size_t drawH = std::min(bgY + uiSb->m_bg->h(), bgYEnd) - bgY; - DrawArt(uiSb->m_rect.x, bgY, uiSb->m_bg, 0, SCROLLBAR_BG_WIDTH, drawH); + DrawArt({ uiSb->m_rect.x, bgY }, uiSb->m_bg, 0, SCROLLBAR_BG_WIDTH, drawH); bgY += drawH; } } @@ -778,18 +778,18 @@ void Render(const UiScrollbar *uiSb) { const SDL_Rect rect = UpArrowRect(uiSb); const int frame = static_cast(scrollBarState.upArrowPressed ? ScrollBarArrowFrame_UP_ACTIVE : ScrollBarArrowFrame_UP); - DrawArt(rect.x, rect.y, uiSb->m_arrow, frame, rect.w); + DrawArt({ rect.x, rect.y }, uiSb->m_arrow, frame, rect.w); } { const SDL_Rect rect = DownArrowRect(uiSb); const int frame = static_cast(scrollBarState.downArrowPressed ? ScrollBarArrowFrame_DOWN_ACTIVE : ScrollBarArrowFrame_DOWN); - DrawArt(rect.x, rect.y, uiSb->m_arrow, frame, rect.w); + DrawArt({ rect.x, rect.y }, uiSb->m_arrow, frame, rect.w); } // Thumb: if (SelectedItemMax > 0) { const SDL_Rect rect = ThumbRect(uiSb, SelectedItem, SelectedItemMax + 1); - DrawArt(rect.x, rect.y, uiSb->m_thumb); + DrawArt({ rect.x, rect.y }, uiSb->m_thumb); } } @@ -1014,6 +1014,6 @@ void DrawMouse() if (IsHardwareCursor() || sgbControllerActive) return; - DrawArt(MousePosition.x, MousePosition.y, &ArtCursor); + DrawArt(MousePosition, &ArtCursor); } } // namespace devilution diff --git a/Source/DiabloUI/progress.cpp b/Source/DiabloUI/progress.cpp index 64b96ffe5..bfbca7e97 100644 --- a/Source/DiabloUI/progress.cpp +++ b/Source/DiabloUI/progress.cpp @@ -63,22 +63,21 @@ void ProgressFree() void ProgressRender(BYTE progress) { SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000); - DrawArt(0, 0, &ArtBackground); + DrawArt({ 0, 0 }, &ArtBackground); - Sint16 x = GetCenterOffset(280); - Sint16 y = GetCenterOffset(144, gnScreenHeight); + Point position = { GetCenterOffset(280), GetCenterOffset(144, gnScreenHeight) }; - DrawArt(x, y, &ArtPopupSm, 0, 280, 140); - DrawArt(GetCenterOffset(227), y + 52, &ArtProgBG, 0, 227); + DrawArt(position, &ArtPopupSm, 0, 280, 140); + DrawArt({ GetCenterOffset(227), position.y + 52 }, &ArtProgBG, 0, 227); if (progress != 0) { - DrawArt(GetCenterOffset(227), y + 52, &ProgFil, 0, 227 * progress / 100); + DrawArt({ GetCenterOffset(227), position.y + 52 }, &ProgFil, 0, 227 * progress / 100); } - DrawArt(GetCenterOffset(110), y + 99, &SmlButton, 2, 110); + DrawArt({ GetCenterOffset(110), position.y + 99 }, &SmlButton, 2, 110); if (msgSurface != nullptr) { SDL_Rect dscRect = { - static_cast(x + 50 + 1), - static_cast(y + 8 + 1), + static_cast(position.x + 50 + 1), + static_cast(position.y + 8 + 1), static_cast(msgSurface->w), static_cast(msgSurface->h) }; diff --git a/Source/DiabloUI/text_draw.cpp b/Source/DiabloUI/text_draw.cpp index 0ff3f09cf..4d24a04a9 100644 --- a/Source/DiabloUI/text_draw.cpp +++ b/Source/DiabloUI/text_draw.cpp @@ -90,11 +90,11 @@ void DrawArtStr(const char *text, const SDL_Rect &rect, UiFlags flags, bool draw } uint8_t w = FontTables[size][static_cast(text[i]) + 2]; w = (w != 0) ? w : FontTables[size][0]; - DrawArt(sx, sy, &ArtFonts[size][color], static_cast(text[i]), w); + DrawArt({ sx, sy }, &ArtFonts[size][color], static_cast(text[i]), w); sx += w; } if (drawTextCursor && GetAnimationFrame(2, 500) != 0) { - DrawArt(sx, sy, &ArtFonts[size][color], '|'); + DrawArt({ sx, sy }, &ArtFonts[size][color], '|'); } } diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 0d665d9ac..a900a78cf 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -171,7 +171,7 @@ void DrawCutscene() { lock_buf(1); const Surface &out = GlobalBackBuffer(); - DrawArt(out, PANEL_X - (ArtCutsceneWidescreen.w() - PANEL_WIDTH) / 2, UI_OFFSET_Y, &ArtCutsceneWidescreen); + DrawArt(out, { PANEL_X - (ArtCutsceneWidescreen.w() - PANEL_WIDTH) / 2, UI_OFFSET_Y }, &ArtCutsceneWidescreen); CelDrawTo(out, { PANEL_X, 480 - 1 + UI_OFFSET_Y }, *sgpBackCel, 1); constexpr int ProgressHeight = 22; diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index 7521244a5..5d49ef78e 100644 --- a/Source/qol/monhealthbar.cpp +++ b/Source/qol/monhealthbar.cpp @@ -63,46 +63,45 @@ void DrawMonsterHealthBar(const Surface &out) const int width = healthBox.w(); const int height = healthBox.h(); - int xPos = (gnScreenWidth - width) / 2; + Point position = { (gnScreenWidth - width) / 2, 18 }; if (CanPanelsCoverView()) { if (invflag || sbookflag) - xPos -= SPANEL_WIDTH / 2; + position.x -= SPANEL_WIDTH / 2; if (chrflag || QuestLogIsOpen) - xPos += SPANEL_WIDTH / 2; + position.x += SPANEL_WIDTH / 2; } - const int yPos = 18; const int border = 3; const int maxLife = std::max(monster._mmaxhp, monster._mhitpoints); - DrawArt(out, xPos, yPos, &healthBox); - DrawHalfTransparentRectTo(out, xPos + border, yPos + border, width - (border * 2), height - (border * 2)); + DrawArt(out, position, &healthBox); + DrawHalfTransparentRectTo(out, position.x + border, position.y + border, width - (border * 2), height - (border * 2)); int barProgress = (width * monster._mhitpoints) / maxLife; if (barProgress != 0) { - DrawArt(out, xPos + border + 1, yPos + border + 1, &health, 0, barProgress, height - (border * 2) - 2); + DrawArt(out, position + Displacement { border + 1, border + 1 }, &health, 0, barProgress, height - (border * 2) - 2); } if (sgOptions.Gameplay.bShowMonsterType) { Uint8 borderColors[] = { 248 /*undead*/, 232 /*demon*/, 150 /*beast*/ }; Uint8 borderColor = borderColors[monster.MData->mMonstClass]; int borderWidth = width - (border * 2); - UnsafeDrawHorizontalLine(out, { xPos + border, yPos + border }, borderWidth, borderColor); - UnsafeDrawHorizontalLine(out, { xPos + border, yPos + height - border - 1 }, borderWidth, borderColor); + UnsafeDrawHorizontalLine(out, { position.x + border, position.y + border }, borderWidth, borderColor); + UnsafeDrawHorizontalLine(out, { position.x + border, position.y + height - border - 1 }, borderWidth, borderColor); int borderHeight = height - (border * 2) - 2; - UnsafeDrawVerticalLine(out, { xPos + border, yPos + border + 1 }, borderHeight, borderColor); - UnsafeDrawVerticalLine(out, { xPos + width - border - 1, yPos + border + 1 }, borderHeight, borderColor); + UnsafeDrawVerticalLine(out, { position.x + border, position.y + border + 1 }, borderHeight, borderColor); + UnsafeDrawVerticalLine(out, { position.x + width - border - 1, position.y + border + 1 }, borderHeight, borderColor); } - int barLabelY = yPos + 10 + (height - 11) / 2; - DrawString(out, monster.mName, { { xPos - 1, barLabelY + 1 }, { width, height } }, UiFlags::AlignCenter | UiFlags::ColorBlack); + int barLabelY = position.y + 10 + (height - 11) / 2; + DrawString(out, monster.mName, { position.x - 1, barLabelY + 1, width, height }, UiFlags::AlignCenter | UiFlags::ColorBlack); UiFlags style = UiFlags::ColorSilver; if (monster._uniqtype != 0) style = UiFlags::ColorGold; else if (monster.leader != 0) style = UiFlags::ColorBlue; - DrawString(out, monster.mName, { { xPos, barLabelY }, { width, height } }, UiFlags::AlignCenter | style); + DrawString(out, monster.mName, { position.x, barLabelY, width, height }, UiFlags::AlignCenter | style); if (monster._uniqtype != 0 || MonsterKillCounts[monster.MType->mtype] >= 15) { monster_resistance immunes[] = { IMMUNE_MAGIC, IMMUNE_FIRE, IMMUNE_LIGHTNING }; @@ -111,10 +110,10 @@ void DrawMonsterHealthBar(const Surface &out) int resOffset = 5; for (int i = 0; i < 3; i++) { if ((monster.mMagicRes & immunes[i]) != 0) { - DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2 + 1); + DrawArt(out, position + Displacement { resOffset, height - 6 }, &resistance, i * 2 + 1); resOffset += resistance.w() + 2; } else if ((monster.mMagicRes & resists[i]) != 0) { - DrawArt(out, xPos + resOffset, yPos + height - 6, &resistance, i * 2); + DrawArt(out, position + Displacement { resOffset, height - 6 }, &resistance, i * 2); resOffset += resistance.w() + 2; } } diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index 7657a4c74..31f81c4fb 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -72,13 +72,12 @@ void DrawXPBar(const Surface &out) const auto &player = Players[MyPlayerId]; - const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155; - const int backY = PANEL_TOP + PANEL_HEIGHT - 11; + const Point back = { PANEL_LEFT + PANEL_WIDTH / 2 - 155, PANEL_TOP + PANEL_HEIGHT - 11 }; - const int xPos = backX + 3; - const int yPos = backY + 2; + const int xPos = back.x + 3; + const int yPos = back.y + 2; - DrawArt(out, backX, backY, &xpbarArt); + DrawArt(out, back, &xpbarArt); const int8_t charLevel = player._pLevel;