@@ -56,6 +56,10 @@ 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+
5963 // Rebuild monitors array every frame
6064 monitorCount = GetMonitorCount ();
6165 for (int i = 0 ; i < monitorCount ; i ++ )
@@ -69,17 +73,22 @@ int main(void)
6973 GetMonitorPhysicalHeight (i ),
7074 GetMonitorRefreshRate (i )
7175 };
76+
77+ const int width = monitors [i ].position .x + monitors [i ].width ;
78+ const int height = monitors [i ].position .y + monitors [i ].height ;
79+
80+ if (maxWidth < width ) maxWidth = width ;
81+
82+ if (maxHeight < height ) maxHeight = height ;
7283 }
7384
7485 if (IsKeyPressed (KEY_ENTER ) && monitorCount > 1 )
7586 {
7687 currentMonitorIndex += 1 ;
7788
7889 // Set index to 0 if the last one
79- if (currentMonitorIndex == GetMonitorCount ())
80- {
81- currentMonitorIndex = 0 ;
82- }
90+ if (currentMonitorIndex == monitorCount ) currentMonitorIndex = 0 ;
91+
8392 SetWindowMonitor (currentMonitorIndex ); // Move window to currentMonitorIndex
8493 }
8594 else
@@ -89,7 +98,10 @@ int main(void)
8998 }
9099 const Monitor currentMonitor = monitors [currentMonitorIndex ];
91100
92- const float monitorScale = 0.2 / monitorCount ;
101+ float monitorScale = 0.6 ;
102+
103+ if (maxHeight > maxWidth ) monitorScale *= ((float )screenHeight /(float )maxHeight );
104+ else monitorScale *= ((float )screenWidth /(float )maxWidth );
93105
94106 // Draw
95107 //----------------------------------------------------------------------------------
@@ -99,46 +111,45 @@ int main(void)
99111
100112 DrawText ("Press [Enter] to move window to next monitor available" , 20 , 20 , 20 , DARKGRAY );
101113
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- }
122114 DrawRectangleLines (20 , 60 , screenWidth - 40 , screenHeight - 100 , DARKGRAY );
123115
124- // Draw Monitors
116+ // Draw Monitor Rectangles with information inside
125117 for (int i = 0 ; i < monitorCount ; i ++ )
126118 {
119+ // Calculate retangle position and size using monitorScale
127120 const Rectangle rec = (Rectangle ){
128121 monitors [i ].position .x * monitorScale + 140 ,
129- monitors [i ].position .y * monitorScale + 180 ,
122+ monitors [i ].position .y * monitorScale + 80 ,
130123 monitors [i ].width * monitorScale ,
131124 monitors [i ].height * monitorScale
132125 };
126+
127+ // Draw monitor name and information inside the rectangle
128+ DrawText (TextFormat ("[%i] %s" , i , monitors [i ].name ), rec .x + 10 , rec .y + (int )(100 * monitorScale ), (int )(120 * monitorScale ), BLUE );
129+ DrawText (
130+ TextFormat ("Resolution: [%ipx x %ipx]\nRefreshRate: [%ihz]\nPhysical Size: [%imm x %imm]\nPosition: %3.0f x %3.0f" ,
131+ monitors [i ].width ,
132+ monitors [i ].height ,
133+ monitors [i ].refreshRate ,
134+ monitors [i ].physicalWidth ,
135+ monitors [i ].physicalHeight ,
136+ monitors [i ].position .x ,
137+ monitors [i ].position .y
138+ ), rec .x + 10 , rec .y + (int )(200 * monitorScale ), (int )(120 * monitorScale ), DARKGRAY );
139+
140+ // Highlight current monitor
133141 if (i == currentMonitorIndex )
134142 {
135143 DrawRectangleLinesEx (rec , 5 , RED );
144+ Vector2 windowPosition = (Vector2 ){ GetWindowPosition ().x * monitorScale + 140 , GetWindowPosition ().y * monitorScale + 80 };
145+
146+ // Draw window position based on monitors
147+ DrawRectangleV (windowPosition , (Vector2 ){screenWidth * monitorScale , screenHeight * monitorScale }, Fade (GREEN , 0.5 ));
136148 }
137149 else
138150 {
139151 DrawRectangleLinesEx (rec , 5 , GRAY );
140152 }
141- DrawText (TextFormat ("%i" , i ), rec .x + rec .width * 0.5 - 10 , rec .y + rec .height * 0.5 - 25 , 50 , GRAY );
142153
143154 }
144155
0 commit comments