style_selector.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*******************************************************************************************
  2. *
  3. * raygui - style selector
  4. *
  5. * DEPENDENCIES:
  6. * raylib 4.5 - Windowing/input management and drawing
  7. * raygui 3.5 - Immediate-mode GUI controls with custom styling and icons
  8. *
  9. * COMPILATION (Windows - MinGW):
  10. * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
  11. *
  12. * LICENSE: zlib/libpng
  13. *
  14. * Copyright (c) 2016-2024 Ramon Santamaria (@raysan5)
  15. *
  16. **********************************************************************************************/
  17. #include "raylib.h"
  18. #define RAYGUI_IMPLEMENTATION
  19. //#define RAYGUI_CUSTOM_ICONS // It requires providing gui_icons.h in the same directory
  20. //#include "gui_icons.h" // External icons data provided, it can be generated with rGuiIcons tool
  21. #include "../../src/raygui.h"
  22. // raygui embedded styles
  23. // NOTE: Included in the same order as selector
  24. #define MAX_GUI_STYLES_AVAILABLE 12 // NOTE: Included light style
  25. #include "../styles/style_jungle.h" // raygui style: jungle
  26. #include "../styles/style_candy.h" // raygui style: candy
  27. #include "../styles/style_lavanda.h" // raygui style: lavanda
  28. #include "../styles/style_cyber.h" // raygui style: cyber
  29. #include "../styles/style_terminal.h" // raygui style: terminal
  30. #include "../styles/style_ashes.h" // raygui style: ashes
  31. #include "../styles/style_bluish.h" // raygui style: bluish
  32. #include "../styles/style_dark.h" // raygui style: dark
  33. #include "../styles/style_cherry.h" // raygui style: cherry
  34. #include "../styles/style_sunny.h" // raygui style: sunny
  35. #include "../styles/style_enefete.h" // raygui style: enefete
  36. #include <string.h> // Required for: strcpy()
  37. //------------------------------------------------------------------------------------
  38. // Program main entry point
  39. //------------------------------------------------------------------------------------
  40. int main()
  41. {
  42. // Initialization
  43. //---------------------------------------------------------------------------------------
  44. const int screenWidth = 800;
  45. const int screenHeight = 480;
  46. InitWindow(screenWidth, screenHeight, "raygui - styles selector");
  47. SetExitKey(0);
  48. // Custom GUI font loading
  49. //Font font = LoadFontEx("fonts/custom_font.ttf", 12, 0, 0);
  50. //GuiSetFont(font);
  51. bool exitWindow = false;
  52. bool showMessageBox = false;
  53. // Load default style
  54. GuiLoadStyleBluish();
  55. int visualStyleActive = 4;
  56. int prevVisualStyleActive = 4;
  57. SetTargetFPS(60);
  58. //--------------------------------------------------------------------------------------
  59. // Main game loop
  60. while (!exitWindow) // Detect window close button or ESC key
  61. {
  62. // Update
  63. //----------------------------------------------------------------------------------
  64. exitWindow = WindowShouldClose();
  65. if (IsKeyPressed(KEY_ESCAPE)) showMessageBox = !showMessageBox;
  66. if (IsFileDropped())
  67. {
  68. FilePathList droppedFiles = LoadDroppedFiles();
  69. if ((droppedFiles.count > 0) && IsFileExtension(droppedFiles.paths[0], ".rgs")) GuiLoadStyle(droppedFiles.paths[0]);
  70. UnloadDroppedFiles(droppedFiles); // Clear internal buffers
  71. }
  72. if (visualStyleActive != prevVisualStyleActive)
  73. {
  74. // Reset to default internal style
  75. // NOTE: Required to unload any previously loaded font texture
  76. GuiLoadStyleDefault();
  77. switch (visualStyleActive)
  78. {
  79. case 1: GuiLoadStyleJungle(); break;
  80. case 2: GuiLoadStyleCandy(); break;
  81. case 3: GuiLoadStyleLavanda(); break;
  82. case 4: GuiLoadStyleCyber(); break;
  83. case 5: GuiLoadStyleTerminal(); break;
  84. case 6: GuiLoadStyleAshes(); break;
  85. case 7: GuiLoadStyleBluish(); break;
  86. case 8: GuiLoadStyleDark(); break;
  87. case 9: GuiLoadStyleCherry(); break;
  88. case 10: GuiLoadStyleSunny(); break;
  89. case 11: GuiLoadStyleEnefete(); break;
  90. default: break;
  91. }
  92. prevVisualStyleActive = visualStyleActive;
  93. }
  94. //----------------------------------------------------------------------------------
  95. // Draw
  96. //----------------------------------------------------------------------------------
  97. BeginDrawing();
  98. ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
  99. // Visuals options
  100. GuiLabel((Rectangle){ 10, 10, 60, 24 }, "Style:");
  101. GuiComboBox((Rectangle){ 60,10, 120, 24 }, "default;Jungle;Candy;Lavanda;Cyber;Terminal;Ashes;Bluish;Dark;Cherry;Sunny;Enefete", &visualStyleActive);
  102. DrawRectangle(10, 44, GuiGetFont().texture.width, GuiGetFont().texture.height, BLACK);
  103. DrawTexture(GuiGetFont().texture, 10, 44, WHITE);
  104. DrawRectangleLines(10, 44, GuiGetFont().texture.width, GuiGetFont().texture.height,
  105. GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)));
  106. //GuiSetIconScale(2);
  107. //GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_RIGHT);
  108. //GuiButton((Rectangle){ 25, 255, 300, 30 }, GuiIconText(ICON_FILE_SAVE, "Save File"));
  109. //GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  110. //----------------------------------------------------------------------------------
  111. EndDrawing();
  112. //----------------------------------------------------------------------------------
  113. }
  114. // De-Initialization
  115. //--------------------------------------------------------------------------------------
  116. CloseWindow(); // Close window and OpenGL context
  117. //--------------------------------------------------------------------------------------
  118. return 0;
  119. }