From fb4d2a0f3fb5846167a91be3921fa2a24a2d4604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 31 Jan 2026 14:09:31 +0100 Subject: [PATCH] Fix rendering of the hold-overlay for main screen buttons without icons --- Common/Data/Color/RGBAUtil.cpp | 12 ++++++++++++ Common/Data/Color/RGBAUtil.h | 1 + UI/MainScreen.cpp | 36 +++++++++++++++++++--------------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Common/Data/Color/RGBAUtil.cpp b/Common/Data/Color/RGBAUtil.cpp index 21b0781a14..865ff1d09f 100644 --- a/Common/Data/Color/RGBAUtil.cpp +++ b/Common/Data/Color/RGBAUtil.cpp @@ -43,6 +43,18 @@ uint32_t colorBlend(uint32_t rgb1, uint32_t rgb2, float alpha) { return c; } +uint32_t colorAdd(uint32_t color, uint32_t color2) { + const int r = (int)((color >> 0) & 0xFF) + (int)((color2 >> 0) & 0xFF); + const int g = (int)((color >> 8) & 0xFF) + (int)((color2 >> 8) & 0xFF); + const int b = (int)((color >> 16) & 0xFF) + (int)((color2 >> 16) & 0xFF); + const int a = (int)((color >> 24) & 0xFF) + (int)((color2 >> 24) & 0xFF); + uint32_t c = clamp(a, 0, 255) << 24; + c |= clamp(b, 0, 255) << 16; + c |= clamp(g, 0, 255) << 8; + c |= clamp(r, 0, 255); + return c; +} + uint32_t alphaMul(uint32_t color, float alphaMul) { const uint32_t rgb = color & 0xFFFFFF; int32_t alpha = color >> 24; diff --git a/Common/Data/Color/RGBAUtil.h b/Common/Data/Color/RGBAUtil.h index 3ea03f328a..f9629df977 100644 --- a/Common/Data/Color/RGBAUtil.h +++ b/Common/Data/Color/RGBAUtil.h @@ -6,6 +6,7 @@ uint32_t whiteAlpha(float alpha); uint32_t blackAlpha(float alpha); uint32_t colorAlpha(uint32_t color, float alpha); uint32_t colorBlend(uint32_t color, uint32_t color2, float alpha); +uint32_t colorAdd(uint32_t color, uint32_t color2); uint32_t alphaMul(uint32_t color, float alphaMul); uint32_t rgba(float r, float g, float b, float alpha); uint32_t rgba_clamp(float r, float g, float b, float alpha); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 3b9617789a..48407b83be 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -296,6 +296,22 @@ void GameButton::Draw(UIContext &dc) { default: break; } + Bounds overlayBounds = bounds_; + u32 overlayColor = 0; + if (holdEnabled_ && holdStart_ != 0.0) { + double time_held = time_now_d() - holdStart_; + overlayColor = whiteAlpha(time_held / 2.5f); + if (holdStart_ != 0.0) { + double time_held = time_now_d() - holdStart_; + int holdFrameCount = (int)(time_held * 60.0f); + if (holdFrameCount > 60) { + // Blink before launching by holding + if (((holdFrameCount >> 3) & 1) == 0) + overlayColor = 0x0; + } + } + } + if (imageIcon.isValid()) { Style style = dc.GetTheme().itemStyle; @@ -305,6 +321,10 @@ void GameButton::Draw(UIContext &dc) { dc.FillRect(style.background, bounds_); DrawIconWithText(dc, imageIcon, ginfo->GetTitle(), bounds_, gridStyle_, style); + + if (overlayColor) { + dc.FillRect(Drawable(overlayColor), overlayBounds); + } return; } @@ -345,13 +365,6 @@ void GameButton::Draw(UIContext &dc) { int txOffset = down_ ? 4 : 0; if (!gridStyle_) txOffset = 0; - Bounds overlayBounds = bounds_; - u32 overlayColor = 0; - if (holdEnabled_ && holdStart_ != 0.0) { - double time_held = time_now_d() - holdStart_; - overlayColor = whiteAlpha(time_held / 2.5f); - } - // Render button int dropsize = 10; if (texture) { @@ -378,15 +391,6 @@ void GameButton::Draw(UIContext &dc) { dc.Draw()->Flush(); dc.GetDrawContext()->BindTexture(0, texture); - if (holdStart_ != 0.0) { - double time_held = time_now_d() - holdStart_; - int holdFrameCount = (int)(time_held * 60.0f); - if (holdFrameCount > 60) { - // Blink before launching by holding - if (((holdFrameCount >> 3) & 1) == 0) - color = darkenColor(color); - } - } dc.Draw()->DrawTexRect(x, y, x+w, y+h, 0, 0, 1, 1, color); dc.Draw()->Flush(); }