@@ -175,6 +175,8 @@ static char **srcFileNameList = NULL;
175175
176176static float exportProjectProgress = 0.0f ;
177177
178+ static bool screenSizeDouble = false; // Scale screen x2 (useful for HighDPI/4K screens)
179+
178180//------------------------------------------------------------------------------------
179181// Program main entry point
180182//------------------------------------------------------------------------------------
@@ -274,6 +276,26 @@ int main(int argc, char *argv[])
274276 InitWindow (screenWidth , screenHeight , "raylib project creator" );
275277 SetExitKey (0 );
276278
279+ RenderTexture2D screenTarget = LoadRenderTexture (screenWidth , screenHeight );
280+ SetTextureFilter (screenTarget .texture , TEXTURE_FILTER_POINT );
281+
282+ #if !defined(PLATFORM_WEB )
283+ int monitorWidth = GetMonitorWidth (GetCurrentMonitor ());
284+ int monitorHeight = GetMonitorHeight (GetCurrentMonitor ());
285+ if ((GetWindowScaleDPI ().x > 1.0f ) || (monitorWidth > (screenWidth * 2 )))
286+ {
287+ // NOTE: We need to consider app window title bar and possible OS bottom bar
288+ if ((monitorHeight - 24 - 40 ) > (screenHeight * 2 ))
289+ {
290+ screenSizeDouble = true;
291+ SetWindowSize (screenWidth * 2 , screenHeight * 2 );
292+ SetMouseScale (0.5f , 0.5f );
293+
294+ SetWindowPosition (monitorWidth /2 - screenWidth , monitorHeight /2 - screenHeight );
295+ }
296+ }
297+ #endif
298+
277299 // Initialize project config default
278300 ProjectConfig * config = (ProjectConfig * )RL_CALLOC (1 , sizeof (ProjectConfig ));
279301 config -> project .type = 2 ; // Custom files
@@ -402,6 +424,34 @@ int main(int argc, char *argv[])
402424
403425 // Basic program flow logic
404426 //----------------------------------------------------------------------------------
427+ #if !defined(PLATFORM_WEB )
428+ // Window scale logic to support 4K/HighDPI monitors
429+ if (IsKeyPressed (KEY_F10 ))
430+ {
431+ screenSizeDouble = !screenSizeDouble ;
432+ if (screenSizeDouble )
433+ {
434+ // Screen size x2
435+ if (GetScreenWidth () < screenWidth * 2 )
436+ {
437+ SetWindowSize (screenWidth * 2 , screenHeight * 2 );
438+ SetMouseScale (0.5f , 0.5f );
439+ SetWindowPosition (monitorWidth /2 - screenWidth , monitorHeight /2 - screenHeight );
440+ }
441+ }
442+ else
443+ {
444+ // Screen size x1
445+ if (screenWidth * 2 >= GetScreenWidth ())
446+ {
447+ SetWindowSize (screenWidth , screenHeight );
448+ SetMouseScale (1.0f , 1.0f );
449+ SetWindowPosition (monitorWidth /2 - screenWidth /2 , monitorHeight /2 - screenHeight /2 );
450+ }
451+ }
452+ }
453+ #endif
454+
405455 if (showExitWindow ||
406456 showInfoMessagePanel ||
407457 showLoadSourceFilesDialog ||
@@ -417,8 +467,9 @@ int main(int argc, char *argv[])
417467
418468 // Draw
419469 //----------------------------------------------------------------------------------
420- BeginDrawing ();
421- ClearBackground (GetColor (GuiGetStyle (DEFAULT , BACKGROUND_COLOR )));
470+ // Render all screen to texture (for scaling)
471+ BeginTextureMode (screenTarget );
472+ ClearBackground (GetColor (GuiGetStyle (DEFAULT , BACKGROUND_COLOR )));
422473
423474 // GUI: Main Window
424475 //----------------------------------------------------------------------------------
@@ -487,8 +538,14 @@ int main(int argc, char *argv[])
487538#endif
488539 if (GuiButton ((Rectangle ){ anchorBuilding .x + 656 , anchorBuilding .y + 16 , 120 , 24 }, "Browse" )) showLoadRaylibSourcePathDialog = true;
489540 GuiEnable ();
541+
542+ #if !defined(PLATFORM_WEB ) && (defined(__linux__ ) || defined(__FreeBSD__ ))
543+ GuiDisable ()
544+ #endif
490545 GuiLabel ((Rectangle ){ anchorBuilding .x + 8 , anchorBuilding .y + 48 , 104 , 24 }, "COMPILER PATH:" );
491546 if (GuiTextBox ((Rectangle ){ anchorBuilding .x + 112 , anchorBuilding .y + 48 , 536 , 24 }, config -> building .compilerPath , 128 , buildingCompilerPathEditMode )) buildingCompilerPathEditMode = !buildingCompilerPathEditMode ;
547+ GuiEnable ();
548+
492549#if defined(PLATFORM_WEB )
493550 GuiDisable ();
494551#endif
@@ -520,10 +577,10 @@ int main(int argc, char *argv[])
520577 }
521578 GuiEnable ();
522579
523- if (!lockBackground && CheckCollisionPointRec (GetMousePosition (), (Rectangle ){ 0 , GetScreenHeight () - 32 , GetScreenWidth () , 32 })) SetMouseCursor (MOUSE_CURSOR_POINTING_HAND );
580+ if (!lockBackground && CheckCollisionPointRec (GetMousePosition (), (Rectangle ){ 0 , GetScreenHeight () - 32 , screenWidth , 32 })) SetMouseCursor (MOUSE_CURSOR_POINTING_HAND );
524581 else SetMouseCursor (MOUSE_CURSOR_DEFAULT );
525582
526- if (GuiButton ((Rectangle ){ 0 , GetScreenHeight () - 32 , GetScreenWidth () , 32 },
583+ if (GuiButton ((Rectangle ){ 0 , screenHeight - 32 , screenWidth , 32 },
527584 "Did you find this tool useful? Please, consider a donation! Thanks! <3" ))
528585 {
529586 OpenURL ("https://github.com/sponsors/raysan5" );
@@ -535,13 +592,13 @@ int main(int argc, char *argv[])
535592 //int textPadding = GuiGetStyle(STATUSBAR, TEXT_PADDING);
536593 //GuiSetStyle(STATUSBAR, TEXT_PADDING, 0);
537594 //GuiSetStyle(STATUSBAR, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
538- //GuiStatusBar((Rectangle){ 0, screenHeight - 24, GetScreenWidth() , 24 }, "PROJECT INFO");
595+ //GuiStatusBar((Rectangle){ 0, screenHeight - 24, screenWidth , 24 }, "PROJECT INFO");
539596 //GuiSetStyle(STATUSBAR, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
540597 //GuiSetStyle(STATUSBAR, TEXT_PADDING, textPadding);
541598 //----------------------------------------------------------------------------------
542599
543600 // NOTE: If some overlap window is open and main window is locked, we draw a background rectangle
544- if (lockBackground ) DrawRectangle (0 , 0 , GetScreenWidth (), GetScreenHeight () , Fade (GetColor (GuiGetStyle (DEFAULT , BACKGROUND_COLOR )), 0.85f ));
601+ if (lockBackground ) DrawRectangle (0 , 0 , screenWidth , screenHeight , Fade (GetColor (GuiGetStyle (DEFAULT , BACKGROUND_COLOR )), 0.85f ));
545602
546603 // WARNING: Before drawing the windows, we unlock them
547604 GuiUnlock ();
@@ -551,18 +608,18 @@ int main(int argc, char *argv[])
551608 if (showInfoMessagePanel )
552609 {
553610 Vector2 textSize = MeasureTextEx (GuiGetFont (), infoMessage , GuiGetFont ().baseSize * 2 , 3 );
554- GuiPanel ((Rectangle ){ -10 , GetScreenHeight () /2 - 180 , GetScreenWidth () + 20 , 290 }, NULL );
611+ GuiPanel ((Rectangle ){ -10 , screenHeight /2 - 180 , screenWidth + 20 , 290 }, NULL );
555612
556613 GuiSetStyle (DEFAULT , TEXT_SIZE , GuiGetFont ().baseSize * 3 );
557614 GuiSetStyle (DEFAULT , TEXT_SPACING , 3 );
558615 GuiSetStyle (LABEL , TEXT_ALIGNMENT , TEXT_ALIGN_CENTER );
559616 GuiSetStyle (LABEL , TEXT_COLOR_NORMAL , GuiGetStyle (DEFAULT , TEXT_COLOR_FOCUSED ));
560- GuiLabel ((Rectangle ){ -10 , GetScreenHeight () /2 - 140 , GetScreenWidth () + 20 , 30 }, infoTitle );
617+ GuiLabel ((Rectangle ){ -10 , screenHeight /2 - 140 , screenWidth + 20 , 30 }, infoTitle );
561618 GuiSetStyle (LABEL , TEXT_COLOR_NORMAL , GuiGetStyle (DEFAULT , TEXT_COLOR_NORMAL ));
562619 GuiSetStyle (DEFAULT , TEXT_SIZE , GuiGetFont ().baseSize * 2 );
563- GuiLabel ((Rectangle ){ -10 , GetScreenHeight () /2 - textSize .y - 30 , GetScreenWidth () + 20 , 30 }, infoMessage );
620+ GuiLabel ((Rectangle ){ -10 , screenHeight /2 - textSize .y - 30 , screenWidth + 20 , 30 }, infoMessage );
564621
565- if (GuiButton ((Rectangle ){ GetScreenWidth () /4 , GetScreenHeight () /2 + 40 , GetScreenWidth () /2 , 40 }, infoButton ))
622+ if (GuiButton ((Rectangle ){ screenWidth /4 , screenHeight /2 + 40 , screenWidth /2 , 40 }, infoButton ))
566623 {
567624 showInfoMessagePanel = false;
568625
@@ -725,21 +782,21 @@ int main(int argc, char *argv[])
725782 //----------------------------------------------------------------------------------------
726783 if (showExportProjectProgress )
727784 {
728- GuiPanel ((Rectangle ){ -10 , GetScreenHeight () /2 - 100 , GetScreenWidth () + 20 , 200 }, NULL );
785+ GuiPanel ((Rectangle ){ -10 , screenHeight /2 - 100 , screenWidth + 20 , 200 }, NULL );
729786
730787 GuiSetStyle (DEFAULT , TEXT_SIZE , GuiGetFont ().baseSize * 3 );
731788 GuiSetStyle (DEFAULT , TEXT_SPACING , 3 );
732789 GuiSetStyle (LABEL , TEXT_ALIGNMENT , TEXT_ALIGN_CENTER );
733790 GuiSetStyle (LABEL , TEXT_COLOR_NORMAL , GuiGetStyle (DEFAULT , TEXT_COLOR_FOCUSED ));
734- GuiLabel ((Rectangle ){ -10 , GetScreenHeight () /2 - 60 , GetScreenWidth () + 20 , 30 }, ((int )exportProjectProgress >= 100 )? "PROJECT GENERATED SUCCESSFULLY" : "GENERATING PROJECT..." );
791+ GuiLabel ((Rectangle ){ -10 , screenHeight /2 - 60 , screenWidth + 20 , 30 }, ((int )exportProjectProgress >= 100 )? "PROJECT GENERATED SUCCESSFULLY" : "GENERATING PROJECT..." );
735792 GuiSetStyle (LABEL , TEXT_COLOR_NORMAL , GuiGetStyle (DEFAULT , TEXT_COLOR_NORMAL ));
736793 GuiSetStyle (DEFAULT , TEXT_SIZE , GuiGetFont ().baseSize * 2 );
737794
738795 exportProjectProgress += 2.0f ;
739- GuiProgressBar ((Rectangle ){ 12 , GetScreenHeight () /2 , GetScreenWidth () - 24 , 20 }, NULL , NULL , & exportProjectProgress , 0 , 100 );
796+ GuiProgressBar ((Rectangle ){ 12 , screenHeight /2 , screenWidth - 24 , 20 }, NULL , NULL , & exportProjectProgress , 0 , 100 );
740797
741798 if (exportProjectProgress < 100.0f ) GuiDisable ();
742- if (GuiButton ((Rectangle ){ GetScreenWidth () /4 , GetScreenHeight () /2 + 40 , GetScreenWidth () /2 , 40 }, "GREAT!" ))
799+ if (GuiButton ((Rectangle ){ screenWidth /4 , screenHeight /2 + 40 , screenWidth /2 , 40 }, "GREAT!" ))
743800 {
744801 showExportProjectProgress = false;
745802 }
@@ -792,7 +849,14 @@ int main(int argc, char *argv[])
792849 }
793850 }
794851 //----------------------------------------------------------------------------------------
852+ EndTextureMode ();
853+
854+ BeginDrawing ();
855+ ClearBackground (GetColor (GuiGetStyle (DEFAULT , BACKGROUND_COLOR )));
795856
857+ // Draw render texture to screen
858+ if (screenSizeDouble ) DrawTexturePro (screenTarget .texture , (Rectangle ){ 0 , 0 , (float )screenTarget .texture .width , - (float )screenTarget .texture .height }, (Rectangle ){ 0 , 0 , (float )screenTarget .texture .width * 2 , (float )screenTarget .texture .height * 2 }, (Vector2 ){ 0 , 0 }, 0.0f , WHITE );
859+ else DrawTextureRec (screenTarget .texture , (Rectangle ){ 0 , 0 , (float )screenTarget .texture .width , - (float )screenTarget .texture .height }, (Vector2 ){ 0 , 0 }, WHITE );
796860 EndDrawing ();
797861 //----------------------------------------------------------------------------------
798862 }
0 commit comments