mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-27 08:05:41 +00:00
CommonHostInterface: Don't draw OSD/FPS as windows
Slight performance improvement.
This commit is contained in:
parent
9f73791343
commit
c8efade20c
|
@ -859,72 +859,68 @@ void CommonHostInterface::DrawFPSWindow()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImVec2 window_size =
|
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
||||||
ImVec2(175.0f * ImGui::GetIO().DisplayFramebufferScale.x, 48.0f * ImGui::GetIO().DisplayFramebufferScale.y);
|
float margin = 10.0f * scale;
|
||||||
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - window_size.x, 0.0f), ImGuiCond_Always);
|
float spacing = 5.0f * scale;
|
||||||
ImGui::SetNextWindowSize(window_size);
|
float position_y = margin;
|
||||||
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
if (!ImGui::Begin("FPSWindow", nullptr,
|
ImFont* font = ImGui::GetFont();
|
||||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse |
|
TinyString text;
|
||||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMouseInputs |
|
ImVec2 text_size;
|
||||||
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNav))
|
|
||||||
{
|
|
||||||
ImGui::End();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
if (g_settings.display_show_fps)
|
|
||||||
{
|
|
||||||
ImGui::Text("%.2f", System::GetFPS());
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
if (g_settings.display_show_vps)
|
|
||||||
{
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("/");
|
|
||||||
ImGui::SameLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::Text("%.2f", System::GetVPS());
|
#define DRAW_LINE(color) \
|
||||||
}
|
do \
|
||||||
if (g_settings.display_show_speed)
|
{ \
|
||||||
{
|
text_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, text, \
|
||||||
if (first)
|
text.GetCharArray() + text.GetLength(), nullptr); \
|
||||||
{
|
dl->AddText(font, font->FontSize, ImVec2(ImGui::GetIO().DisplaySize.x - margin - text_size.x, position_y), color, \
|
||||||
first = false;
|
text, text.GetCharArray() + text.GetLength()); \
|
||||||
}
|
position_y += text_size.y + spacing; \
|
||||||
else
|
} while (0)
|
||||||
{
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("/");
|
|
||||||
ImGui::SameLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const System::State state = System::GetState();
|
||||||
|
if (System::GetState() == System::State::Running)
|
||||||
|
{
|
||||||
const float speed = System::GetEmulationSpeed();
|
const float speed = System::GetEmulationSpeed();
|
||||||
const u32 rounded_speed = static_cast<u32>(std::round(speed));
|
if (g_settings.display_show_fps)
|
||||||
if (speed < 90.0f)
|
{
|
||||||
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "%u%%", rounded_speed);
|
text.AppendFormattedString("%.2f", System::GetFPS());
|
||||||
else if (speed < 110.0f)
|
first = false;
|
||||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "%u%%", rounded_speed);
|
}
|
||||||
else
|
if (g_settings.display_show_vps)
|
||||||
ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "%u%%", rounded_speed);
|
{
|
||||||
|
text.AppendFormattedString("%s%.2f", first ? "" : " / ", System::GetVPS());
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
if (g_settings.display_show_speed)
|
||||||
|
{
|
||||||
|
text.AppendFormattedString("%s%u%%", first ? "" : " / ", static_cast<u32>(std::round(speed)));
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
if (!text.IsEmpty())
|
||||||
|
{
|
||||||
|
ImU32 color;
|
||||||
|
if (speed < 95.0f)
|
||||||
|
color = IM_COL32(255, 100, 100, 255);
|
||||||
|
else if (speed > 105.0f)
|
||||||
|
color = IM_COL32(100, 255, 100, 255);
|
||||||
|
else
|
||||||
|
color = IM_COL32(255, 255, 255, 255);
|
||||||
|
|
||||||
|
DRAW_LINE(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_settings.display_show_resolution)
|
||||||
|
{
|
||||||
|
const auto [effective_width, effective_height] = g_gpu->GetEffectiveDisplayResolution();
|
||||||
|
const bool interlaced = g_gpu->IsInterlacedDisplayEnabled();
|
||||||
|
text.Format("%ux%u (%s)", effective_width, effective_height, interlaced ? "interlaced" : "progressive");
|
||||||
|
DRAW_LINE(IM_COL32(255, 255, 255, 255));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_settings.display_show_resolution)
|
#undef DRAW_LINE
|
||||||
{
|
|
||||||
const auto [effective_width, effective_height] = g_gpu->GetEffectiveDisplayResolution();
|
|
||||||
const bool interlaced = g_gpu->IsInterlacedDisplayEnabled();
|
|
||||||
ImGui::Text("%ux%u (%s)", effective_width, effective_height, interlaced ? "interlaced" : "progressive");
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonHostInterface::AddOSDMessage(std::string message, float duration /*= 2.0f*/)
|
void CommonHostInterface::AddOSDMessage(std::string message, float duration /*= 2.0f*/)
|
||||||
|
@ -988,12 +984,17 @@ void CommonHostInterface::DrawOSDMessages()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
||||||
const float max_width = ImGui::GetIO().DisplaySize.x - (20.0f * scale);
|
const float spacing = 5.0f * scale;
|
||||||
|
const float margin = 10.0f * scale;
|
||||||
|
const float padding = 8.0f * scale;
|
||||||
|
const float rounding = 5.0f * scale;
|
||||||
|
const float max_width = ImGui::GetIO().DisplaySize.x - margin;
|
||||||
|
float position_x = margin;
|
||||||
|
float position_y = margin;
|
||||||
|
|
||||||
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
|
ImFont* font = ImGui::GetFont();
|
||||||
auto iter = m_osd_messages.begin();
|
auto iter = m_osd_messages.begin();
|
||||||
float position_x = 10.0f * scale;
|
|
||||||
float position_y = (10.0f + (static_cast<float>(m_display->GetDisplayTopMargin()))) * scale;
|
|
||||||
u32 index = 0;
|
|
||||||
while (iter != m_osd_messages.end())
|
while (iter != m_osd_messages.end())
|
||||||
{
|
{
|
||||||
const OSDMessage& msg = *iter;
|
const OSDMessage& msg = *iter;
|
||||||
|
@ -1005,35 +1006,24 @@ void CommonHostInterface::DrawOSDMessages()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_settings.display_show_osd_messages)
|
if (!g_settings.display_show_osd_messages || position_y >= ImGui::GetIO().DisplaySize.y)
|
||||||
{
|
{
|
||||||
++iter;
|
++iter;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float opacity = std::min(time_remaining, 1.0f);
|
const float opacity = std::min(time_remaining, 1.0f);
|
||||||
const ImVec2 text_size(ImGui::CalcTextSize(msg.text.c_str(), nullptr));
|
|
||||||
const bool wrapped = (text_size.x > max_width);
|
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(position_x, position_y));
|
const ImVec2 pos(position_x, position_y);
|
||||||
ImGui::SetNextWindowSize(ImVec2(wrapped ? max_width : 0.0f, 0.0f));
|
const ImVec2 text_size(ImGui::CalcTextSize(msg.text.c_str(), nullptr, false, max_width));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity);
|
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);
|
||||||
char buf[64];
|
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), ImGui::GetColorU32(ImGuiCol_WindowBg, opacity),
|
||||||
std::snprintf(buf, sizeof(buf), "osd_%u", index++);
|
rounding);
|
||||||
|
dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), ImGui::GetColorU32(ImGuiCol_Border), rounding);
|
||||||
if (ImGui::Begin(buf, nullptr, window_flags))
|
dl->AddText(font, font->FontSize, ImVec2(text_rect.x, text_rect.y), ImGui::GetColorU32(ImGuiCol_Text, opacity),
|
||||||
{
|
msg.text.c_str(), nullptr, max_width, &text_rect);
|
||||||
if (wrapped)
|
position_y += size.y + spacing;
|
||||||
ImGui::TextWrapped("%s", msg.text.c_str());
|
|
||||||
else
|
|
||||||
ImGui::TextUnformatted(msg.text.c_str());
|
|
||||||
|
|
||||||
position_y += ImGui::GetWindowSize().y + (4.0f * scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2685,8 +2685,6 @@ void DrawOSDMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushFont(g_large_font);
|
ImGui::PushFont(g_large_font);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(10.0f, 10.0f));
|
|
||||||
|
|
||||||
const float max_width = LayoutScale(1080.0f);
|
const float max_width = LayoutScale(1080.0f);
|
||||||
const float spacing = LayoutScale(4.0f);
|
const float spacing = LayoutScale(4.0f);
|
||||||
|
@ -2703,7 +2701,7 @@ void DrawOSDMessages()
|
||||||
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, max_width));
|
const ImVec2 text_size(ImGui::CalcTextSize(message.c_str(), nullptr, false, max_width));
|
||||||
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();
|
||||||
|
@ -2715,7 +2713,6 @@ void DrawOSDMessages()
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
ImGui::PopStyleVar(2);
|
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue