Skip to content

Commit b6fa2ce

Browse files
committed
FullscreenUI: Fix shadowed text alpha again
1 parent 9c97182 commit b6fa2ce

3 files changed

Lines changed: 40 additions & 15 deletions

File tree

src/core/achievements.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ void Achievements::DrawGameOverlays()
24112411

24122412
const auto lock = GetLock();
24132413

2414-
constexpr float overlay_opacity = 0.8f;
2414+
constexpr float bg_opacity = 0.8f;
24152415

24162416
const float margin =
24172417
std::max(ImCeil(ImGuiManager::GetScreenMargin() * ImGuiManager::GetGlobalScale()), LayoutScale(10.0f));
@@ -2459,7 +2459,7 @@ void Achievements::DrawGameOverlays()
24592459
if (s_state.active_progress_indicator.has_value())
24602460
{
24612461
AchievementProgressIndicator& indicator = s_state.active_progress_indicator.value();
2462-
const float opacity = IndicatorOpacity(io.DeltaTime, indicator) * overlay_opacity;
2462+
const float opacity = IndicatorOpacity(io.DeltaTime, indicator);
24632463

24642464
const char* text_start = s_state.active_progress_indicator->achievement->measured_progress;
24652465
const char* text_end = text_start + std::strlen(text_start);
@@ -2470,7 +2470,8 @@ void Achievements::DrawGameOverlays()
24702470
position.y - image_size.y - padding * 2.0f);
24712471
const ImVec2 box_max = position;
24722472

2473-
dl->AddRectFilled(box_min, box_max, ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity)), rounding);
2473+
dl->AddRectFilled(box_min, box_max,
2474+
ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity * bg_opacity)), rounding);
24742475

24752476
GPUTexture* badge = ImGuiFullscreen::GetCachedTextureAsync(indicator.badge_path);
24762477
if (badge)
@@ -2501,7 +2502,7 @@ void Achievements::DrawGameOverlays()
25012502
for (auto it = s_state.active_leaderboard_trackers.begin(); it != s_state.active_leaderboard_trackers.end();)
25022503
{
25032504
LeaderboardTrackerIndicator& indicator = *it;
2504-
const float opacity = IndicatorOpacity(io.DeltaTime, indicator) * overlay_opacity;
2505+
const float opacity = IndicatorOpacity(io.DeltaTime, indicator);
25052506

25062507
TinyString width_string;
25072508
width_string.append(ICON_FA_STOPWATCH);
@@ -2511,8 +2512,8 @@ void Achievements::DrawGameOverlays()
25112512
ImGuiFullscreen::UIStyle.MediumFont->FontSize, FLT_MAX, 0.0f, width_string.c_str(), width_string.end_ptr());
25122513

25132514
const ImRect box(ImVec2(position.x - size.x - padding * 2.0f, position.y - size.y - padding * 2.0f), position);
2514-
dl->AddRectFilled(box.Min, box.Max, ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity)),
2515-
rounding);
2515+
dl->AddRectFilled(box.Min, box.Max,
2516+
ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity * bg_opacity)), rounding);
25162517

25172518
const u32 text_col = ImGui::GetColorU32(ModAlpha(UIStyle.ToastTextColor, opacity));
25182519
const ImVec2 text_size = ImGuiFullscreen::UIStyle.MediumFont->CalcTextSizeA(

src/util/imgui_fullscreen.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,9 +1299,9 @@ void ImGuiFullscreen::ResetMenuButtonFrame()
12991299

13001300
void ImGuiFullscreen::RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min,
13011301
const ImVec2& pos_max, u32 color, const char* text,
1302-
const char* text_end, const ImVec2* text_size_if_known /* = nullptr */,
1303-
const ImVec2& align /* = ImVec2(0, 0)*/, float wrap_width /* = 0.0f*/,
1304-
const ImRect* clip_rect /* = nullptr */)
1302+
const char* text_end, const ImVec2* text_size_if_known,
1303+
const ImVec2& align, float wrap_width, const ImRect* clip_rect,
1304+
float shadow_offset)
13051305
{
13061306
const char* text_display_end = ImGui::FindRenderedTextEnd(text, text_end);
13071307
const int text_len = (int)(text_display_end - text);
@@ -1328,22 +1328,36 @@ void ImGuiFullscreen::RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* f
13281328
pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
13291329

13301330
// Render
1331-
const u32 shadow_color = (UIStyle.ShadowColor & ~IM_COL32_A_MASK) | (color & IM_COL32_A_MASK);
1331+
const u32 alpha = (color /*& IM_COL32_A_MASK*/) >> IM_COL32_A_SHIFT;
1332+
if (alpha == 0)
1333+
return;
1334+
1335+
const u32 shadow_color = MulAlpha(UIStyle.ShadowColor, alpha);
13321336
if (need_clipping)
13331337
{
13341338
ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
1335-
draw_list->AddText(font, font->FontSize, pos + LayoutScale(LAYOUT_SHADOW_OFFSET, LAYOUT_SHADOW_OFFSET),
1336-
shadow_color, text, text_display_end, wrap_width, &fine_clip_rect);
1339+
draw_list->AddText(font, font->FontSize, ImVec2(pos.x + shadow_offset, pos.y + shadow_offset), shadow_color, text,
1340+
text_display_end, wrap_width, &fine_clip_rect);
13371341
draw_list->AddText(font, font->FontSize, pos, color, text, text_display_end, wrap_width, &fine_clip_rect);
13381342
}
13391343
else
13401344
{
1341-
draw_list->AddText(font, font->FontSize, pos + LayoutScale(LAYOUT_SHADOW_OFFSET, LAYOUT_SHADOW_OFFSET),
1342-
shadow_color, text, text_display_end, wrap_width, nullptr);
1345+
draw_list->AddText(font, font->FontSize, ImVec2(pos.x + shadow_offset, pos.y + shadow_offset), shadow_color, text,
1346+
text_display_end, wrap_width, nullptr);
13431347
draw_list->AddText(font, font->FontSize, pos, color, text, text_display_end, wrap_width, nullptr);
13441348
}
13451349
}
13461350

1351+
void ImGuiFullscreen::RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min,
1352+
const ImVec2& pos_max, u32 color, const char* text,
1353+
const char* text_end, const ImVec2* text_size_if_known /* = nullptr */,
1354+
const ImVec2& align /* = ImVec2(0, 0)*/, float wrap_width /* = 0.0f*/,
1355+
const ImRect* clip_rect /* = nullptr */)
1356+
{
1357+
RenderShadowedTextClipped(draw_list, font, pos_min, pos_max, color, text, text_end, text_size_if_known, align,
1358+
wrap_width, clip_rect, LayoutScale(LAYOUT_SHADOW_OFFSET));
1359+
}
1360+
13471361
void ImGuiFullscreen::RenderShadowedTextClipped(ImFont* font, const ImVec2& pos_min, const ImVec2& pos_max, u32 color,
13481362
const char* text, const char* text_end,
13491363
const ImVec2* text_size_if_known /* = nullptr */,

src/util/imgui_fullscreen.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ ALWAYS_INLINE static ImVec4 MulAlpha(const ImVec4& v, float a)
133133
ALWAYS_INLINE static u32 MulAlpha(u32 col32, float a)
134134
{
135135
return (col32 & ~IM_COL32_A_MASK) |
136-
(static_cast<u32>(static_cast<float>((col32 & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) * a) << IM_COL32_A_SHIFT);
136+
(static_cast<u32>(static_cast<float>((col32 /*& IM_COL32_A_MASK*/) >> IM_COL32_A_SHIFT) * a)
137+
<< IM_COL32_A_SHIFT);
138+
}
139+
140+
ALWAYS_INLINE static u32 MulAlpha(u32 col32, u32 a)
141+
{
142+
return (col32 & ~IM_COL32_A_MASK) |
143+
(((((col32 /*& IM_COL32_A_MASK*/) >> IM_COL32_A_SHIFT) * a) / 255u) << IM_COL32_A_SHIFT);
137144
}
138145

139146
ALWAYS_INLINE static std::string_view RemoveHash(std::string_view s)
@@ -247,6 +254,9 @@ void RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2
247254
u32 color, const char* text, const char* text_end,
248255
const ImVec2* text_size_if_known = nullptr, const ImVec2& align = ImVec2(0, 0),
249256
float wrap_width = 0.0f, const ImRect* clip_rect = nullptr);
257+
void RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min, const ImVec2& pos_max,
258+
u32 color, const char* text, const char* text_end, const ImVec2* text_size_if_known,
259+
const ImVec2& align, float wrap_width, const ImRect* clip_rect, float shadow_offset);
250260
void MenuHeading(const char* title, bool draw_line = true);
251261
bool MenuHeadingButton(const char* title, const char* value = nullptr, bool enabled = true, bool draw_line = true);
252262
bool ActiveButton(const char* title, bool is_active, bool enabled = true,

0 commit comments

Comments
 (0)