Update core_monitor_detector.c

This commit is contained in:
Ray 2025-11-19 13:07:45 +01:00
parent e1d5adb326
commit 80e164fa04

View File

@ -40,10 +40,9 @@ int main(void)
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
MonitorInfo monitors[MAX_MONITORS] = { 0 };
InitWindow(screenWidth, screenHeight, "raylib [core] example - monitor detector"); InitWindow(screenWidth, screenHeight, "raylib [core] example - monitor detector");
MonitorInfo monitors[MAX_MONITORS] = { 0 };
int currentMonitorIndex = GetCurrentMonitor(); int currentMonitorIndex = GetCurrentMonitor();
int monitorCount = 0; int monitorCount = 0;
@ -55,7 +54,6 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Variables to find the max x and Y to calculate the scale // Variables to find the max x and Y to calculate the scale
int maxWidth = 1; int maxWidth = 1;
int maxHeight = 1; int maxHeight = 1;
@ -76,7 +74,8 @@ int main(void)
GetMonitorPhysicalHeight(i), GetMonitorPhysicalHeight(i),
GetMonitorRefreshRate(i) GetMonitorRefreshRate(i)
}; };
if (monitors[i].position.x < monitorOffsetX) monitorOffsetX = (int)monitors[i].position.x*-1;
if (monitors[i].position.x < monitorOffsetX) monitorOffsetX = -(int)monitors[i].position.x;
const int width = (int)monitors[i].position.x + monitors[i].width; const int width = (int)monitors[i].position.x + monitors[i].width;
const int height = (int)monitors[i].position.y + monitors[i].height; const int height = (int)monitors[i].position.y + monitors[i].height;
@ -85,7 +84,7 @@ int main(void)
if (maxHeight < height) maxHeight = height; if (maxHeight < height) maxHeight = height;
} }
if (IsKeyPressed(KEY_ENTER) && monitorCount > 1) if (IsKeyPressed(KEY_ENTER) && (monitorCount > 1))
{ {
currentMonitorIndex += 1; currentMonitorIndex += 1;
@ -94,16 +93,13 @@ int main(void)
SetWindowMonitor(currentMonitorIndex); // Move window to currentMonitorIndex SetWindowMonitor(currentMonitorIndex); // Move window to currentMonitorIndex
} }
else else currentMonitorIndex = GetCurrentMonitor(); // Get currentMonitorIndex if manually moved
{
// Get currentMonitorIndex if manually moved
currentMonitorIndex = GetCurrentMonitor();
}
float monitorScale = 0.6f; float monitorScale = 0.6f;
if(maxHeight > maxWidth + monitorOffsetX) monitorScale *= ((float)screenHeight/(float)maxHeight); if (maxHeight > (maxWidth + monitorOffsetX)) monitorScale *= ((float)screenHeight/(float)maxHeight);
else monitorScale *= ((float)screenWidth/(float)(maxWidth + monitorOffsetX)); else monitorScale *= ((float)screenWidth/(float)(maxWidth + monitorOffsetX));
//----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -148,14 +144,9 @@ int main(void)
// Draw window position based on monitors // Draw window position based on monitors
DrawRectangleV(windowPosition, (Vector2){screenWidth * monitorScale, screenHeight * monitorScale}, Fade(GREEN, 0.5)); DrawRectangleV(windowPosition, (Vector2){screenWidth * monitorScale, screenHeight * monitorScale}, Fade(GREEN, 0.5));
} }
else else DrawRectangleLinesEx(rec, 5, GRAY);
{
DrawRectangleLinesEx(rec, 5, GRAY);
} }
}
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }