From 6a30b4a2a7716d891e73889ffcae3a79a04d34c3 Mon Sep 17 00:00:00 2001 From: Rafael Sachetto Date: Wed, 5 Jun 2019 10:08:24 -0300 Subject: [PATCH] Added GetCurrentMonitor() function to Get the monitor that contains the greater window area --- src/core.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/raylib.h | 1 + 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/core.c b/src/core.c index 26a8b2a48..4bbe650b2 100644 --- a/src/core.c +++ b/src/core.c @@ -938,6 +938,47 @@ int GetMonitorCount(void) #endif } +int GetCurrentMonitor(void) +{ + + int bestmonitor = 0; + +#if defined(PLATFORM_DESKTOP) + + int nmonitors, i; + int wx, wy, ww, wh; + int mx, my, mw, mh; + int overlap, bestoverlap; + GLFWmonitor **monitors; + const GLFWvidmode *mode; + + bestoverlap = 0; + + glfwGetWindowPos(window, &wx, &wy); + glfwGetWindowSize(window, &ww, &wh); + monitors = glfwGetMonitors(&nmonitors); + + for (i = 0; i < nmonitors; i++) { + mode = glfwGetVideoMode(monitors[i]); + glfwGetMonitorPos(monitors[i], &mx, &my); + mw = mode->width; + mh = mode->height; + + overlap = + maxi(0, mini(wx + ww, mx + mw) - maxi(wx, mx)) * + maxi(0, mini(wy + wh, my + mh) - maxi(wy, my)); + + if (bestoverlap < overlap) { + bestoverlap = overlap; + bestmonitor = i; + } + } +#endif + return bestmonitor; + +} + + // Get primary monitor width int GetMonitorWidth(int monitor) { @@ -4991,4 +5032,4 @@ static void LogoAnimation(void) #endif showLogo = false; // Prevent for repeating when reloading window (Android) -} \ No newline at end of file +} diff --git a/src/raylib.h b/src/raylib.h index 21202f18d..83f4aab68 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -878,6 +878,7 @@ RLAPI void *GetWindowHandle(void); // Get native RLAPI int GetScreenWidth(void); // Get current screen width RLAPI int GetScreenHeight(void); // Get current screen height RLAPI int GetMonitorCount(void); // Get number of connected monitors +RLAPI int GetCurrentMonitor(void); // Get the monitor that contains the greater window area. RLAPI int GetMonitorWidth(int monitor); // Get primary monitor width RLAPI int GetMonitorHeight(int monitor); // Get primary monitor height RLAPI int GetMonitorPhysicalWidth(int monitor); // Get primary monitor physical width in millimetres