@@ -56,6 +56,12 @@ int main(void)
5656 // Update
5757 //----------------------------------------------------------------------------------
5858
59+ // Variables to find the max x and Y to calculate the scale
60+ int maxWidth = 1 ;
61+ int maxHeight = 1 ;
62+
63+ int monitorOffset = 0 ;
64+
5965 // Rebuild monitors array every frame
6066 monitorCount = GetMonitorCount ();
6167 for (int i = 0 ; i < monitorCount ; i ++ )
@@ -69,17 +75,22 @@ int main(void)
6975 GetMonitorPhysicalHeight (i ),
7076 GetMonitorRefreshRate (i )
7177 };
78+ if (monitors [i ].position .x < monitorOffset ) monitorOffset = monitors [i ].position .x * -1 ;
79+
80+ const int width = monitors [i ].position .x + monitors [i ].width ;
81+ const int height = monitors [i ].position .y + monitors [i ].height ;
82+
83+ if (maxWidth < width ) maxWidth = width ;
84+ if (maxHeight < height ) maxHeight = height ;
7285 }
7386
7487 if (IsKeyPressed (KEY_ENTER ) && monitorCount > 1 )
7588 {
7689 currentMonitorIndex += 1 ;
7790
7891 // Set index to 0 if the last one
79- if (currentMonitorIndex == GetMonitorCount ())
80- {
81- currentMonitorIndex = 0 ;
82- }
92+ if (currentMonitorIndex == monitorCount ) currentMonitorIndex = 0 ;
93+
8394 SetWindowMonitor (currentMonitorIndex ); // Move window to currentMonitorIndex
8495 }
8596 else
@@ -89,7 +100,10 @@ int main(void)
89100 }
90101 const Monitor currentMonitor = monitors [currentMonitorIndex ];
91102
92- const float monitorScale = 0.2 / monitorCount ;
103+ float monitorScale = 0.6 ;
104+
105+ if (maxHeight > maxWidth + monitorOffset ) monitorScale *= ((float )screenHeight /(float )maxHeight );
106+ else monitorScale *= ((float )screenWidth /(float )(maxWidth + monitorOffset ));
93107
94108 // Draw
95109 //----------------------------------------------------------------------------------
@@ -99,46 +113,45 @@ int main(void)
99113
100114 DrawText ("Press [Enter] to move window to next monitor available" , 20 , 20 , 20 , DARKGRAY );
101115
102- DrawText (
103- TextFormat ("Resolution: [%ipx x %ipx]\nRefreshRate: [%ihz]\nPhysical Size: [%imm x %imm]\nPosition: %3.2f x %3.2f" ,
104- currentMonitor .width ,
105- currentMonitor .height ,
106- currentMonitor .refreshRate ,
107- currentMonitor .physicalWidth ,
108- currentMonitor .physicalHeight ,
109- currentMonitor .position .x ,
110- currentMonitor .position .y
111- ), 30 , 80 , 20 , GRAY );
112-
113- // List available Monitors
114- for (int i = 0 ; i < monitorCount ; i ++ )
115- {
116- DrawText (TextFormat ("%s" , monitors [i ].name ), 40 , 180 + 20 * i , 20 , GRAY );
117- if (i == currentMonitorIndex )
118- {
119- DrawCircle (30 , 190 + 20 * i , 5 , RED );
120- }
121- }
122116 DrawRectangleLines (20 , 60 , screenWidth - 40 , screenHeight - 100 , DARKGRAY );
123117
124- // Draw Monitors
118+ // Draw Monitor Rectangles with information inside
125119 for (int i = 0 ; i < monitorCount ; i ++ )
126120 {
121+ // Calculate retangle position and size using monitorScale
127122 const Rectangle rec = (Rectangle ){
128- monitors [i ].position .x * monitorScale + 140 ,
129- monitors [i ].position .y * monitorScale + 180 ,
123+ ( monitors [i ].position .x + monitorOffset ) * monitorScale + 140 ,
124+ monitors [i ].position .y * monitorScale + 80 ,
130125 monitors [i ].width * monitorScale ,
131126 monitors [i ].height * monitorScale
132127 };
128+
129+ // Draw monitor name and information inside the rectangle
130+ DrawText (TextFormat ("[%i] %s" , i , monitors [i ].name ), rec .x + 10 , rec .y + (int )(100 * monitorScale ), (int )(120 * monitorScale ), BLUE );
131+ DrawText (
132+ TextFormat ("Resolution: [%ipx x %ipx]\nRefreshRate: [%ihz]\nPhysical Size: [%imm x %imm]\nPosition: %3.0f x %3.0f" ,
133+ monitors [i ].width ,
134+ monitors [i ].height ,
135+ monitors [i ].refreshRate ,
136+ monitors [i ].physicalWidth ,
137+ monitors [i ].physicalHeight ,
138+ monitors [i ].position .x ,
139+ monitors [i ].position .y
140+ ), rec .x + 10 , rec .y + (int )(200 * monitorScale ), (int )(120 * monitorScale ), DARKGRAY );
141+
142+ // Highlight current monitor
133143 if (i == currentMonitorIndex )
134144 {
135145 DrawRectangleLinesEx (rec , 5 , RED );
146+ Vector2 windowPosition = (Vector2 ){ (GetWindowPosition ().x + monitorOffset )* monitorScale + 140 , GetWindowPosition ().y * monitorScale + 80 };
147+
148+ // Draw window position based on monitors
149+ DrawRectangleV (windowPosition , (Vector2 ){screenWidth * monitorScale , screenHeight * monitorScale }, Fade (GREEN , 0.5 ));
136150 }
137151 else
138152 {
139153 DrawRectangleLinesEx (rec , 5 , GRAY );
140154 }
141- DrawText (TextFormat ("%i" , i ), rec .x + rec .width * 0.5 - 10 , rec .y + rec .height * 0.5 - 25 , 50 , GRAY );
142155
143156 }
144157
0 commit comments