From 2bbad2e03b6cbbc01dac7055cd68a82c7d2185ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 6 Jan 2026 21:11:04 +0100 Subject: [PATCH] Floating symbols background animation: Make resolution-dependent Fixes part of #20211 --- UI/Background.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/UI/Background.cpp b/UI/Background.cpp index 4368e9b887..d192c1c061 100644 --- a/UI/Background.cpp +++ b/UI/Background.cpp @@ -118,18 +118,19 @@ public: } void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override { - dc.Flush(); - dc.Begin(); float xres = dc.GetBounds().w; float yres = dc.GetBounds().h; + + dc.Flush(); + dc.Begin(); if (last_xres != xres || last_yres != yres) { Regenerate(xres, yres); } - for (int i = 0; i < COUNT; i++) { - float x = xbase[i] + dc.GetBounds().x; - float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); - float angle = (float)sin(i + t); + for (size_t i = 0; i < base.size(); i++) { + const float x = base[i].x + dc.GetBounds().x; + const float y = base[i].y + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); + const float angle = sinf(i + t); int n = i & 3; Color color = is_colored ? colorAlpha(COLORS[n], alpha * 0.25f) : colorAlpha(DEFAULT_COLOR, alpha * 0.1f); ui_draw2d.DrawImageRotated(SYMBOLS[n], x, y, 1.0f, angle, color); @@ -138,22 +139,23 @@ public: } private: - static constexpr int COUNT = 100; static constexpr Color DEFAULT_COLOR = 0xC0FFFFFF; static constexpr Color COLORS[4] = {0xFFE3B56F, 0xFF615BFF, 0xFFAA88F3, 0xFFC2CC7A,}; // X O D A static const ImageID SYMBOLS[4]; bool is_colored = false; - float xbase[COUNT]{}; - float ybase[COUNT]{}; + std::vector base; float last_xres = 0; float last_yres = 0; void Regenerate(int xres, int yres) { + int count = xres * yres / (120.0f * 120.0f); + base.resize(count); + GMRng rng; - for (int i = 0; i < COUNT; i++) { - xbase[i] = rng.F() * xres; - ybase[i] = rng.F() * yres; + rng.Init(time_now_d() * 100239); + for (size_t i = 0; i < base.size(); i++) { + base[i] = { rng.F() * xres, rng.F() * yres }; } last_xres = xres;