mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-06 06:13:10 +00:00
Update core_monitor_detector.c
This commit is contained in:
parent
e1d5adb326
commit
80e164fa04
@ -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,25 +84,22 @@ 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;
|
||||||
|
|
||||||
// Set index to 0 if the last one
|
// Set index to 0 if the last one
|
||||||
if(currentMonitorIndex == monitorCount) currentMonitorIndex = 0;
|
if (currentMonitorIndex == monitorCount) currentMonitorIndex = 0;
|
||||||
|
|
||||||
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
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -120,10 +116,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Calculate retangle position and size using monitorScale
|
// Calculate retangle position and size using monitorScale
|
||||||
const Rectangle rec = (Rectangle){
|
const Rectangle rec = (Rectangle){
|
||||||
(monitors[i].position.x + monitorOffsetX) * monitorScale + 140,
|
(monitors[i].position.x + monitorOffsetX)*monitorScale + 140,
|
||||||
monitors[i].position.y * monitorScale + 80,
|
monitors[i].position.y*monitorScale + 80,
|
||||||
monitors[i].width * monitorScale,
|
monitors[i].width*monitorScale,
|
||||||
monitors[i].height * monitorScale
|
monitors[i].height*monitorScale
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draw monitor name and information inside the rectangle
|
// Draw monitor name and information inside the rectangle
|
||||||
@ -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();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user