From 7b50443c66b0d5fdb52d045f9d94b70552d3e61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 1 Jun 2024 13:15:14 +0200 Subject: [PATCH 1/2] Simplfication --- UI/MiscScreens.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index cfa3c793e7b9..900d7ad77896 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -1041,15 +1041,13 @@ void CreditsScreen::DrawForeground(UIContext &dc) { float t = (float)(time_now_d() - startTime_) * 60.0; float y = bounds.y2() - fmodf(t, (float)totalHeight); - std::string line; for (int i = 0; i < numItems; i++) { float alpha = linearInOut(y+32, 64, bounds.y2() - 192, 64); uint32_t textColor = colorAlpha(dc.theme->infoStyle.fgColor, alpha); if (alpha > 0.0f) { dc.SetFontScale(ease(alpha), ease(alpha)); - line = credits[i]; - dc.DrawText(line.c_str(), bounds.centerX(), y, textColor, ALIGN_HCENTER); + dc.DrawText(credits[i], bounds.centerX(), y, textColor, ALIGN_HCENTER); dc.SetFontScale(1.0f, 1.0f); } y += itemHeight; From 81c642e2b24d15ce1ddd5572639690c7bb8fd433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 1 Jun 2024 13:44:11 +0200 Subject: [PATCH 2/2] Fix scaling issues in cocoa text drawer --- Common/Math/curves.cpp | 6 +++--- Common/Render/Text/draw_text.cpp | 8 ++++---- Common/Render/Text/draw_text_cocoa.mm | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Common/Math/curves.cpp b/Common/Math/curves.cpp index 88c915b62d89..982b8ea28500 100644 --- a/Common/Math/curves.cpp +++ b/Common/Math/curves.cpp @@ -33,14 +33,14 @@ float linearOut(int t, int fadeOutLength) { } float ease(float val) { - if (val > 1.0f) return 1.0f; - if (val < 0.0f) return 0.0f; + if (val >= 1.0f) return 1.0f; + if (val <= 0.0f) return 0.0f; return (float)(((-cosf(val * PI)) + 1.0f) * 0.5); } float ease(int t, int fadeLength) { - if (t < 0) return 0.0f; + if (t <= 0.0f) return 0.0f; if (t >= fadeLength) return 1.0f; return ease((float)t / (float)fadeLength); } diff --git a/Common/Render/Text/draw_text.cpp b/Common/Render/Text/draw_text.cpp index 8e5a1edc0a64..8303c2b6e1ee 100644 --- a/Common/Render/Text/draw_text.cpp +++ b/Common/Render/Text/draw_text.cpp @@ -113,10 +113,10 @@ void TextDrawer::DrawString(DrawBuffer &target, std::string_view str, float x, f draw_->BindTexture(0, entry->texture); // Okay, the texture is bound, let's draw. - float w = entry->width * fontScaleX_ * dpiScale_; - float h = entry->height * fontScaleY_ * dpiScale_; - float u = entry->width / (float)entry->bmWidth; - float v = entry->height / (float)entry->bmHeight; + float w = (float)entry->width * (fontScaleX_ * dpiScale_); + float h = (float)entry->height * (fontScaleY_ * dpiScale_); + float u = (float)entry->width / (float)entry->bmWidth; + float v = (float)entry->height / (float)entry->bmHeight; DrawBuffer::DoAlign(align, &x, &y, &w, &h); target.DrawTexRect(x, y, x + w, y + h, 0.0f, 0.0f, u, v, color); diff --git a/Common/Render/Text/draw_text_cocoa.mm b/Common/Render/Text/draw_text_cocoa.mm index f75e8739f959..ff7ac1b0d665 100644 --- a/Common/Render/Text/draw_text_cocoa.mm +++ b/Common/Render/Text/draw_text_cocoa.mm @@ -184,8 +184,8 @@ void Destroy() { float w, h; MeasureString(str, &w, &h); // Reverse the DPI scale that MeasureString baked in. - w /= dpiScale_; - h /= dpiScale_; + w /= (dpiScale_ * fontScaleX_); + h /= (dpiScale_ * fontScaleY_); int width = (int)ceilf(w); int height = (int)ceilf(h);