CommonHostInterface: Don't draw OSD/FPS as windows

Slight performance improvement.
pull/1630/head
Connor McLaughlin 6 years ago
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();
ImFont* font = ImGui::GetFont();
TinyString text;
ImVec2 text_size;
bool first = true;
if (!ImGui::Begin("FPSWindow", nullptr, #define DRAW_LINE(color) \
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | do \
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMouseInputs | { \
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNav)) text_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, text, \
{ text.GetCharArray() + text.GetLength(), nullptr); \
ImGui::End(); dl->AddText(font, font->FontSize, ImVec2(ImGui::GetIO().DisplaySize.x - margin - text_size.x, position_y), color, \
return; text, text.GetCharArray() + text.GetLength()); \
} position_y += text_size.y + spacing; \
} while (0)
bool first = true; const System::State state = System::GetState();
if (g_settings.display_show_fps) if (System::GetState() == System::State::Running)
{
ImGui::Text("%.2f", System::GetFPS());
first = false;
}
if (g_settings.display_show_vps)
{ {
if (first) const float speed = System::GetEmulationSpeed();
if (g_settings.display_show_fps)
{ {
text.AppendFormattedString("%.2f", System::GetFPS());
first = false; first = false;
} }
else if (g_settings.display_show_vps)
{ {
ImGui::SameLine(); text.AppendFormattedString("%s%.2f", first ? "" : " / ", System::GetVPS());
ImGui::Text("/"); first = false;
ImGui::SameLine();
} }
if (g_settings.display_show_speed)
ImGui::Text("%.2f", System::GetVPS());
}
if (g_settings.display_show_speed)
{
if (first)
{ {
text.AppendFormattedString("%s%u%%", first ? "" : " / ", static_cast<u32>(std::round(speed)));
first = false; first = false;
} }
else if (!text.IsEmpty())
{ {
ImGui::SameLine(); ImU32 color;
ImGui::Text("/"); if (speed < 95.0f)
ImGui::SameLine(); 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);
const float speed = System::GetEmulationSpeed(); DRAW_LINE(color);
const u32 rounded_speed = static_cast<u32>(std::round(speed)); }
if (speed < 90.0f)
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "%u%%", rounded_speed);
else if (speed < 110.0f)
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "%u%%", rounded_speed);
else
ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "%u%%", rounded_speed);
}
if (g_settings.display_show_resolution) if (g_settings.display_show_resolution)
{ {
const auto [effective_width, effective_height] = g_gpu->GetEffectiveDisplayResolution(); const auto [effective_width, effective_height] = g_gpu->GetEffectiveDisplayResolution();
const bool interlaced = g_gpu->IsInterlacedDisplayEnabled(); const bool interlaced = g_gpu->IsInterlacedDisplayEnabled();
ImGui::Text("%ux%u (%s)", effective_width, effective_height, interlaced ? "interlaced" : "progressive"); text.Format("%ux%u (%s)", effective_width, effective_height, interlaced ? "interlaced" : "progressive");
DRAW_LINE(IM_COL32(255, 255, 255, 255));
}
} }
ImGui::End(); #undef DRAW_LINE
} }
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));
ImGui::SetNextWindowSize(ImVec2(wrapped ? max_width : 0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity);
char buf[64];
std::snprintf(buf, sizeof(buf), "osd_%u", index++);
if (ImGui::Begin(buf, nullptr, window_flags))
{
if (wrapped)
ImGui::TextWrapped("%s", msg.text.c_str());
else
ImGui::TextUnformatted(msg.text.c_str());
position_y += ImGui::GetWindowSize().y + (4.0f * scale);
}
ImGui::End(); const ImVec2 pos(position_x, position_y);
ImGui::PopStyleVar(); const ImVec2 text_size(ImGui::CalcTextSize(msg.text.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);
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),
msg.text.c_str(), nullptr, max_width, &text_rect);
position_y += size.y + spacing;
++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…
Cancel
Save