From 72d8c68298ae975aff8314751a686a8aeca6ba91 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Wed, 10 Apr 2024 17:10:03 +0200 Subject: [PATCH] Rename BackendWindowHelper::GetDisplayFramebufferScale --- src/hello_imgui/dpi_aware.h | 5 ++++- src/hello_imgui/internal/backend_impls/abstract_runner.cpp | 2 +- .../backend_window_helper/backend_window_helper.h | 2 +- .../backend_window_helper/glfw_window_helper.cpp | 4 ++-- .../backend_impls/backend_window_helper/glfw_window_helper.h | 2 +- .../backend_impls/backend_window_helper/null_window_helper.h | 2 +- .../backend_window_helper/sdl_window_helper.cpp | 2 +- .../backend_impls/backend_window_helper/sdl_window_helper.h | 2 +- src/hello_imgui/internal/backend_impls/null_config.h | 4 +++- 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/hello_imgui/dpi_aware.h b/src/hello_imgui/dpi_aware.h index cd48d60a..5a730bd7 100644 --- a/src/hello_imgui/dpi_aware.h +++ b/src/hello_imgui/dpi_aware.h @@ -64,7 +64,10 @@ struct DpiAwareParams // factor by which font size should be multiplied at loading time to get a similar // visible size on different OSes. // The size will be equivalent to a size given for a 96 PPI screen - float DpiFontLoadingFactor() { return dpiWindowSizeFactor / fontRenderingScale;}; + float DpiFontLoadingFactor() { + float r = dpiWindowSizeFactor / fontRenderingScale; + return r; + }; }; // ---------------------------------------------------------------------------- diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp index 376b4418..196541c0 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp @@ -478,7 +478,7 @@ void AbstractRunner::SetupDpiAwareParams() } ImGui::GetIO().FontGlobalScale = params.dpiAwareParams.fontRenderingScale; - ImGui::GetIO().DisplayFramebufferScale = mBackendWindowHelper->GetWindowScaleFactor(mWindow); + ImGui::GetIO().DisplayFramebufferScale = mBackendWindowHelper->GetDisplayFramebufferScale(mWindow); } diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/backend_window_helper.h b/src/hello_imgui/internal/backend_impls/backend_window_helper/backend_window_helper.h index 4d6d8c3f..e447470c 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/backend_window_helper.h +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/backend_window_helper.h @@ -62,7 +62,7 @@ namespace HelloImGui { namespace BackendApi virtual void WaitForEventTimeout(double timeout_seconds) = 0; // Return the ratio FrameBufferSize / WindowSize - virtual ImVec2 GetWindowScaleFactor(WindowPointer window) = 0; + virtual ImVec2 GetDisplayFramebufferScale(WindowPointer window) = 0; // Return the ratio by which the window size should be scaled to account for HighDPI // (i.e. the same size given at creation create the same physical size in mm on the screen) diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp b/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp index 71f4d4d2..9f066400 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp @@ -189,7 +189,7 @@ namespace HelloImGui { namespace BackendApi glfwWaitEventsTimeout(timeout_seconds); } - ImVec2 GlfwWindowHelper::GetWindowScaleFactor(HelloImGui::BackendApi::WindowPointer window) + ImVec2 GlfwWindowHelper::GetDisplayFramebufferScale(HelloImGui::BackendApi::WindowPointer window) { float x_scale, y_scale; glfwGetWindowContentScale((GLFWwindow *) window, &x_scale, &y_scale); @@ -201,7 +201,7 @@ namespace HelloImGui { namespace BackendApi #ifdef __APPLE__ return 1.f; #else - ImVec2 scale = GetWindowScaleFactor(window); + ImVec2 scale = GetDisplayFramebufferScale(window); return scale.x; #endif } diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.h b/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.h index a659386d..4d1f65b8 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.h +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.h @@ -29,7 +29,7 @@ namespace HelloImGui { namespace BackendApi void WaitForEventTimeout(double timeout_seconds) override; - ImVec2 GetWindowScaleFactor(WindowPointer window) override; + ImVec2 GetDisplayFramebufferScale(WindowPointer window) override; float GetWindowSizeDpiScaleFactor(WindowPointer window) override; void HideWindow(WindowPointer window) override; diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/null_window_helper.h b/src/hello_imgui/internal/backend_impls/backend_window_helper/null_window_helper.h index fac9bc92..9138d171 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/null_window_helper.h +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/null_window_helper.h @@ -35,7 +35,7 @@ namespace HelloImGui { namespace BackendApi std::this_thread::sleep_for(std::chrono::milliseconds((int)(timeout_seconds * 1000))); } - ImVec2 GetWindowScaleFactor(WindowPointer window) override { return NullConfig::GetWindowScaleFactor(); } + ImVec2 GetDisplayFramebufferScale(WindowPointer window) override { return NullConfig::GetDisplayFramebufferScale(); } float GetWindowSizeDpiScaleFactor(WindowPointer window) override { return NullConfig::GetWindowSizeDpiScaleFactor(); } void HideWindow(WindowPointer window) override {} diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.cpp b/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.cpp index 3bb13942..df8bc5af 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.cpp +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.cpp @@ -200,7 +200,7 @@ namespace HelloImGui { namespace BackendApi SDL_WaitEventTimeout(NULL, timeout_ms); } - ImVec2 SdlWindowHelper::GetWindowScaleFactor(WindowPointer window) + ImVec2 SdlWindowHelper::GetDisplayFramebufferScale(WindowPointer window) { int win_w, win_h, fb_w, fb_h; SDL_GetWindowSize((SDL_Window *) window, &win_w, &win_h); diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.h b/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.h index 0546bd84..1381ba79 100644 --- a/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.h +++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/sdl_window_helper.h @@ -38,7 +38,7 @@ namespace HelloImGui { namespace BackendApi void WaitForEventTimeout(double timeout_seconds) override; - ImVec2 GetWindowScaleFactor(WindowPointer window) override; + ImVec2 GetDisplayFramebufferScale(WindowPointer window) override; float GetWindowSizeDpiScaleFactor(WindowPointer window) override; void HideWindow(WindowPointer window) override; diff --git a/src/hello_imgui/internal/backend_impls/null_config.h b/src/hello_imgui/internal/backend_impls/null_config.h index ff5bf905..1d91b4b5 100644 --- a/src/hello_imgui/internal/backend_impls/null_config.h +++ b/src/hello_imgui/internal/backend_impls/null_config.h @@ -21,7 +21,9 @@ namespace NullConfig return {GetScreenBounds()}; } - ImVec2 GetWindowScaleFactor() { return {1.f, 1.f}; } + ImVec2 GetDisplayFramebufferScale() { + return {1.f, 1.f}; + } float GetWindowSizeDpiScaleFactor() { return 1.f; } }