From 4c0fa27846a06c021c7f3840c6ec25ba7748714f Mon Sep 17 00:00:00 2001 From: Synth Morxemplum Date: Thu, 5 Dec 2024 12:07:25 -0700 Subject: [PATCH] GLFW: Make relative scaling a double instead of an integer --- src/window_glfw.cpp | 8 ++++---- src/window_glfw.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/window_glfw.cpp b/src/window_glfw.cpp index c180cb4..e01d4c4 100644 --- a/src/window_glfw.cpp +++ b/src/window_glfw.cpp @@ -88,14 +88,14 @@ void GLFWGameWindow::setRelativeScale() { int wx, wy; glfwGetWindowSize(window, &wx, &wy); - relativeScale = (int) floor(((fx / wx) + (fy / wy)) / 2); + relativeScale = (((double) fx / (double) wx) + ((double) fy / (double) wy)) / 2.0; // Update window size to match content size mismatch width = fx; height = fy; resized = true; } -int GLFWGameWindow::getRelativeScale() const { +double GLFWGameWindow::getRelativeScale() const { return relativeScale; } @@ -134,8 +134,8 @@ void GLFWGameWindow::pollEvents() { if(requestFullscreen) { glfwGetWindowPos(window, &windowedX, &windowedY); // convert pixels to window coordinates getRelativeScale() is 2 on macOS retina screens - windowedWidth = width / getRelativeScale(); - windowedHeight = height / getRelativeScale(); + windowedWidth = (int) floor(width / getRelativeScale()); + windowedHeight = (int) floor(height / getRelativeScale()); GLFWmonitor* monitor = glfwGetPrimaryMonitor(); int nModes = 0; auto modes = glfwGetVideoModes(monitor, &nModes); diff --git a/src/window_glfw.h b/src/window_glfw.h index 4447a80..73b278c 100644 --- a/src/window_glfw.h +++ b/src/window_glfw.h @@ -18,7 +18,7 @@ class GLFWGameWindow : public GameWindow { int width = -1, height = -1; // width and height in window coordinates = pixels / relativeScale int windowedWidth = -1, windowedHeight = -1; - int relativeScale; + double relativeScale; bool resized = false; bool focused = true; bool warnedButtons = false; @@ -59,7 +59,7 @@ class GLFWGameWindow : public GameWindow { void makeCurrent(bool active) override; - int getRelativeScale() const; + double getRelativeScale() const; void setRelativeScale();