summaryrefslogtreecommitdiffhomepage
path: root/src/platforms/rcore_web.c
diff options
context:
space:
mode:
authorKarl Zylinski <[email protected]>2024-01-13 10:49:04 +0100
committerGitHub <[email protected]>2024-01-13 10:49:04 +0100
commit520c8cffb2f1b5e7d5574e6be6e502489e75ff55 (patch)
treed7ac86572344a29335d7ea3ceba01feacff5d4b4 /src/platforms/rcore_web.c
parentb7141d556ed2d99c19063ec9f4bd6bb389498810 (diff)
downloadraylib-520c8cffb2f1b5e7d5574e6be6e502489e75ff55.tar.gz
raylib-520c8cffb2f1b5e7d5574e6be6e502489e75ff55.zip
Simplified GetWindowScaleDPI() so it does not fetch the wrong DPI scale some times (Windows looks at center of window while the old raylib code looked on upper left corner of window, now it just uses the glfw function to fetch the window's current scaling). Also introduced a callback to update the CORE.Window.screenScaling when the content scaling updates, previously scaling did not work correctly on systems with multiple monitors that have different DPI scaling. (#3701)
Diffstat (limited to 'src/platforms/rcore_web.c')
-rw-r--r--src/platforms/rcore_web.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c
index a7f42438..8c16ff32 100644
--- a/src/platforms/rcore_web.c
+++ b/src/platforms/rcore_web.c
@@ -110,11 +110,12 @@ void ClosePlatform(void); // Close platform
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
// Window callbacks events
-static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
-static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
-//static void WindowMaximizeCallback(GLFWwindow *window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized
-static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 WindowFocus Callback, runs when window get/lose focus
-static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
+static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
+static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
+//static void WindowMaximizeCallback(GLFWwindow *window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized
+static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 WindowFocus Callback, runs when window get/lose focus
+static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
+static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); // GLFW3 Window Content Scale Callback, runs when window changes scale
// Input callbacks events
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
@@ -1190,6 +1191,11 @@ int InitPlatform(void)
glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback);
glfwSetDropCallback(platform.handle, WindowDropCallback);
+ if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
+ {
+ glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback);
+ }
+
// Set input callback events
glfwSetKeyCallback(platform.handle, KeyCallback);
glfwSetCharCallback(platform.handle, CharCallback);
@@ -1327,6 +1333,11 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
// NOTE: Postprocessing texture is not scaled to new size
}
+static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley)
+{
+ CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f);
+}
+
// GLFW3 WindowIconify Callback, runs when window is minimized/restored
static void WindowIconifyCallback(GLFWwindow *window, int iconified)
{