mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-07-12 18:03:52 +00:00
Add outline to stream overlay text (#1887)
Co-authored-by: Cameron Gutman <aicommander@gmail.com>
This commit is contained in:
@@ -149,10 +149,12 @@ void OverlayManager::notifyOverlayUpdated(OverlayType type)
|
|||||||
(void**)&m_Overlays[type].surface,
|
(void**)&m_Overlays[type].surface,
|
||||||
m_Overlays[type].enabled ?
|
m_Overlays[type].enabled ?
|
||||||
// The _Wrapped variant is required for line breaks to work
|
// The _Wrapped variant is required for line breaks to work
|
||||||
TTF_RenderText_Blended_Wrapped(m_Overlays[type].font,
|
RenderTextOutlinedWrapped(m_Overlays[type].font,
|
||||||
m_Overlays[type].text,
|
m_Overlays[type].text,
|
||||||
m_Overlays[type].color,
|
m_Overlays[type].color,
|
||||||
1024)
|
{0, 0, 0, 255},
|
||||||
|
4,
|
||||||
|
1024)
|
||||||
: nullptr);
|
: nullptr);
|
||||||
|
|
||||||
// Notify the renderer
|
// Notify the renderer
|
||||||
@@ -163,3 +165,32 @@ void OverlayManager::notifyOverlayUpdated(OverlayType type)
|
|||||||
SDL_FreeSurface(oldSurface);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void notifyOverlayUpdated(OverlayType type);
|
void notifyOverlayUpdated(OverlayType type);
|
||||||
|
SDL_Surface* RenderTextOutlinedWrapped(TTF_Font* font, const char* text, SDL_Color textColor, SDL_Color outlineColor, int outlineWidth, int wrapWidth);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|||||||
Reference in New Issue
Block a user