Add outline to stream overlay text (#1887)

Co-authored-by: Cameron Gutman <aicommander@gmail.com>
This commit is contained in:
Mira
2026-07-02 06:03:45 +02:00
committed by GitHub
parent c9b03f80f8
commit 177f845183
2 changed files with 36 additions and 4 deletions
+35 -4
View File
@@ -149,10 +149,12 @@ void OverlayManager::notifyOverlayUpdated(OverlayType type)
(void**)&m_Overlays[type].surface,
m_Overlays[type].enabled ?
// The _Wrapped variant is required for line breaks to work
TTF_RenderText_Blended_Wrapped(m_Overlays[type].font,
m_Overlays[type].text,
m_Overlays[type].color,
1024)
RenderTextOutlinedWrapped(m_Overlays[type].font,
m_Overlays[type].text,
m_Overlays[type].color,
{0, 0, 0, 255},
4,
1024)
: nullptr);
// Notify the renderer
@@ -163,3 +165,32 @@ void OverlayManager::notifyOverlayUpdated(OverlayType type)
SDL_FreeSurface(oldSurface);
}
}
SDL_Surface* OverlayManager::RenderTextOutlinedWrapped(TTF_Font* font, const char* text, SDL_Color textColor, SDL_Color outlineColor, int outlineWidth, int wrapWidth) {
if (text == nullptr || text[0] == '\0') {
return nullptr;
}
// Draw text twice, but outline is a bit bigger
int oldOutline = TTF_GetFontOutline(font);
TTF_SetFontOutline(font, outlineWidth);
auto outlineSurface = TTF_RenderText_Blended_Wrapped(font, text, outlineColor, wrapWidth);
TTF_SetFontOutline(font, 0);
auto textSurface = TTF_RenderText_Blended_Wrapped(font, text, textColor, wrapWidth);
TTF_SetFontOutline(font, oldOutline);
if (outlineSurface == nullptr || textSurface == nullptr) {
SDL_FreeSurface(outlineSurface);
SDL_FreeSurface(textSurface);
return nullptr;
}
// Merge the texts
SDL_Rect dst = { outlineWidth, outlineWidth, textSurface->w, textSurface->h };
SDL_BlitSurface(textSurface, nullptr, outlineSurface, &dst);
SDL_FreeSurface(textSurface);
return outlineSurface;
}
+1
View File
@@ -41,6 +41,7 @@ public:
private:
void notifyOverlayUpdated(OverlayType type);
SDL_Surface* RenderTextOutlinedWrapped(TTF_Font* font, const char* text, SDL_Color textColor, SDL_Color outlineColor, int outlineWidth, int wrapWidth);
struct {
bool enabled;