OSD: Draw shadows on stats overlays (FPS/Resolution)
Makes it more visible on white backgrounds.
This commit is contained in:
parent
175abd4914
commit
77090865c1
|
@ -864,6 +864,7 @@ void CommonHostInterface::DrawFPSWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
||||||
|
const float shadow_offset = 1.0f * scale;
|
||||||
float margin = 10.0f * scale;
|
float margin = 10.0f * scale;
|
||||||
float spacing = 5.0f * scale;
|
float spacing = 5.0f * scale;
|
||||||
float position_y = margin;
|
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_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, text, \
|
||||||
text.GetCharArray() + text.GetLength(), nullptr); \
|
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, \
|
dl->AddText(font, font->FontSize, ImVec2(ImGui::GetIO().DisplaySize.x - margin - text_size.x, position_y), color, \
|
||||||
text, text.GetCharArray() + text.GetLength()); \
|
text, text.GetCharArray() + text.GetLength()); \
|
||||||
position_y += text_size.y + spacing; \
|
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.
|
// 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,
|
// 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.
|
// avoid 99.99% of the unnecessary lock attempts when size == 0.
|
||||||
|
|
||||||
std::atomic_thread_fence(std::memory_order_consume);
|
std::atomic_thread_fence(std::memory_order_consume);
|
||||||
if (!m_osd_posted_messages.empty())
|
if (!m_osd_posted_messages.empty())
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
||||||
for(;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
// lock-and-copy mechanism.
|
// lock-and-copy mechanism.
|
||||||
// this allows us to unlock the deque and minimize time that the mutex is held.
|
// 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_x = margin;
|
||||||
float position_y = margin;
|
float position_y = margin;
|
||||||
|
|
||||||
EnumerateOSDMessages(
|
EnumerateOSDMessages([max_width, spacing, padding, rounding, &position_x, &position_y](const std::string& message,
|
||||||
[max_width, spacing, padding, rounding, &position_x, &position_y](const std::string& message, float time_remaining) -> bool {
|
float time_remaining) -> bool {
|
||||||
const float opacity = std::min(time_remaining, 1.0f);
|
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)
|
if (position_y >= ImGui::GetIO().DisplaySize.y)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ImVec2 pos(position_x, position_y);
|
const ImVec2 pos(position_x, position_y);
|
||||||
const ImVec2 text_size(ImGui::CalcTextSize(message.c_str(), nullptr, false, max_width));
|
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 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 ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
|
||||||
|
|
||||||
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
ImFont* font = ImGui::GetFont();
|
ImFont* font = ImGui::GetFont();
|
||||||
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), ImGui::GetColorU32(ImGuiCol_WindowBg, opacity),
|
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x21, 0x21, 0x21, alpha), rounding);
|
||||||
rounding);
|
dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x48, 0x48, 0x48, alpha), 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), IM_COL32(0xff, 0xff, 0xff, alpha),
|
||||||
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);
|
||||||
message.c_str(), nullptr, max_width, &text_rect);
|
position_y += size.y + spacing;
|
||||||
position_y += size.y + spacing;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonHostInterface::DrawDebugWindows()
|
void CommonHostInterface::DrawDebugWindows()
|
||||||
|
|
|
@ -307,9 +307,9 @@ void Render()
|
||||||
if (s_input_binding_type != InputBindingType::None)
|
if (s_input_binding_type != InputBindingType::None)
|
||||||
DrawInputBindingWindow();
|
DrawInputBindingWindow();
|
||||||
|
|
||||||
ImGuiFullscreen::EndLayout();
|
|
||||||
|
|
||||||
DrawOSDMessages();
|
DrawOSDMessages();
|
||||||
|
|
||||||
|
ImGuiFullscreen::EndLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings& GetSettingsCopy()
|
Settings& GetSettingsCopy()
|
||||||
|
@ -2638,7 +2638,8 @@ void DrawStatsOverlay()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float margin = LayoutScale(10.0f);
|
const float margin = LayoutScale(10.0f);
|
||||||
|
const float shadow_offset = DPIScale(1.0f);
|
||||||
float position_y = margin;
|
float position_y = margin;
|
||||||
ImDrawList* dl = GetDrawListForOverlay();
|
ImDrawList* dl = GetDrawListForOverlay();
|
||||||
TinyString text;
|
TinyString text;
|
||||||
|
@ -2650,6 +2651,10 @@ void DrawStatsOverlay()
|
||||||
{ \
|
{ \
|
||||||
text_size = font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(), -1.0f, text, \
|
text_size = font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(), -1.0f, text, \
|
||||||
text.GetCharArray() + text.GetLength(), nullptr); \
|
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), \
|
dl->AddText(font, font_size, ImVec2(ImGui::GetIO().DisplaySize.x - (right_pad)-margin - text_size.x, position_y), \
|
||||||
color, text, text.GetCharArray() + text.GetLength()); \
|
color, text, text.GetCharArray() + text.GetLength()); \
|
||||||
position_y += text_size.y + margin; \
|
position_y += text_size.y + margin; \
|
||||||
|
@ -2726,6 +2731,7 @@ void DrawOSDMessages()
|
||||||
s_host_interface->EnumerateOSDMessages(
|
s_host_interface->EnumerateOSDMessages(
|
||||||
[max_width, spacing, padding, &position_x, &position_y](const std::string& message, float time_remaining) -> bool {
|
[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 float opacity = std::min(time_remaining, 1.0f);
|
||||||
|
const u32 alpha = static_cast<u32>(opacity * 255.0f);
|
||||||
|
|
||||||
if (position_y >= ImGui::GetIO().DisplaySize.y)
|
if (position_y >= ImGui::GetIO().DisplaySize.y)
|
||||||
return false;
|
return false;
|
||||||
|
@ -2735,10 +2741,10 @@ void DrawOSDMessages()
|
||||||
const ImVec2 size(text_size + LayoutScale(20.0f, 20.0f));
|
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);
|
const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding);
|
||||||
ImDrawList* dl = GetDrawListForOverlay();
|
ImDrawList* dl = GetDrawListForOverlay();
|
||||||
dl->AddRectFilled(pos, pos + size, ImGui::GetColorU32(ImGuiCol_WindowBg, opacity), LayoutScale(10.0f));
|
dl->AddRectFilled(pos, pos + size, IM_COL32(0x21, 0x21, 0x21, alpha), LayoutScale(10.0f));
|
||||||
dl->AddRect(pos, pos + size, ImGui::GetColorU32(ImGuiCol_Border), 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),
|
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;
|
position_y += size.y + spacing;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue