Skip to content

Commit cffafad

Browse files
committed
ImGuiManager: Use fullscreen UI theme for OSD
1 parent b6fa2ce commit cffafad

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/core/fullscreen_ui.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ bool FullscreenUI::Initialize()
660660
if (s_state.tried_to_initialize)
661661
return false;
662662

663-
ImGuiFullscreen::SetTheme(Host::GetBaseStringSettingValue("UI", "FullscreenUITheme", "Dark"));
664663
ImGuiFullscreen::SetSmoothScrolling(Host::GetBaseBoolSettingValue("Main", "FullscreenUISmoothScrolling", true));
665664
ImGuiFullscreen::UpdateLayoutScale();
666665

src/util/imgui_manager.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ bool ImGuiManager::Initialize(float global_scale, float screen_margin, Error* er
257257

258258
SetKeyMap();
259259
SetStyle(s_state.imgui_context->Style, s_state.global_scale);
260+
ImGuiFullscreen::SetTheme(Host::GetBaseStringSettingValue("UI", "FullscreenUITheme", "Dark"));
260261

261262
if (!AddImGuiFonts(false, false) || !g_gpu_device->UpdateImGuiFontTexture())
262263
{
@@ -953,6 +954,10 @@ void ImGuiManager::AcquirePendingOSDMessages(Timer::Value current_time)
953954

954955
void ImGuiManager::DrawOSDMessages(Timer::Value current_time)
955956
{
957+
using ImGuiFullscreen::ModAlpha;
958+
using ImGuiFullscreen::RenderShadowedTextClipped;
959+
using ImGuiFullscreen::UIStyle;
960+
956961
static constexpr float MOVE_DURATION = 0.5f;
957962

958963
ImFont* const font = s_state.osd_font;
@@ -979,13 +984,13 @@ void ImGuiManager::DrawOSDMessages(Timer::Value current_time)
979984

980985
++iter;
981986

982-
u8 opacity;
987+
float opacity;
983988
if (time_passed < OSD_FADE_IN_TIME)
984-
opacity = static_cast<u8>((time_passed / OSD_FADE_IN_TIME) * 255.0f);
989+
opacity = time_passed / OSD_FADE_IN_TIME;
985990
else if (time_passed > (msg.duration - OSD_FADE_OUT_TIME))
986-
opacity = static_cast<u8>(std::min((msg.duration - time_passed) / OSD_FADE_OUT_TIME, 1.0f) * 255.0f);
991+
opacity = std::min((msg.duration - time_passed) / OSD_FADE_OUT_TIME, 1.0f);
987992
else
988-
opacity = 255;
993+
opacity = 1.0f;
989994

990995
const float expected_y = position_y;
991996
float actual_y = msg.last_y;
@@ -1031,13 +1036,15 @@ void ImGuiManager::DrawOSDMessages(Timer::Value current_time)
10311036
const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, max_width, max_width, msg.text.c_str(),
10321037
msg.text.c_str() + msg.text.length()));
10331038
const ImVec2 size(text_size.x + padding * 2.0f, text_size.y + padding * 2.0f);
1034-
const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
1039+
const ImRect text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
10351040

10361041
ImDrawList* dl = ImGui::GetForegroundDrawList();
1037-
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x21, 0x21, 0x21, opacity), rounding);
1038-
dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x48, 0x48, 0x48, opacity), rounding);
1039-
dl->AddText(font, font->FontSize, ImVec2(text_rect.x, text_rect.y), IM_COL32(0xff, 0xff, 0xff, opacity),
1040-
msg.text.c_str(), msg.text.c_str() + msg.text.length(), max_width, &text_rect);
1042+
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y),
1043+
ImGui::GetColorU32(ModAlpha(UIStyle.ToastBackgroundColor, opacity * 0.95f)), rounding);
1044+
RenderShadowedTextClipped(dl, font, text_rect.Min, text_rect.Max,
1045+
ImGui::GetColorU32(ModAlpha(UIStyle.ToastTextColor, opacity)), msg.text.c_str(),
1046+
msg.text.c_str() + msg.text.length(), &text_size, ImVec2(0.0f, 0.0f), max_width,
1047+
&text_rect, scale);
10411048
position_y += size.y + spacing;
10421049
}
10431050
}

0 commit comments

Comments
 (0)