From 58de891f57299a2fd919e20f7e5499c7f32fba92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 24 Aug 2022 10:20:33 +0200 Subject: [PATCH] OSD: Scale large multiline messages to fit better on screen (like shader logging) --- UI/OnScreenDisplay.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 1b4700e9f6..acc0347fd1 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -28,18 +28,33 @@ void OnScreenMessagesView::Draw(UIContext &dc) { float alpha = (iter->endTime - now) * 4.0f; if (alpha > 1.0) alpha = 1.0f; if (alpha < 0.0) alpha = 0.0f; + dc.SetFontScale(1.0f, 1.0f); // Messages that are wider than the screen are left-aligned instead of centered. + + int align = 0; + // Simple heuristic: Draw messages that contain line breaks with ASCII_FONT (likely debug output) + if (iter->text.find('\n') != 0) { + align |= FLAG_DYNAMIC_ASCII; + } + float tw, th; - dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, iter->text.c_str(), &tw, &th); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, iter->text.c_str(), &tw, &th, align); float x = bounds_.centerX(); - int align = ALIGN_TOP | ALIGN_HCENTER; if (tw > bounds_.w) { - align = ALIGN_TOP | ALIGN_LEFT; + align |= ALIGN_TOP | ALIGN_LEFT; x = 2; + } else { + align |= ALIGN_TOP | ALIGN_HCENTER; + } + float scale = 1.0f; + if (th > bounds_.h - y) { + // Scale down! + scale = std::max(0.15f, (bounds_.h - y) / th); + dc.SetFontScale(scale, scale); } dc.SetFontStyle(dc.theme->uiFont); dc.DrawTextShadow(iter->text.c_str(), x, y, colorAlpha(iter->color, alpha), align); - y += h; + y += th * scale; } osm.Unlock();