From e50e21e0e42fcfaa441ab0c6900e2b259cf30e6f Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 12 Jan 2023 09:50:31 +0100 Subject: [PATCH] Use outline for spell icon texts --- Source/DiabloUI/ui_flags.hpp | 3 ++- Source/engine/render/text_render.cpp | 23 +++++++++++++++-------- Source/panels/spell_list.cpp | 10 ++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Source/DiabloUI/ui_flags.hpp b/Source/DiabloUI/ui_flags.hpp index 1d4530ec9..1ee0da80d 100644 --- a/Source/DiabloUI/ui_flags.hpp +++ b/Source/DiabloUI/ui_flags.hpp @@ -43,9 +43,10 @@ enum class UiFlags : uint32_t { PentaCursor = 1 << 26, TextCursor = 1 << 27, + Outlined = 1 << 28, /** @brief Ensures that the if current element is active that the next element is also visible. */ - NeedsNextElement = 1 << 28, + NeedsNextElement = 1 << 29, // clang-format on }; use_enum_as_flags(UiFlags); diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index 57a1c79c1..2fbe69bbf 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -213,9 +213,12 @@ const OwnedClxSpriteList *LoadFont(GameFontTables size, text_color color, uint16 return &(*font); } -void DrawFont(const Surface &out, Point position, const OwnedClxSpriteList *font, text_color color, int frame) +void DrawFont(const Surface &out, Point position, const OwnedClxSpriteList *font, text_color color, int frame, bool outline) { ClxSprite glyph = (*font)[frame]; + if (outline) { + ClxDrawOutlineSkipColorZero(out, 0, { position.x, position.y + glyph.height() - 1 }, glyph); + } if (ColorTranslationsData[color]) { RenderClxSpriteWithTRN(out, glyph, position, ColorTranslationsData[color]->data()); } else { @@ -383,7 +386,7 @@ int GetLineStartX(UiFlags flags, const Rectangle &rect, int lineWidth) uint32_t DoDrawString(const Surface &out, string_view text, Rectangle rect, Point &characterPosition, int spacing, int lineHeight, int lineWidth, int rightMargin, int bottomMargin, - UiFlags flags, GameFontTables size, text_color color) + UiFlags flags, GameFontTables size, text_color color, bool outline) { Font *font = nullptr; std::array *kerning = nullptr; @@ -423,7 +426,7 @@ uint32_t DoDrawString(const Surface &out, string_view text, Rectangle rect, Poin continue; } - DrawFont(out, characterPosition, font, color, frame); + DrawFont(out, characterPosition, font, color, frame, outline); characterPosition.x += (*kerning)[frame] + spacing; } return remaining.data() - text.data(); @@ -661,9 +664,11 @@ uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect, characterPosition.y += BaseLineOffset[size]; + const bool outlined = HasAnyOf(flags, UiFlags::Outlined); + const Surface clippedOut = ClipSurface(out, rect); - const uint32_t bytesDrawn = DoDrawString(clippedOut, text, rect, characterPosition, spacing, lineHeight, lineWidth, rightMargin, bottomMargin, flags, size, color); + const uint32_t bytesDrawn = DoDrawString(clippedOut, text, rect, characterPosition, spacing, lineHeight, lineWidth, rightMargin, bottomMargin, flags, size, color, outlined); if (HasAnyOf(flags, UiFlags::PentaCursor)) { const ClxSprite sprite = (*pSPentSpn2Cels)[PentSpn2Spin()]; @@ -671,7 +676,7 @@ uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect, ClxDraw(clippedOut, characterPosition + Displacement { 0, lineHeight - BaseLineOffset[size] }, sprite); } else if (HasAnyOf(flags, UiFlags::TextCursor) && GetAnimationFrame(2, 500) != 0) { MaybeWrap(characterPosition, 2, rightMargin, initialX, lineHeight); - DrawFont(clippedOut, characterPosition, LoadFont(size, color, 0), color, '|'); + DrawFont(clippedOut, characterPosition, LoadFont(size, color, 0), color, '|', outlined); } return bytesDrawn; @@ -707,6 +712,8 @@ void DrawStringWithColors(const Surface &out, string_view fmt, DrawStringFormatA characterPosition.y += BaseLineOffset[size]; + const bool outlined = HasAnyOf(flags, UiFlags::Outlined); + const Surface clippedOut = ClipSurface(out, rect); Font *font = nullptr; @@ -728,7 +735,7 @@ void DrawStringWithColors(const Surface &out, string_view fmt, DrawStringFormatA const std::optional fmtArgPos = fmtArgParser(remaining); if (fmtArgPos) { DoDrawString(clippedOut, args[*fmtArgPos].GetFormatted(), rect, characterPosition, spacing, lineHeight, lineWidth, rightMargin, bottomMargin, flags, size, - GetColorFromFlags(args[*fmtArgPos].GetFlags())); + GetColorFromFlags(args[*fmtArgPos].GetFlags()), outlined); // `fmtArgParser` has already consumed `remaining`. Ensure the loop doesn't consume any more. cpLen = 0; // The loop assigns `prev = next`. We want `prev` to be `\0` after this. @@ -762,7 +769,7 @@ void DrawStringWithColors(const Surface &out, string_view fmt, DrawStringFormatA continue; } - DrawFont(clippedOut, characterPosition, font, color, frame); + DrawFont(clippedOut, characterPosition, font, color, frame, outlined); characterPosition.x += (*kerning)[frame] + spacing; } @@ -772,7 +779,7 @@ void DrawStringWithColors(const Surface &out, string_view fmt, DrawStringFormatA ClxDraw(clippedOut, characterPosition + Displacement { 0, lineHeight - BaseLineOffset[size] }, sprite); } else if (HasAnyOf(flags, UiFlags::TextCursor) && GetAnimationFrame(2, 500) != 0) { MaybeWrap(characterPosition, 2, rightMargin, initialX, lineHeight); - DrawFont(clippedOut, characterPosition, LoadFont(size, color, 0), color, '|'); + DrawFont(clippedOut, characterPosition, LoadFont(size, color, 0), color, '|', outlined); } } diff --git a/Source/panels/spell_list.cpp b/Source/panels/spell_list.cpp index 6807ac1c6..d748058f4 100644 --- a/Source/panels/spell_list.cpp +++ b/Source/panels/spell_list.cpp @@ -30,12 +30,8 @@ void PrintSBookSpellType(const Surface &out, Point position, string_view text, u // Align the spell type text with bottom of spell icon position += Displacement { SPLICONLENGTH / 2 - GetLineWidth(text) / 2, (IsSmallFontTall() ? -19 : -15) }; - // Draw a drop shadow below and to the left of the text - DrawString(out, text, position + Displacement { -1, 1 }, UiFlags::ColorBlack); - DrawString(out, text, position + Displacement { -1, -1 }, UiFlags::ColorBlack); - DrawString(out, text, position + Displacement { 1, -1 }, UiFlags::ColorBlack); // Then draw the text over the top - DrawString(out, text, position, UiFlags::ColorWhite); + DrawString(out, text, position, UiFlags::ColorWhite | UiFlags::Outlined); } void PrintSBookHotkey(const Surface &out, Point position, const string_view text) @@ -43,10 +39,8 @@ void PrintSBookHotkey(const Surface &out, Point position, const string_view text // Align the hot key text with the top-right corner of the spell icon position += Displacement { SPLICONLENGTH - (GetLineWidth(text.data()) + 5), 5 - SPLICONLENGTH }; - // Draw a drop shadow below and to the left of the text - DrawString(out, text, position + Displacement { -1, 1 }, UiFlags::ColorBlack); // Then draw the text over the top - DrawString(out, text, position, UiFlags::ColorWhite); + DrawString(out, text, position, UiFlags::ColorWhite | UiFlags::Outlined); } bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType)