From 1836e02c1ef9909d25bbb89b9d9fdd6ec934aada Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 27 Sep 2018 15:52:56 +0100 Subject: [PATCH 1/5] Added monitor functions - Get number of monitors - Get size, physical size and name of primary monitor. Could pass monitor id instead not sure. --- src/core.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/raylib.h | 6 ++++++ 2 files changed, 55 insertions(+) diff --git a/src/core.c b/src/core.c index fc1a5a09..e785e735 100644 --- a/src/core.c +++ b/src/core.c @@ -770,6 +770,55 @@ int GetScreenHeight(void) return screenHeight; } +// Get number of monitors +int GetMonitorCount(void) +{ + int monitorCount; + glfwGetMonitors(&monitorCount); + return monitorCount; +} + +// Get primary monitor width +int GetMonitorWidth(void) +{ + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode * mode = glfwGetVideoMode(monitor); + return mode->width; +} + +// Get primary monitor height +int GetMonitorHeight(void) +{ + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode * mode = glfwGetVideoMode(monitor); + return mode->height; +} + +// Get primary montior physical width in millimetres +int GetMonitorPhysicalWidth(void) +{ + int physicalWidth; + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + glfwGetMonitorPhysicalSize(monitor, &physicalWidth, NULL); + return physicalWidth; +} + +// Get primary monitor physical height in millimetres +int GetMonitorPhysicalHeight(void) +{ + int physicalHeight; + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + glfwGetMonitorPhysicalSize(monitor, NULL, &physicalHeight); + return physicalHeight; +} + +// Get the human-readable, UTF-8 encoded name of the primary monitor +const char *GetMonitorName(void) +{ + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + return glfwGetMonitorName(monitor); +} + // Show mouse cursor void ShowCursor() { diff --git a/src/raylib.h b/src/raylib.h index a44b77ee..ee8744e7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -814,6 +814,12 @@ RLAPI void SetWindowMinSize(int width, int height); // Set window RLAPI void SetWindowSize(int width, int height); // Set window dimensions 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 GetMonitorWidth(void); // Get primary monitor width +RLAPI int GetMonitorHeight(void); // Get primary monitor height +RLAPI int GetMonitorPhysicalWidth(void); // Get primary monitor physical width in millimetres +RLAPI int GetMonitorPhysicalHeight(void); // Get primary monitor physical height in millimetres +RLAPI const char *GetMonitorName(void); // Get the human-readable, UTF-8 encoded name of the primary monitor // Cursor-related functions RLAPI void ShowCursor(void); // Shows cursor From ed79d53e1a177596d312453db8db4bc69f2b8656 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 27 Sep 2018 16:23:11 +0100 Subject: [PATCH 2/5] Changed tabs to spaces - Fixed tabs used instead of 4 spaces --- src/core.c | 32 ++++++++++++++++---------------- src/raylib.h | 10 +++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core.c b/src/core.c index 5b9db9fa..9086ad65 100644 --- a/src/core.c +++ b/src/core.c @@ -773,9 +773,9 @@ int GetScreenHeight(void) // Get number of monitors int GetMonitorCount(void) { - int monitorCount; - glfwGetMonitors(&monitorCount); - return monitorCount; + int monitorCount; + glfwGetMonitors(&monitorCount); + return monitorCount; } // Get primary monitor width @@ -789,34 +789,34 @@ int GetMonitorWidth(void) // Get primary monitor height int GetMonitorHeight(void) { - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode * mode = glfwGetVideoMode(monitor); - return mode->height; + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode * mode = glfwGetVideoMode(monitor); + return mode->height; } // Get primary montior physical width in millimetres int GetMonitorPhysicalWidth(void) { - int physicalWidth; - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - glfwGetMonitorPhysicalSize(monitor, &physicalWidth, NULL); - return physicalWidth; + int physicalWidth; + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + glfwGetMonitorPhysicalSize(monitor, &physicalWidth, NULL); + return physicalWidth; } // Get primary monitor physical height in millimetres int GetMonitorPhysicalHeight(void) { - int physicalHeight; - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - glfwGetMonitorPhysicalSize(monitor, NULL, &physicalHeight); - return physicalHeight; + int physicalHeight; + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + glfwGetMonitorPhysicalSize(monitor, NULL, &physicalHeight); + return physicalHeight; } // Get the human-readable, UTF-8 encoded name of the primary monitor const char *GetMonitorName(void) { - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - return glfwGetMonitorName(monitor); + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + return glfwGetMonitorName(monitor); } // Show mouse cursor diff --git a/src/raylib.h b/src/raylib.h index ee8744e7..fb4fb842 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -814,11 +814,11 @@ RLAPI void SetWindowMinSize(int width, int height); // Set window RLAPI void SetWindowSize(int width, int height); // Set window dimensions 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 GetMonitorWidth(void); // Get primary monitor width -RLAPI int GetMonitorHeight(void); // Get primary monitor height -RLAPI int GetMonitorPhysicalWidth(void); // Get primary monitor physical width in millimetres -RLAPI int GetMonitorPhysicalHeight(void); // Get primary monitor physical height in millimetres +RLAPI int GetMonitorCount(void); // Get number of connected monitors +RLAPI int GetMonitorWidth(void); // Get primary monitor width +RLAPI int GetMonitorHeight(void); // Get primary monitor height +RLAPI int GetMonitorPhysicalWidth(void); // Get primary monitor physical width in millimetres +RLAPI int GetMonitorPhysicalHeight(void); // Get primary monitor physical height in millimetres RLAPI const char *GetMonitorName(void); // Get the human-readable, UTF-8 encoded name of the primary monitor // Cursor-related functions From ed95337eb884baac8de84ae0e973a5ecb0d530e2 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sat, 29 Sep 2018 14:10:29 +0100 Subject: [PATCH 3/5] Added platform check - Added PLATFORM_DESKTOP check for Monitor functions to try to fix issue on android. - Not sure what return types should be when not on desktop. Added rough guess for now. --- src/core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core.c b/src/core.c index 9086ad65..65c18fec 100644 --- a/src/core.c +++ b/src/core.c @@ -773,50 +773,68 @@ int GetScreenHeight(void) // Get number of monitors int GetMonitorCount(void) { +#if defined(PLATFORM_DESKTOP) int monitorCount; glfwGetMonitors(&monitorCount); return monitorCount; +#endif + return 1; } // Get primary monitor width int GetMonitorWidth(void) { +#if defined(PLATFORM_DESKTOP) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode * mode = glfwGetVideoMode(monitor); return mode->width; +#endif + return GetScreenWidth(); } // Get primary monitor height int GetMonitorHeight(void) { +#if defined(PLATFORM_DESKTOP) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode * mode = glfwGetVideoMode(monitor); return mode->height; +#endif + return GetScreenHeight(); } // Get primary montior physical width in millimetres int GetMonitorPhysicalWidth(void) { +#if defined(PLATFORM_DESKTOP) int physicalWidth; GLFWmonitor *monitor = glfwGetPrimaryMonitor(); glfwGetMonitorPhysicalSize(monitor, &physicalWidth, NULL); return physicalWidth; +#endif + return 0; } // Get primary monitor physical height in millimetres int GetMonitorPhysicalHeight(void) { +#if defined(PLATFORM_DESKTOP) int physicalHeight; GLFWmonitor *monitor = glfwGetPrimaryMonitor(); glfwGetMonitorPhysicalSize(monitor, NULL, &physicalHeight); return physicalHeight; +#endif + return 0; } // Get the human-readable, UTF-8 encoded name of the primary monitor const char *GetMonitorName(void) { +#if defined(PLATFORM_DESKTOP) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); return glfwGetMonitorName(monitor); +#endif + return ""; } // Show mouse cursor From 6b84b76b70be35b471ef31afc0f0dc4e16cfe383 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sat, 29 Sep 2018 14:28:07 +0100 Subject: [PATCH 4/5] Forgot #else in platform check - Added else so return not compiled twice. --- src/core.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core.c b/src/core.c index 65c18fec..e370d5e3 100644 --- a/src/core.c +++ b/src/core.c @@ -777,8 +777,9 @@ int GetMonitorCount(void) int monitorCount; glfwGetMonitors(&monitorCount); return monitorCount; -#endif +#else return 1; +#endif } // Get primary monitor width @@ -788,8 +789,9 @@ int GetMonitorWidth(void) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode * mode = glfwGetVideoMode(monitor); return mode->width; -#endif +#else return GetScreenWidth(); +#endif } // Get primary monitor height @@ -799,8 +801,9 @@ int GetMonitorHeight(void) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode * mode = glfwGetVideoMode(monitor); return mode->height; -#endif +#else return GetScreenHeight(); +#endif } // Get primary montior physical width in millimetres @@ -811,8 +814,9 @@ int GetMonitorPhysicalWidth(void) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); glfwGetMonitorPhysicalSize(monitor, &physicalWidth, NULL); return physicalWidth; -#endif +#else return 0; +#endif } // Get primary monitor physical height in millimetres @@ -823,8 +827,9 @@ int GetMonitorPhysicalHeight(void) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); glfwGetMonitorPhysicalSize(monitor, NULL, &physicalHeight); return physicalHeight; -#endif +#else return 0; +#endif } // Get the human-readable, UTF-8 encoded name of the primary monitor @@ -833,8 +838,9 @@ const char *GetMonitorName(void) #if defined(PLATFORM_DESKTOP) GLFWmonitor *monitor = glfwGetPrimaryMonitor(); return glfwGetMonitorName(monitor); -#endif +#else return ""; +#endif } // Show mouse cursor From 67dc50ef0077b194fa51014880e531b126d0b059 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Sun, 30 Sep 2018 15:20:02 +0100 Subject: [PATCH 5/5] Changed monitor functions to use a index - Using same idea as SetWindowMonitor to take in a index with 0 being the primary monitor. --- src/core.c | 93 +++++++++++++++++++++++++++++++++------------------- src/raylib.h | 10 +++--- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/core.c b/src/core.c index e370d5e3..203da4d9 100644 --- a/src/core.c +++ b/src/core.c @@ -783,64 +783,89 @@ int GetMonitorCount(void) } // Get primary monitor width -int GetMonitorWidth(void) +int GetMonitorWidth(int monitor) { #if defined(PLATFORM_DESKTOP) - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode * mode = glfwGetVideoMode(monitor); - return mode->width; -#else - return GetScreenWidth(); + int monitorCount; + GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); + + if ((monitor >= 0) && (monitor < monitorCount)) + { + const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); + return mode->width; + } + else TraceLog(LOG_WARNING, "Selected monitor not found"); #endif + return 0; } -// Get primary monitor height -int GetMonitorHeight(void) -{ +// Get primary monitor width +int GetMonitorHeight(int monitor) +{ #if defined(PLATFORM_DESKTOP) - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode * mode = glfwGetVideoMode(monitor); - return mode->height; -#else - return GetScreenHeight(); + int monitorCount; + GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); + + if ((monitor >= 0) && (monitor < monitorCount)) + { + const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); + return mode->height; + } + else TraceLog(LOG_WARNING, "Selected monitor not found"); #endif + return 0; } // Get primary montior physical width in millimetres -int GetMonitorPhysicalWidth(void) +int GetMonitorPhysicalWidth(int monitor) { #if defined(PLATFORM_DESKTOP) - int physicalWidth; - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - glfwGetMonitorPhysicalSize(monitor, &physicalWidth, NULL); - return physicalWidth; -#else - return 0; + int monitorCount; + GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); + + if ((monitor >= 0) && (monitor < monitorCount)) + { + int physicalWidth; + glfwGetMonitorPhysicalSize(monitors[monitor], &physicalWidth, NULL); + return physicalWidth; + } + else TraceLog(LOG_WARNING, "Selected monitor not found"); #endif + return 0; } // Get primary monitor physical height in millimetres -int GetMonitorPhysicalHeight(void) +int GetMonitorPhysicalHeight(int monitor) { -#if defined(PLATFORM_DESKTOP) - int physicalHeight; - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - glfwGetMonitorPhysicalSize(monitor, NULL, &physicalHeight); - return physicalHeight; -#else - return 0; +#if defined(PLATFORM_DESKTOP) + int monitorCount; + GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); + + if ((monitor >= 0) && (monitor < monitorCount)) + { + int physicalHeight; + glfwGetMonitorPhysicalSize(monitors[monitor], NULL, &physicalHeight); + return physicalHeight; + } + else TraceLog(LOG_WARNING, "Selected monitor not found"); #endif + return 0; } // Get the human-readable, UTF-8 encoded name of the primary monitor -const char *GetMonitorName(void) +const char *GetMonitorName(int monitor) { #if defined(PLATFORM_DESKTOP) - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - return glfwGetMonitorName(monitor); -#else - return ""; + int monitorCount; + GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); + + if ((monitor >= 0) && (monitor < monitorCount)) + { + return glfwGetMonitorName(monitors[monitor]); + } + else TraceLog(LOG_WARNING, "Selected monitor not found"); #endif + return ""; } // Show mouse cursor diff --git a/src/raylib.h b/src/raylib.h index fb4fb842..17c4234e 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -815,11 +815,11 @@ RLAPI void SetWindowSize(int width, int height); // Set window 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 GetMonitorWidth(void); // Get primary monitor width -RLAPI int GetMonitorHeight(void); // Get primary monitor height -RLAPI int GetMonitorPhysicalWidth(void); // Get primary monitor physical width in millimetres -RLAPI int GetMonitorPhysicalHeight(void); // Get primary monitor physical height in millimetres -RLAPI const char *GetMonitorName(void); // Get the human-readable, UTF-8 encoded name of the primary monitor +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 +RLAPI int GetMonitorPhysicalHeight(int monitor); // Get primary monitor physical height in millimetres +RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the primary monitor // Cursor-related functions RLAPI void ShowCursor(void); // Shows cursor