diff --git a/src/hello_imgui/doc_api.md b/src/hello_imgui/doc_api.md index c48080e6..fdebc670 100644 --- a/src/hello_imgui/doc_api.md +++ b/src/hello_imgui/doc_api.md @@ -458,7 +458,6 @@ Under windows, it will always be (1,1). Under macOS / linux, it will reflect the It will typically be (2,2) on a macOS retina screen. Notes: -- As a convenience, `ImGui::GetIO().DisplayFramebufferScale` is mirrored in `HelloImGui::DpiAwareParams::roDisplayFramebufferScale`. - You cannot change DisplayFramebufferScale manually, it will be reset at each new frame, by asking the platform backend. diff --git a/src/hello_imgui/doc_params.md b/src/hello_imgui/doc_params.md index e92d870c..1298d1f3 100644 --- a/src/hello_imgui/doc_params.md +++ b/src/hello_imgui/doc_params.md @@ -886,8 +886,9 @@ struct DpiAwareParams { // `dpiWindowSizeFactor` // factor by which window size should be multiplied to get a similar - // visible size on different OSes. This affects the size of the window, - // but *not* the size of widgets and text. + // physical size on different OSes (as if they were all displayed on a 96 PPI screen). + // This affects the size of native app windows, + // but *not* imgui Windows, and *not* the size of widgets and text. // In a standard environment (i.e. outside of Hello ImGui), an application with a size of 960x480 pixels, // may have a physical size (in mm or inches) that varies depending on the screen DPI, and the OS. // @@ -903,36 +904,23 @@ struct DpiAwareParams // `fontRenderingScale` // factor (that is either 1 or < 1.) by which fonts glyphs should be scaled at rendering time. - // On macOS retina screens, it will be 0.5, since macOS APIs hide the real resolution of the screen. - // Changing this value will *not* change the visible font size on the screen, however it will - // affect the size of the loaded glyphs. - // For example, if fontRenderingScale=0.5 (which is the default on a macOS retina screen), - // a font size of 16 will be loaded as if it was 32, and will be rendered at half size. - // This leads to a better rendering quality on some platforms. + // On macOS retina screens, it will be 0.5, since macOS APIs hide the real resolution of the screen. + // Changing this value will *not* change the visible font size on the screen, however it will + // affect the size of the loaded glyphs. + // For example, if fontRenderingScale=0.5 (which is the default on a macOS retina screen), + // a font size of 16 will be loaded as if it was 32, and will be rendered at half size. + // This leads to a better rendering quality on some platforms. + // (This parameter will be used to set ImGui::GetIO().FontGlobalScale at startup) float fontRenderingScale = 0.0f; // `dpiFontLoadingFactor` - // 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() { + // 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() const { float r = dpiWindowSizeFactor / fontRenderingScale; return r; }; - - // `roDisplayFramebufferScale` - // When rendering, the internal frame buffer size might be bigger than the - // size (in "virtual screen coordinate" pixels) of the window. - // For example: - // - on macOS retina screens, the frame buffer size will be twice the window size - // (and roDisplayFramebufferScale will be 2, 2) - // - on Windows, the frame buffer size will be the same as the window size. - // (since virtual screen coordinate pixels are the same as physical screen pixels on Windows) - // - // This is an output-only value: it will be set by the platform backend - // after it was initialized (any change you make to it at startup will not be used) - // It mirrors the value inside ImGui::GetIO().DisplayFramebufferScale. - ImVec2 roDisplayFramebufferScale = ImVec2(0.f, 0.f); }; // ---------------------------------------------------------------------------- diff --git a/src/hello_imgui/dpi_aware.h b/src/hello_imgui/dpi_aware.h index fccf5038..99879ff4 100644 --- a/src/hello_imgui/dpi_aware.h +++ b/src/hello_imgui/dpi_aware.h @@ -76,20 +76,6 @@ struct DpiAwareParams float r = dpiWindowSizeFactor / fontRenderingScale; return r; }; - - // `roDisplayFramebufferScale` - // When rendering, the internal frame buffer size might be bigger than the - // size (in "virtual screen coordinate" pixels) of the window. - // For example: - // - on macOS retina screens, the frame buffer size will be twice the window size - // (and roDisplayFramebufferScale will be 2, 2) - // - on Windows, the frame buffer size will be the same as the window size. - // (since virtual screen coordinate pixels are the same as physical screen pixels on Windows) - // - // This is an output-only value: it will be set by the platform backend - // after it was initialized (any change you make to it at startup will not be used) - // It mirrors the value inside ImGui::GetIO().DisplayFramebufferScale. - ImVec2 roDisplayFramebufferScale = ImVec2(0.f, 0.f); }; // ---------------------------------------------------------------------------- @@ -203,7 +189,6 @@ Under windows, it will always be (1,1). Under macOS / linux, it will reflect the It will typically be (2,2) on a macOS retina screen. Notes: -- As a convenience, `ImGui::GetIO().DisplayFramebufferScale` is mirrored in `HelloImGui::DpiAwareParams::roDisplayFramebufferScale`. - You cannot change DisplayFramebufferScale manually, it will be reset at each new frame, by asking the platform backend. diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp index cd4b80a3..31453908 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp @@ -451,19 +451,18 @@ void _CheckDpiAwareParamsChanges(const std::string& msg) printf("dpiAwareParams: fontRenderingScale=%f\n", dpiAwareParams.fontRenderingScale); printf(" ImGui FontGlobalScale: %f\n", ImGui::GetIO().FontGlobalScale); printf("dpiAwareParams: DpiFontLoadingFactor()=%f\n", dpiAwareParams.DpiFontLoadingFactor()); - printf("dpiAwareParams: roDisplayFramebufferScale=%f, %f\n", dpiAwareParams.roDisplayFramebufferScale.x, dpiAwareParams.roDisplayFramebufferScale.y); + printf("dpiAwareParams: io.DisplayFramebufferScale=%f, %f\n", io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); auto fbs = ImGui::GetIO().DisplayFramebufferScale; printf(" ImGui DisplayFramebufferScale: %f,%f\n", fbs.x, fbs.y); printf("-------------------------------------------------------------\n"); } - if (dpiAwareParams.fontRenderingScale != io.FontGlobalScale) - { - printf("Warning: fontRenderingScale != ImGui::GetIO().FontGlobalScale\n"); - } - if (dpiAwareParams.roDisplayFramebufferScale.x != io.DisplayFramebufferScale.x) + bool didFontGlobalScaleChange = dpiAwareParams.fontRenderingScale != io.FontGlobalScale; + + if (didFontGlobalScaleChange) { - printf("Warning: roDisplayFramebufferScale != ImGui::GetIO().DisplayFramebufferScale\n"); + printf("Warning: didDpiAwareParamsChange=:true\n"); + dpiAwareParams.fontRenderingScale = io.FontGlobalScale; } } @@ -517,19 +516,6 @@ void AbstractRunner::SetupDpiAwareParams() } ImGui::GetIO().FontGlobalScale = params.dpiAwareParams.fontRenderingScale; - // - // DisplayFramebufferScale - // - ImVec2 displayFramebufferScale = mBackendWindowHelper->GetDisplayFramebufferScale(mWindow); - // Note: ImGui_ImplGlfw_NewFrame, ImGui_ImplSDL2_NewFrame, ... will also set ImGui::GetIO().DisplayFramebufferScale - // (using their own backend abstraction). - // There is a slight chance of discrepancy here, However, GetDisplayFramebufferScale() and DearImGui - // do get the same results for SDL and GLFW under Windows Linux macOS, Android, iOS. - auto& io = ImGui::GetIO(); - io.DisplayFramebufferScale = displayFramebufferScale; - // dpiAwareParams.roDisplayFramebufferScale is an output-only value (for information only) - params.dpiAwareParams.roDisplayFramebufferScale = displayFramebufferScale; - _CheckDpiAwareParamsChanges("Setup End"); } 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 e447470c..bbec66c9 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 @@ -61,8 +61,8 @@ namespace HelloImGui { namespace BackendApi virtual void WaitForEventTimeout(double timeout_seconds) = 0; - // Return the ratio FrameBufferSize / WindowSize - virtual ImVec2 GetDisplayFramebufferScale(WindowPointer window) = 0; + // (ImGui backends handle this by themselves) + //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 b04d7893..a6d496a3 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,11 +189,10 @@ namespace HelloImGui { namespace BackendApi glfwWaitEventsTimeout(timeout_seconds); } - ImVec2 GlfwWindowHelper::GetDisplayFramebufferScale(HelloImGui::BackendApi::WindowPointer window) + ImVec2 _GetWindowContentScale(HelloImGui::BackendApi::WindowPointer window) { float x_scale, y_scale; glfwGetWindowContentScale((GLFWwindow *) window, &x_scale, &y_scale); - printf("GlfwWindowHelper::GetDisplayFramebufferScale: %f, %f\n", x_scale, y_scale); return ImVec2(x_scale, y_scale); } @@ -202,7 +201,7 @@ namespace HelloImGui { namespace BackendApi #ifdef __APPLE__ return 1.f; #else - ImVec2 scale = GetDisplayFramebufferScale(window); + ImVec2 scale = _GetWindowContentScale(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 4d1f65b8..f7f35fa3 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,6 @@ namespace HelloImGui { namespace BackendApi void WaitForEventTimeout(double timeout_seconds) 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 9138d171..88e45266 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,6 @@ namespace HelloImGui { namespace BackendApi std::this_thread::sleep_for(std::chrono::milliseconds((int)(timeout_seconds * 1000))); } - 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 df8bc5af..b5858301 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,15 +200,6 @@ namespace HelloImGui { namespace BackendApi SDL_WaitEventTimeout(NULL, timeout_ms); } - ImVec2 SdlWindowHelper::GetDisplayFramebufferScale(WindowPointer window) - { - int win_w, win_h, fb_w, fb_h; - SDL_GetWindowSize((SDL_Window *) window, &win_w, &win_h); - SDL_GL_GetDrawableSize((SDL_Window *) window, &fb_w, &fb_h); - return ImVec2((float)fb_w / win_w, (float)fb_h / win_h); - } - - float SdlWindowHelper::GetWindowSizeDpiScaleFactor(WindowPointer window) { #if TARGET_OS_MAC // is true for any software platform that's derived from macOS, which includes iOS, watchOS, and tvOS 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 1381ba79..3633e97b 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,6 @@ namespace HelloImGui { namespace BackendApi void WaitForEventTimeout(double timeout_seconds) 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 1d91b4b5..87a99862 100644 --- a/src/hello_imgui/internal/backend_impls/null_config.h +++ b/src/hello_imgui/internal/backend_impls/null_config.h @@ -21,9 +21,6 @@ namespace NullConfig return {GetScreenBounds()}; } - ImVec2 GetDisplayFramebufferScale() { - return {1.f, 1.f}; - } float GetWindowSizeDpiScaleFactor() { return 1.f; } }