From 28fdc5537f15dd894398562c0f717249792d9666 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 22 Feb 2021 02:58:25 +1000 Subject: [PATCH] FullscreenUI: Draw quick menu at screen bounds, not scaled bounds --- src/duckstation-nogui/nogui_host_interface.cpp | 7 ------- src/frontend-common/fullscreen_ui.cpp | 17 ++++++++++------- src/frontend-common/imgui_fullscreen.cpp | 13 +++++++++++-- src/frontend-common/imgui_fullscreen.h | 10 +++++++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/duckstation-nogui/nogui_host_interface.cpp b/src/duckstation-nogui/nogui_host_interface.cpp index 045b8f1b9..a04a26dbb 100644 --- a/src/duckstation-nogui/nogui_host_interface.cpp +++ b/src/duckstation-nogui/nogui_host_interface.cpp @@ -86,13 +86,6 @@ bool NoGUIHostInterface::CreateDisplay() return false; } - // imgui init from window - ImGui::GetIO().DisplayFramebufferScale.x = wi->surface_scale; - ImGui::GetIO().DisplayFramebufferScale.y = wi->surface_scale; - ImGui::GetStyle() = ImGuiStyle(); - ImGui::GetStyle().ScaleAllSizes(wi->surface_scale); - ImGui::StyleColorsDarker(); - Assert(!m_display); switch (g_settings.gpu_renderer) { diff --git a/src/frontend-common/fullscreen_ui.cpp b/src/frontend-common/fullscreen_ui.cpp index 67245cb3b..becf8bac7 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -1992,7 +1992,8 @@ void DrawSettingsWindow() void DrawQuickMenu(MainWindowType type) { ImDrawList* dl = ImGui::GetBackgroundDrawList(); - dl->AddRectFilled(ImVec2(0.0f, 0.0f), ImGui::GetIO().DisplaySize, IM_COL32(0x21, 0x21, 0x21, 200)); + const ImVec2 display_size(ImGui::GetIO().DisplaySize); + dl->AddRectFilled(ImVec2(0.0f, 0.0f), display_size, IM_COL32(0x21, 0x21, 0x21, 200)); // title info { @@ -2009,21 +2010,23 @@ void DrawQuickMenu(MainWindowType type) const ImVec2 subtitle_size( g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits::max(), -1.0f, subtitle)); - const ImVec2 title_pos(LayoutScale(LAYOUT_SCREEN_WIDTH - 20.0f - 50.0f - 20.0f) - title_size.x, - LayoutScale(LAYOUT_SCREEN_HEIGHT - 20.0f - 50.0f)); - const ImVec2 subtitle_pos(LayoutScale(LAYOUT_SCREEN_WIDTH - 20.0f - 50.0f - 20.0f) - subtitle_size.x, + const ImVec2 title_pos(display_size.x - LayoutScale(20.0f + 50.0f + 20.0f) - title_size.x, + display_size.y - LayoutScale(20.0f + 50.0f)); + const ImVec2 subtitle_pos(display_size.x - LayoutScale(20.0f + 50.0f + 20.0f) - subtitle_size.x, title_pos.y + g_large_font->FontSize + LayoutScale(4.0f)); dl->AddText(g_large_font, g_large_font->FontSize, title_pos, IM_COL32(255, 255, 255, 255), title.c_str()); dl->AddText(g_medium_font, g_medium_font->FontSize, subtitle_pos, IM_COL32(255, 255, 255, 255), subtitle); - const ImVec2 image_min(LayoutScale(LAYOUT_SCREEN_WIDTH - 20.0f - 50.0f, LAYOUT_SCREEN_HEIGHT - 20.0f - 50.0f)); + const ImVec2 image_min(display_size - LayoutScale(20.0f + 50.0f, 20.0f + 50.0f)); const ImVec2 image_max(image_min + LayoutScale(50.0f, 50.0f)); dl->AddImage(GetCoverForCurrentGame()->GetHandle(), image_min, image_max); } - if (BeginFullscreenWindow(0.0f, 0.0f, 500.0f, LAYOUT_SCREEN_HEIGHT, "pause_menu", ImVec4(0.0f, 0.0f, 0.0f, 0.0f), - 0.0f, 10.0f, ImGuiWindowFlags_NoBackground)) + const ImVec2 window_size(LayoutScale(500.0f, LAYOUT_SCREEN_HEIGHT)); + const ImVec2 window_pos(0.0f, display_size.y - window_size.y); + if (BeginFullscreenWindow(window_pos, window_size, "pause_menu", ImVec4(0.0f, 0.0f, 0.0f, 0.0f), 0.0f, 10.0f, + ImGuiWindowFlags_NoBackground)) { BeginMenuButtons(11, 1.0f, ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING, diff --git a/src/frontend-common/imgui_fullscreen.cpp b/src/frontend-common/imgui_fullscreen.cpp index 8175dabdc..67726ba44 100644 --- a/src/frontend-common/imgui_fullscreen.cpp +++ b/src/frontend-common/imgui_fullscreen.cpp @@ -291,8 +291,17 @@ bool BeginFullscreenWindow(float left, float top, float width, float height, con if (top < 0.0f) top = (LAYOUT_SCREEN_HEIGHT - height) * -top; - ImGui::SetNextWindowSize(LayoutScale(ImVec2(width, height))); - ImGui::SetNextWindowPos(ImVec2(LayoutScale(left) + g_layout_padding_left, LayoutScale(top) + g_layout_padding_top)); + const ImVec2 pos(ImVec2(LayoutScale(left) + g_layout_padding_left, LayoutScale(top) + g_layout_padding_top)); + const ImVec2 size(LayoutScale(ImVec2(width, height))); + return BeginFullscreenWindow(pos, size, name, background, rounding, padding, flags); +} + +bool BeginFullscreenWindow(const ImVec2& position, const ImVec2& size, const char* name, + const ImVec4& background /* = HEX_TO_IMVEC4(0x212121, 0xFF) */, float rounding /*= 0.0f*/, + float padding /*= 0.0f*/, ImGuiWindowFlags flags /*= 0*/) +{ + ImGui::SetNextWindowPos(position); + ImGui::SetNextWindowSize(size); ImGui::PushStyleColor(ImGuiCol_WindowBg, background); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(padding, padding)); diff --git a/src/frontend-common/imgui_fullscreen.h b/src/frontend-common/imgui_fullscreen.h index 3fdff40bb..27f22de53 100644 --- a/src/frontend-common/imgui_fullscreen.h +++ b/src/frontend-common/imgui_fullscreen.h @@ -10,7 +10,7 @@ namespace ImGuiFullscreen { ImVec4(static_cast((hex >> 16) & 0xFFu) / 255.0f, static_cast((hex >> 8) & 0xFFu) / 255.0f, \ static_cast(hex & 0xFFu) / 255.0f, static_cast(alpha) / 255.0f) -using ResolveTextureHandleCallback = ImTextureID(*)(const std::string& path); +using ResolveTextureHandleCallback = ImTextureID (*)(const std::string& path); static constexpr float LAYOUT_SCREEN_WIDTH = 1280.0f; static constexpr float LAYOUT_SCREEN_HEIGHT = 720.0f; @@ -71,6 +71,11 @@ static ALWAYS_INLINE ImVec2 LayoutScale(float x, float y) return ImVec2(x * g_layout_scale, y * g_layout_scale); } +static ALWAYS_INLINE ImVec2 LayoutScaleAndOffset(float x, float y) +{ + return ImVec2(g_layout_padding_left + x * g_layout_scale, g_layout_padding_top + y * g_layout_scale); +} + static ALWAYS_INLINE ImVec4 UIPrimaryColor() { return HEX_TO_IMVEC4(0x212121, 0xff); @@ -161,6 +166,9 @@ void EndFullscreenColumnWindow(); bool BeginFullscreenWindow(float left, float top, float width, float height, const char* name, const ImVec4& background = HEX_TO_IMVEC4(0x212121, 0xFF), float rounding = 0.0f, float padding = 0.0f, ImGuiWindowFlags flags = 0); +bool BeginFullscreenWindow(const ImVec2& position, const ImVec2& size, const char* name, + const ImVec4& background = HEX_TO_IMVEC4(0x212121, 0xFF), float rounding = 0.0f, + float padding = 0.0f, ImGuiWindowFlags flags = 0); void EndFullscreenWindow(); void BeginMenuButtons(u32 num_items = 0, float y_align = 0.0f, float x_padding = LAYOUT_MENU_BUTTON_X_PADDING,