GS: Fix OSD scaling on hidpi displays

This commit is contained in:
TellowKrinkle 2022-01-06 19:18:47 -06:00 committed by tellowkrinkle
parent 50afd83bc6
commit 49b1a496b1
4 changed files with 13 additions and 11 deletions

View File

@ -66,7 +66,7 @@ bool ImGuiManager::Initialize()
s_global_scale = std::max(1.0f, display->GetWindowScale() * static_cast<float>(EmuConfig.GS.OsdScale / 100.0));
ImGui::GetIO().DisplayFramebufferScale = ImVec2(display->GetWindowScale(), display->GetWindowScale());
ImGui::GetIO().DisplayFramebufferScale = ImVec2(1, 1); // We already scale things ourselves, this would double-apply scaling
ImGui::GetIO().DisplaySize.x = static_cast<float>(display->GetWindowWidth());
ImGui::GetIO().DisplaySize.y = static_cast<float>(display->GetWindowHeight());
ImGui::GetStyle() = ImGuiStyle();
@ -111,18 +111,18 @@ void ImGuiManager::WindowResized()
const u32 new_width = display ? display->GetWindowWidth() : 0;
const u32 new_height = display ? display->GetWindowHeight() : 0;
const float new_scale = (display ? display->GetWindowScale() : 1.0f);
ImGui::GetIO().DisplaySize = ImVec2(static_cast<float>(new_width), static_cast<float>(new_height));
ImGui::GetIO().DisplayFramebufferScale = ImVec2(new_scale, new_scale);
UpdateScale();
}
void ImGuiManager::UpdateScale()
{
const float scale =
std::max(ImGui::GetIO().DisplayFramebufferScale.x * static_cast<float>(EmuConfig.GS.OsdScale / 100.0), 1.0f);
HostDisplay* display = Host::GetHostDisplay();
const float window_scale = display ? display->GetWindowScale() : 1.0f;
const float scale = std::max(window_scale * static_cast<float>(EmuConfig.GS.OsdScale / 100.0), 1.0f);
if (scale == s_global_scale)
return;
@ -131,8 +131,6 @@ void ImGuiManager::UpdateScale()
s_global_scale = scale;
HostDisplay* display = Host::GetHostDisplay();
ImGui::GetStyle() = ImGuiStyle();
ImGui::GetStyle().WindowMinSize = ImVec2(1.0f, 1.0f);
SetImGuiStyle();

View File

@ -178,12 +178,14 @@ static std::atomic_bool s_gs_window_resized{false};
static std::mutex s_gs_window_resized_lock;
static int s_new_gs_window_width = 0;
static int s_new_gs_window_height = 0;
static float s_new_gs_window_scale = 1;
void Host::GSWindowResized(int width, int height)
void Host::GSWindowResized(int width, int height, float scale)
{
std::unique_lock lock(s_gs_window_resized_lock);
s_new_gs_window_width = width;
s_new_gs_window_height = height;
s_new_gs_window_scale = scale;
s_gs_window_resized.store(true);
}
@ -193,17 +195,19 @@ void Host::CheckForGSWindowResize()
return;
int width, height;
float scale;
{
std::unique_lock lock(s_gs_window_resized_lock);
width = s_new_gs_window_width;
height = s_new_gs_window_height;
scale = s_new_gs_window_scale;
s_gs_window_resized.store(false);
}
if (!s_host_display)
return;
s_host_display->ResizeRenderWindow(width, height, s_host_display ? s_host_display->GetWindowScale() : 1.0f);
s_host_display->ResizeRenderWindow(width, height, scale);
ImGuiManager::WindowResized();
}

View File

@ -4,7 +4,7 @@
namespace Host
{
// UI thread
void GSWindowResized(int width, int height);
void GSWindowResized(int width, int height, float scale);
// MTGS thread
void CheckForGSWindowResize();

View File

@ -384,7 +384,7 @@ void GSPanel::OnResize(wxEvent& event)
g_gs_window_info.surface_height = height;
g_gs_window_info.surface_scale = scale;
Host::GSWindowResized(width, height);
Host::GSWindowResized(width, height, scale);
}
void GSPanel::OnMouseEvent( wxMouseEvent& evt )