From 5d985310895391744aee777b1b377766045e5a35 Mon Sep 17 00:00:00 2001 From: TianyunXuan Date: Tue, 22 Aug 2023 11:28:33 +0800 Subject: [PATCH] display_scale_factor error and extern static error --- examples/application/source/platform_glfw.cpp | 12 +++++++++++- imgui_extra_math.inl | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/application/source/platform_glfw.cpp b/examples/application/source/platform_glfw.cpp index 6fe71b52a..e92dabd48 100644 --- a/examples/application/source/platform_glfw.cpp +++ b/examples/application/source/platform_glfw.cpp @@ -37,6 +37,7 @@ struct PlatformGLFW final void FinishFrame() override; void Quit() override; + float GetDisplayScaleFactor(); void UpdatePixelDensity(); Application& m_Application; @@ -265,6 +266,15 @@ void PlatformGLFW::Quit() glfwPostEmptyEvent(); } +float PlatformGLFW::GetDisplayScaleFactor() { + float xscale = 1.f; + float yscale = 1.f; + auto monitor = glfwGetPrimaryMonitor(); + if (monitor) + glfwGetMonitorContentScale(monitor, &xscale, &yscale); + return 0.5f * (xscale + yscale); +} + void PlatformGLFW::UpdatePixelDensity() { float xscale, yscale; @@ -275,7 +285,7 @@ void PlatformGLFW::UpdatePixelDensity() float windowScale = scale; float framebufferScale = scale; # else - float windowScale = 1.0f; + float windowScale = GetDisplayScaleFactor(); float framebufferScale = scale; # endif diff --git a/imgui_extra_math.inl b/imgui_extra_math.inl index 51fb5951f..13cf9906c 100644 --- a/imgui_extra_math.inl +++ b/imgui_extra_math.inl @@ -34,7 +34,7 @@ inline ImVec2 operator*(const float lhs, const ImVec2& rhs) return ImVec2(lhs * rhs.x, lhs * rhs.y); } -inline static ImVec2 operator-(const ImVec2& lhs) +inline ImVec2 operator-(const ImVec2& lhs) { return ImVec2(-lhs.x, -lhs.y); }