OSD: Draw shadows on stats overlays (FPS/Resolution)

Makes it more visible on white backgrounds.
This commit is contained in:
Connor McLaughlin 2021-02-24 00:20:52 +10:00
parent 175abd4914
commit 77090865c1
2 changed files with 38 additions and 28 deletions

View File

@ -864,6 +864,7 @@ void CommonHostInterface::DrawFPSWindow()
}
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
const float shadow_offset = 1.0f * scale;
float margin = 10.0f * scale;
float spacing = 5.0f * scale;
float position_y = margin;
@ -878,6 +879,10 @@ void CommonHostInterface::DrawFPSWindow()
{ \
text_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, text, \
text.GetCharArray() + text.GetLength(), nullptr); \
dl->AddText( \
font, font->FontSize, \
ImVec2(ImGui::GetIO().DisplaySize.x - margin - text_size.x + shadow_offset, position_y + shadow_offset), \
IM_COL32(0, 0, 0, 100), text, text.GetCharArray() + text.GetLength()); \
dl->AddText(font, font->FontSize, ImVec2(ImGui::GetIO().DisplaySize.x - margin - text_size.x, position_y), color, \
text, text.GetCharArray() + text.GetLength()); \
position_y += text_size.y + spacing; \
@ -972,14 +977,14 @@ void CommonHostInterface::AcquirePendingOSDMessages()
// we just want to force the compiler to always reload the deque size value from memory.
//
// ARM doesn't have good atomic read guarantees so it _could_ read some non-zero value here spuriously,
// but that's OK because we lock the mutex later and recheck things anyway. This early out will still
// but that's OK because we lock the mutex later and recheck things anyway. This early out will still
// avoid 99.99% of the unnecessary lock attempts when size == 0.
std::atomic_thread_fence(std::memory_order_consume);
if (!m_osd_posted_messages.empty())
{
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
for(;;)
for (;;)
{
// lock-and-copy mechanism.
// this allows us to unlock the deque and minimize time that the mutex is held.
@ -1020,30 +1025,29 @@ void CommonHostInterface::DrawOSDMessages()
float position_x = margin;
float position_y = margin;
EnumerateOSDMessages(
[max_width, spacing, padding, rounding, &position_x, &position_y](const std::string& message, float time_remaining) -> bool {
const float opacity = std::min(time_remaining, 1.0f);
EnumerateOSDMessages([max_width, spacing, padding, rounding, &position_x, &position_y](const std::string& message,
float time_remaining) -> bool {
const float opacity = std::min(time_remaining, 1.0f);
const u32 alpha = static_cast<u32>(opacity * 255.0f);
if (position_y >= ImGui::GetIO().DisplaySize.y)
return false;
if (position_y >= ImGui::GetIO().DisplaySize.y)
return false;
const ImVec2 pos(position_x, position_y);
const ImVec2 text_size(ImGui::CalcTextSize(message.c_str(), nullptr, false, max_width));
const ImVec2 size(text_size.x + padding * 2.0f, text_size.y + padding * 2.0f);
const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
const ImVec2 pos(position_x, position_y);
const ImVec2 text_size(ImGui::CalcTextSize(message.c_str(), nullptr, false, max_width));
const ImVec2 size(text_size.x + padding * 2.0f, text_size.y + padding * 2.0f);
const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
ImDrawList* dl = ImGui::GetBackgroundDrawList();
ImFont* font = ImGui::GetFont();
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), ImGui::GetColorU32(ImGuiCol_WindowBg, opacity),
rounding);
dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), ImGui::GetColorU32(ImGuiCol_Border), rounding);
dl->AddText(font, font->FontSize, ImVec2(text_rect.x, text_rect.y), ImGui::GetColorU32(ImGuiCol_Text, opacity),
message.c_str(), nullptr, max_width, &text_rect);
position_y += size.y + spacing;
ImDrawList* dl = ImGui::GetBackgroundDrawList();
ImFont* font = ImGui::GetFont();
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x21, 0x21, 0x21, alpha), rounding);
dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x48, 0x48, 0x48, alpha), rounding);
dl->AddText(font, font->FontSize, ImVec2(text_rect.x, text_rect.y), IM_COL32(0xff, 0xff, 0xff, alpha),
message.c_str(), nullptr, max_width, &text_rect);
position_y += size.y + spacing;
return true;
}
);
return true;
});
}
void CommonHostInterface::DrawDebugWindows()

View File

@ -307,9 +307,9 @@ void Render()
if (s_input_binding_type != InputBindingType::None)
DrawInputBindingWindow();
ImGuiFullscreen::EndLayout();
DrawOSDMessages();
ImGuiFullscreen::EndLayout();
}
Settings& GetSettingsCopy()
@ -2638,7 +2638,8 @@ void DrawStatsOverlay()
return;
}
float margin = LayoutScale(10.0f);
const float margin = LayoutScale(10.0f);
const float shadow_offset = DPIScale(1.0f);
float position_y = margin;
ImDrawList* dl = GetDrawListForOverlay();
TinyString text;
@ -2650,6 +2651,10 @@ void DrawStatsOverlay()
{ \
text_size = font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(), -1.0f, text, \
text.GetCharArray() + text.GetLength(), nullptr); \
dl->AddText(font, font_size, \
ImVec2(ImGui::GetIO().DisplaySize.x - (right_pad)-margin - text_size.x + shadow_offset, \
position_y + shadow_offset), \
IM_COL32(0, 0, 0, 100), text, text.GetCharArray() + text.GetLength()); \
dl->AddText(font, font_size, ImVec2(ImGui::GetIO().DisplaySize.x - (right_pad)-margin - text_size.x, position_y), \
color, text, text.GetCharArray() + text.GetLength()); \
position_y += text_size.y + margin; \
@ -2726,6 +2731,7 @@ void DrawOSDMessages()
s_host_interface->EnumerateOSDMessages(
[max_width, spacing, padding, &position_x, &position_y](const std::string& message, float time_remaining) -> bool {
const float opacity = std::min(time_remaining, 1.0f);
const u32 alpha = static_cast<u32>(opacity * 255.0f);
if (position_y >= ImGui::GetIO().DisplaySize.y)
return false;
@ -2735,10 +2741,10 @@ void DrawOSDMessages()
const ImVec2 size(text_size + LayoutScale(20.0f, 20.0f));
const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
ImDrawList* dl = GetDrawListForOverlay();
dl->AddRectFilled(pos, pos + size, ImGui::GetColorU32(ImGuiCol_WindowBg, opacity), LayoutScale(10.0f));
dl->AddRect(pos, pos + size, ImGui::GetColorU32(ImGuiCol_Border), LayoutScale(10.0f));
dl->AddRectFilled(pos, pos + size, IM_COL32(0x21, 0x21, 0x21, alpha), LayoutScale(10.0f));
dl->AddRect(pos, pos + size, IM_COL32(0x48, 0x48, 0x48, alpha), LayoutScale(10.0f));
dl->AddText(g_large_font, g_large_font->FontSize, ImVec2(text_rect.x, text_rect.y),
ImGui::GetColorU32(ImGuiCol_Text, opacity), message.c_str(), nullptr, max_width, &text_rect);
IM_COL32(0xff, 0xff, 0xff, alpha), message.c_str(), nullptr, max_width, &text_rect);
position_y += size.y + spacing;
return true;
});