Complement GetMonitorPosition SDL implementation

This commit is contained in:
ubkp 2023-10-20 01:04:19 -03:00
parent c8e04b0af5
commit e5b0d796e2

View File

@ -693,20 +693,18 @@ int GetCurrentMonitor(void)
// Get selected monitor position // Get selected monitor position
Vector2 GetMonitorPosition(int monitor) Vector2 GetMonitorPosition(int monitor)
{ {
if (monitor < 0 || monitor >= SDL_GetNumVideoDisplays()) const int monitorCount = SDL_GetNumVideoDisplays();
if ((monitor >= 0) && (monitor < monitorCount))
{ {
TRACELOG(LOG_ERROR, "Invalid monitor index"); SDL_Rect displayBounds;
return (Vector2) { 0, 0 }; if (SDL_GetDisplayUsableBounds(monitor, &displayBounds) == 0)
{
return (Vector2){ (float)displayBounds.x, (float)displayBounds.y };
}
else TRACELOG(LOG_WARNING, "SDL: Failed to get selected display usable bounds");
} }
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
SDL_Rect displayBounds; return (Vector2){ 0.0f, 0.0f };
if (SDL_GetDisplayBounds(monitor, &displayBounds) != 0)
{
TRACELOG(LOG_ERROR, "Failed to get display bounds");
return (Vector2) { 0, 0 };
}
return (Vector2) { displayBounds.x, displayBounds.y };
} }
// Get selected monitor width (currently used by monitor) // Get selected monitor width (currently used by monitor)