From a7408143546010a753a57e018932b8d689020f54 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 24 Nov 2024 18:59:23 -0500 Subject: [PATCH] Fix Bug When Resizing ImGui --- launcher/src/ui/frame.cpp | 1 + libreborn/src/util/glfw.cpp | 50 ++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/launcher/src/ui/frame.cpp b/launcher/src/ui/frame.cpp index 61cab743f7..e53b85e0df 100644 --- a/launcher/src/ui/frame.cpp +++ b/launcher/src/ui/frame.cpp @@ -90,6 +90,7 @@ void Frame::setup_style(const float scale) { font_cfg.FontDataOwnedByAtlas = false; io.Fonts->AddFontFromMemoryTTF(Roboto_Medium_ttf, int(Roboto_Medium_ttf_len), std::floor(20.0f * scale), &font_cfg); monospace = io.Fonts->AddFontFromMemoryTTF(Cousine_Regular_ttf, int(Cousine_Regular_ttf_len), std::floor(18.0f * scale), &font_cfg); + ImGui_ImplOpenGL2_DestroyFontsTexture(); // Style ImGuiStyle &style = ImGui::GetStyle(); style = ImGuiStyle(); diff --git a/libreborn/src/util/glfw.cpp b/libreborn/src/util/glfw.cpp index babd1a47d8..44ac596b8b 100644 --- a/libreborn/src/util/glfw.cpp +++ b/libreborn/src/util/glfw.cpp @@ -46,23 +46,37 @@ void cleanup_glfw(GLFWwindow *window) { } // Framebuffer Scaling -void get_glfw_scale(GLFWwindow *window, float *x_scale, float *y_scale) { - // Get Window Size - int window_width; - int window_height; - glfwGetWindowSize(window, &window_width, &window_height); - if (window_width <= 0 || window_height <= 0) { - return; - } - // Get Framebuffer Size - int framebuffer_width; - int framebuffer_height; - glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); - // Calculate Scale - if (x_scale) { - *x_scale = float(framebuffer_width) / float(window_width); - } - if (y_scale) { - *y_scale = float(framebuffer_height) / float(window_height); +void get_glfw_scale(GLFWwindow *window, float *x_scale_ptr, float *y_scale_ptr) { + // Output + float x_scale; + float y_scale; + + // Default + x_scale = y_scale = 1.0f; + + // Detect Platform + if (glfwGetPlatform() == GLFW_PLATFORM_X11) { + // X11 Has No Scaling + } else { + // Get Window Size + int window_width; + int window_height; + glfwGetWindowSize(window, &window_width, &window_height); + // Get Framebuffer Size + int framebuffer_width; + int framebuffer_height; + glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); + + // Calculate + if (window_width > 0 && window_height > 0) { + x_scale = float(framebuffer_width) / float(window_width); + y_scale = float(framebuffer_height) / float(window_height); + } } + + // Return +#define ret(x) if (x##_ptr) *x##_ptr = x + ret(x_scale); + ret(y_scale); +#undef ret } \ No newline at end of file