Browse Source

Use outline for spell icon texts

pull/5656/head
Anders Jenbo 3 years ago
parent
commit
e50e21e0e4
  1. 3
      Source/DiabloUI/ui_flags.hpp
  2. 23
      Source/engine/render/text_render.cpp
  3. 10
      Source/panels/spell_list.cpp

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

23
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<uint8_t, 256> *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<std::size_t> 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);
}
}

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

Loading…
Cancel
Save