FullscreenUI: Fix double display of stats with debug menu

This commit is contained in:
Connor McLaughlin 2021-04-03 02:37:58 +10:00
parent 924756860e
commit 6c59e769ed
3 changed files with 26 additions and 18 deletions

View file

@ -299,6 +299,7 @@ void Render()
if (System::IsValid())
{
if (!s_debug_menu_enabled)
DrawStatsOverlay();
if (!IsCheevosHardcoreModeActive())
@ -3033,7 +3034,7 @@ void DrawStatsOverlay()
const float margin = LayoutScale(10.0f);
const float shadow_offset = DPIScale(1.0f);
float position_y = margin;
float position_y = ImGuiFullscreen::g_menu_bar_size + margin;
ImDrawList* dl = ImGui::GetBackgroundDrawList();
TinyString text;
ImVec2 text_size;
@ -3119,7 +3120,7 @@ void DrawOSDMessages()
const float margin = LayoutScale(10.0f);
const float padding = LayoutScale(10.0f);
float position_x = margin;
float position_y = margin + static_cast<float>(s_host_interface->GetDisplay()->GetDisplayTopMargin());
float position_y = margin + ImGuiFullscreen::g_menu_bar_size;
s_host_interface->EnumerateOSDMessages(
[max_width, spacing, padding, &position_x, &position_y](const std::string& message, float time_remaining) -> bool {
@ -3371,21 +3372,27 @@ void DrawDebugStats()
if (!System::IsShutdown())
{
const float framebuffer_scale = ImGui::GetIO().DisplayFramebufferScale.x;
const float framebuffer_width = ImGui::GetIO().DisplaySize.x;
if (System::IsPaused())
{
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - (50.0f * framebuffer_scale));
ImGui::SetCursorPosX(framebuffer_width - (50.0f * framebuffer_scale));
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "Paused");
}
else
{
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - (420.0f * framebuffer_scale));
const auto [display_width, display_height] = g_gpu->GetEffectiveDisplayResolution();
ImGui::SetCursorPosX(framebuffer_width - (580.0f * framebuffer_scale));
ImGui::Text("%ux%u (%s)", display_width, display_height,
g_gpu->IsInterlacedDisplayEnabled() ? "interlaced" : "progressive");
ImGui::SetCursorPosX(framebuffer_width - (420.0f * framebuffer_scale));
ImGui::Text("Average: %.2fms", System::GetAverageFrameTime());
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - (310.0f * framebuffer_scale));
ImGui::SetCursorPosX(framebuffer_width - (310.0f * framebuffer_scale));
ImGui::Text("Worst: %.2fms", System::GetWorstFrameTime());
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - (210.0f * framebuffer_scale));
ImGui::SetCursorPosX(framebuffer_width - (210.0f * framebuffer_scale));
const float speed = System::GetEmulationSpeed();
const u32 rounded_speed = static_cast<u32>(std::round(speed));
@ -3396,10 +3403,10 @@ void DrawDebugStats()
else
ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "%u%%", rounded_speed);
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - (165.0f * framebuffer_scale));
ImGui::SetCursorPosX(framebuffer_width - (165.0f * framebuffer_scale));
ImGui::Text("FPS: %.2f", System::GetFPS());
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - (80.0f * framebuffer_scale));
ImGui::SetCursorPosX(framebuffer_width - (80.0f * framebuffer_scale));
ImGui::Text("VPS: %.2f", System::GetVPS());
}
}

View file

@ -29,8 +29,8 @@ ImFont* g_icon_font = nullptr;
float g_layout_scale = 1.0f;
float g_layout_padding_left = 0.0f;
float g_layout_padding_top = 0.0f;
float g_menu_bar_size = 0.0f;
static float s_menu_bar_size;
static std::string s_font_filename;
static std::string s_icon_font_filename;
static std::vector<u8> s_icon_font_data;
@ -81,10 +81,10 @@ void SetFontGlyphRanges(const ImWchar* glyph_ranges)
void SetMenuBarSize(float size)
{
if (s_menu_bar_size == size)
if (g_menu_bar_size == size)
return;
s_menu_bar_size = size;
g_menu_bar_size = size;
}
void SetResolveTextureFunction(ResolveTextureHandleCallback callback)
@ -186,7 +186,7 @@ bool UpdateLayoutScale()
const ImGuiIO& io = ImGui::GetIO();
const float screen_width = io.DisplaySize.x;
const float screen_height = io.DisplaySize.y - s_menu_bar_size;
const float screen_height = io.DisplaySize.y - g_menu_bar_size;
const float screen_ratio = screen_width / screen_height;
const float old_scale = g_layout_scale;
@ -194,14 +194,14 @@ bool UpdateLayoutScale()
{
// screen is wider, use height, pad width
g_layout_scale = screen_height / LAYOUT_SCREEN_HEIGHT;
g_layout_padding_top = s_menu_bar_size;
g_layout_padding_top = g_menu_bar_size;
g_layout_padding_left = (screen_width - (LAYOUT_SCREEN_WIDTH * g_layout_scale)) / 2.0f;
}
else
{
// screen is taller, use width, pad height
g_layout_scale = screen_width / LAYOUT_SCREEN_WIDTH;
g_layout_padding_top = (screen_height - (LAYOUT_SCREEN_HEIGHT * g_layout_scale)) / 2.0f + s_menu_bar_size;
g_layout_padding_top = (screen_height - (LAYOUT_SCREEN_HEIGHT * g_layout_scale)) / 2.0f + g_menu_bar_size;
g_layout_padding_left = 0.0f;
}
@ -244,8 +244,8 @@ bool IsCancelButtonPressed()
bool BeginFullscreenColumns(const char* title)
{
ImGui::SetNextWindowPos(ImVec2(g_layout_padding_left, s_menu_bar_size));
ImGui::SetNextWindowSize(ImVec2(LayoutScale(LAYOUT_SCREEN_WIDTH), ImGui::GetIO().DisplaySize.y - s_menu_bar_size));
ImGui::SetNextWindowPos(ImVec2(g_layout_padding_left, g_menu_bar_size));
ImGui::SetNextWindowSize(ImVec2(LayoutScale(LAYOUT_SCREEN_WIDTH), ImGui::GetIO().DisplaySize.y - g_menu_bar_size));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
@ -276,7 +276,7 @@ void EndFullscreenColumns()
bool BeginFullscreenColumnWindow(float start, float end, const char* name, const ImVec4& background)
{
const ImVec2 pos(LayoutScale(start), 0.0f);
const ImVec2 size(LayoutScale(end - start), ImGui::GetIO().DisplaySize.y - s_menu_bar_size);
const ImVec2 size(LayoutScale(end - start), ImGui::GetIO().DisplaySize.y - g_menu_bar_size);
ImGui::PushStyleColor(ImGuiCol_ChildBg, background);

View file

@ -29,6 +29,7 @@ extern ImFont* g_large_font;
extern float g_layout_scale;
extern float g_layout_padding_left;
extern float g_layout_padding_top;
extern float g_menu_bar_size;
static ALWAYS_INLINE float DPIScale(float v)
{