Make in-stream control panel persistent and readable

This commit is contained in:
Joey Yakimowich-Payne 2026-02-12 01:15:03 -07:00
commit 8a7be971a4
3 changed files with 138 additions and 50 deletions

View file

@ -12,8 +12,8 @@ OverlayManager::OverlayManager() :
m_Overlays[OverlayType::OverlayDebug].color = {0xD0, 0xD0, 0x00, 0xFF};
m_Overlays[OverlayType::OverlayDebug].fontSize = 20;
m_Overlays[OverlayType::OverlayStatusUpdate].color = {0xCC, 0x00, 0x00, 0xFF};
m_Overlays[OverlayType::OverlayStatusUpdate].fontSize = 36;
m_Overlays[OverlayType::OverlayStatusUpdate].color = {0xF0, 0xF0, 0xF0, 0xFF};
m_Overlays[OverlayType::OverlayStatusUpdate].fontSize = 24;
// While TTF will usually not be initialized here, it is valid for that not to
// be the case, since Session destruction is deferred and could overlap with
@ -146,16 +146,45 @@ void OverlayManager::notifyOverlayUpdated(OverlayType type)
}
}
SDL_Surface* newSurface = nullptr;
if (m_Overlays[type].enabled) {
// The _Wrapped variant is required for line breaks to work
SDL_Surface* textSurface = TTF_RenderText_Blended_Wrapped(m_Overlays[type].font,
m_Overlays[type].text,
m_Overlays[type].color,
1024);
if (textSurface != nullptr && type == OverlayStatusUpdate) {
constexpr int kHorizontalPadding = 18;
constexpr int kVerticalPadding = 12;
SDL_Surface* panelSurface = SDL_CreateRGBSurfaceWithFormat(0,
textSurface->w + (kHorizontalPadding * 2),
textSurface->h + (kVerticalPadding * 2),
32,
SDL_PIXELFORMAT_ARGB8888);
if (panelSurface != nullptr) {
SDL_FillRect(panelSurface,
nullptr,
SDL_MapRGBA(panelSurface->format, 0x00, 0x00, 0x00, 0xA0));
SDL_Rect destination = {kHorizontalPadding, kVerticalPadding, textSurface->w, textSurface->h};
SDL_SetSurfaceBlendMode(textSurface, SDL_BLENDMODE_BLEND);
SDL_BlitSurface(textSurface, nullptr, panelSurface, &destination);
SDL_FreeSurface(textSurface);
newSurface = panelSurface;
}
else {
newSurface = textSurface;
}
}
else {
newSurface = textSurface;
}
}
// Exchange the old surface with the new one
SDL_Surface* oldSurface = (SDL_Surface*)SDL_AtomicSetPtr(
(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)
: nullptr);
SDL_Surface* oldSurface = (SDL_Surface*)SDL_AtomicSetPtr((void**)&m_Overlays[type].surface,
newSurface);
// Notify the renderer
m_Renderer->notifyOverlayUpdated(type);