FullscreenUI: Fix shadowed text alpha again

This commit is contained in:
Stenzek 2025-03-14 22:24:37 +10:00
parent 9c971825a9
commit b6fa2cecd3
No known key found for this signature in database
3 changed files with 40 additions and 15 deletions

View File

@ -2411,7 +2411,7 @@ void Achievements::DrawGameOverlays()
const auto lock = GetLock();
constexpr float overlay_opacity = 0.8f;
constexpr float bg_opacity = 0.8f;
const float margin =
std::max(ImCeil(ImGuiManager::GetScreenMargin() * ImGuiManager::GetGlobalScale()), LayoutScale(10.0f));
@ -2459,7 +2459,7 @@ void Achievements::DrawGameOverlays()
if (s_state.active_progress_indicator.has_value())
{
AchievementProgressIndicator& indicator = s_state.active_progress_indicator.value();
const float opacity = IndicatorOpacity(io.DeltaTime, indicator) * overlay_opacity;
const float opacity = IndicatorOpacity(io.DeltaTime, indicator);
const char* text_start = s_state.active_progress_indicator->achievement->measured_progress;
const char* text_end = text_start + std::strlen(text_start);
@ -2470,7 +2470,8 @@ void Achievements::DrawGameOverlays()
position.y - image_size.y - padding * 2.0f);
const ImVec2 box_max = position;
dl->AddRectFilled(box_min, box_max, ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity)), rounding);
dl->AddRectFilled(box_min, box_max,
ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity * bg_opacity)), rounding);
GPUTexture* badge = ImGuiFullscreen::GetCachedTextureAsync(indicator.badge_path);
if (badge)
@ -2501,7 +2502,7 @@ void Achievements::DrawGameOverlays()
for (auto it = s_state.active_leaderboard_trackers.begin(); it != s_state.active_leaderboard_trackers.end();)
{
LeaderboardTrackerIndicator& indicator = *it;
const float opacity = IndicatorOpacity(io.DeltaTime, indicator) * overlay_opacity;
const float opacity = IndicatorOpacity(io.DeltaTime, indicator);
TinyString width_string;
width_string.append(ICON_FA_STOPWATCH);
@ -2511,8 +2512,8 @@ void Achievements::DrawGameOverlays()
ImGuiFullscreen::UIStyle.MediumFont->FontSize, FLT_MAX, 0.0f, width_string.c_str(), width_string.end_ptr());
const ImRect box(ImVec2(position.x - size.x - padding * 2.0f, position.y - size.y - padding * 2.0f), position);
dl->AddRectFilled(box.Min, box.Max, ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity)),
rounding);
dl->AddRectFilled(box.Min, box.Max,
ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity * bg_opacity)), rounding);
const u32 text_col = ImGui::GetColorU32(ModAlpha(UIStyle.ToastTextColor, opacity));
const ImVec2 text_size = ImGuiFullscreen::UIStyle.MediumFont->CalcTextSizeA(

View File

@ -1299,9 +1299,9 @@ void ImGuiFullscreen::ResetMenuButtonFrame()
void ImGuiFullscreen::RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min,
const ImVec2& pos_max, u32 color, const char* text,
const char* text_end, const ImVec2* text_size_if_known /* = nullptr */,
const ImVec2& align /* = ImVec2(0, 0)*/, float wrap_width /* = 0.0f*/,
const ImRect* clip_rect /* = nullptr */)
const char* text_end, const ImVec2* text_size_if_known,
const ImVec2& align, float wrap_width, const ImRect* clip_rect,
float shadow_offset)
{
const char* text_display_end = ImGui::FindRenderedTextEnd(text, text_end);
const int text_len = (int)(text_display_end - text);
@ -1328,22 +1328,36 @@ void ImGuiFullscreen::RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* f
pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
// Render
const u32 shadow_color = (UIStyle.ShadowColor & ~IM_COL32_A_MASK) | (color & IM_COL32_A_MASK);
const u32 alpha = (color /*& IM_COL32_A_MASK*/) >> IM_COL32_A_SHIFT;
if (alpha == 0)
return;
const u32 shadow_color = MulAlpha(UIStyle.ShadowColor, alpha);
if (need_clipping)
{
ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
draw_list->AddText(font, font->FontSize, pos + LayoutScale(LAYOUT_SHADOW_OFFSET, LAYOUT_SHADOW_OFFSET),
shadow_color, text, text_display_end, wrap_width, &fine_clip_rect);
draw_list->AddText(font, font->FontSize, ImVec2(pos.x + shadow_offset, pos.y + shadow_offset), shadow_color, text,
text_display_end, wrap_width, &fine_clip_rect);
draw_list->AddText(font, font->FontSize, pos, color, text, text_display_end, wrap_width, &fine_clip_rect);
}
else
{
draw_list->AddText(font, font->FontSize, pos + LayoutScale(LAYOUT_SHADOW_OFFSET, LAYOUT_SHADOW_OFFSET),
shadow_color, text, text_display_end, wrap_width, nullptr);
draw_list->AddText(font, font->FontSize, ImVec2(pos.x + shadow_offset, pos.y + shadow_offset), shadow_color, text,
text_display_end, wrap_width, nullptr);
draw_list->AddText(font, font->FontSize, pos, color, text, text_display_end, wrap_width, nullptr);
}
}
void ImGuiFullscreen::RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min,
const ImVec2& pos_max, u32 color, const char* text,
const char* text_end, const ImVec2* text_size_if_known /* = nullptr */,
const ImVec2& align /* = ImVec2(0, 0)*/, float wrap_width /* = 0.0f*/,
const ImRect* clip_rect /* = nullptr */)
{
RenderShadowedTextClipped(draw_list, font, pos_min, pos_max, color, text, text_end, text_size_if_known, align,
wrap_width, clip_rect, LayoutScale(LAYOUT_SHADOW_OFFSET));
}
void ImGuiFullscreen::RenderShadowedTextClipped(ImFont* font, const ImVec2& pos_min, const ImVec2& pos_max, u32 color,
const char* text, const char* text_end,
const ImVec2* text_size_if_known /* = nullptr */,

View File

@ -133,7 +133,14 @@ ALWAYS_INLINE static ImVec4 MulAlpha(const ImVec4& v, float a)
ALWAYS_INLINE static u32 MulAlpha(u32 col32, float a)
{
return (col32 & ~IM_COL32_A_MASK) |
(static_cast<u32>(static_cast<float>((col32 & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) * a) << IM_COL32_A_SHIFT);
(static_cast<u32>(static_cast<float>((col32 /*& IM_COL32_A_MASK*/) >> IM_COL32_A_SHIFT) * a)
<< IM_COL32_A_SHIFT);
}
ALWAYS_INLINE static u32 MulAlpha(u32 col32, u32 a)
{
return (col32 & ~IM_COL32_A_MASK) |
(((((col32 /*& IM_COL32_A_MASK*/) >> IM_COL32_A_SHIFT) * a) / 255u) << IM_COL32_A_SHIFT);
}
ALWAYS_INLINE static std::string_view RemoveHash(std::string_view s)
@ -247,6 +254,9 @@ void RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2
u32 color, const char* text, const char* text_end,
const ImVec2* text_size_if_known = nullptr, const ImVec2& align = ImVec2(0, 0),
float wrap_width = 0.0f, const ImRect* clip_rect = nullptr);
void RenderShadowedTextClipped(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min, const ImVec2& pos_max,
u32 color, const char* text, const char* text_end, const ImVec2* text_size_if_known,
const ImVec2& align, float wrap_width, const ImRect* clip_rect, float shadow_offset);
void MenuHeading(const char* title, bool draw_line = true);
bool MenuHeadingButton(const char* title, const char* value = nullptr, bool enabled = true, bool draw_line = true);
bool ActiveButton(const char* title, bool is_active, bool enabled = true,