From 177f84518358ba7641077514df97296ebb3dc2d8 Mon Sep 17 00:00:00 2001 From: Mira <27288418+mira-x@users.noreply.github.com> Date: Thu, 2 Jul 2026 06:03:45 +0200 Subject: [PATCH] Add outline to stream overlay text (#1887) Co-authored-by: Cameron Gutman --- app/streaming/video/overlaymanager.cpp | 39 +++++++++++++++++++++++--- app/streaming/video/overlaymanager.h | 1 + 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/streaming/video/overlaymanager.cpp b/app/streaming/video/overlaymanager.cpp index 80cc963c..542c2984 100644 --- a/app/streaming/video/overlaymanager.cpp +++ b/app/streaming/video/overlaymanager.cpp @@ -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; +} + + diff --git a/app/streaming/video/overlaymanager.h b/app/streaming/video/overlaymanager.h index a1675541..8f8a60b3 100644 --- a/app/streaming/video/overlaymanager.h +++ b/app/streaming/video/overlaymanager.h @@ -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;