controls_test_suite.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*******************************************************************************************
  2. *
  3. * raygui - controls test suite
  4. *
  5. * TEST CONTROLS:
  6. * - GuiDropdownBox()
  7. * - GuiValueBox()
  8. * - GuiSpinner()
  9. * - GuiTextBox()
  10. * - GuiTextBoxMulti()
  11. * - GuiListView()
  12. *
  13. * DEPENDENCIES:
  14. * raylib 2.1 - Windowing/input management and drawing.
  15. * raygui 2.0 - Immediate-mode GUI controls.
  16. *
  17. * COMPILATION (Windows - MinGW):
  18. * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
  19. *
  20. * LICENSE: zlib/libpng
  21. *
  22. * Copyright (c) 2018 raylib technologies (@raylibtech)
  23. *
  24. **********************************************************************************************/
  25. #include "raylib.h"
  26. #define RAYGUI_IMPLEMENTATION
  27. #include "../../src/raygui.h"
  28. //------------------------------------------------------------------------------------
  29. // Program main entry point
  30. //------------------------------------------------------------------------------------
  31. int main()
  32. {
  33. // Initialization
  34. //---------------------------------------------------------------------------------------
  35. int screenWidth = 800;
  36. int screenHeight = 600;
  37. InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
  38. // GUI controls initialization
  39. //----------------------------------------------------------------------------------
  40. int dropdownBox000Active = 0;
  41. const char *dropdownBox000TextList[3] = { "ONE", "TWO", "THREE" };
  42. bool dropDown000EditMode = false;
  43. int dropdownBox001Active = 0;
  44. const char *dropdownBox001TextList[5] = { "ONE", "TWO", "THREE", "FOUR", "FIVE" };
  45. bool dropDown001EditMode = false;
  46. int spinner001Value = 0;
  47. bool spinnerEditMode = false;
  48. int valueBox002Value = 0;
  49. bool valueBoxEditMode = false;
  50. char textBoxText[64] = "Text box";
  51. bool textBoxEditMode = false;
  52. int listViewScrollIndex = 1;
  53. int listViewActive = -1;
  54. const char *listViewList[6] = { "Charmander", "Bulbasaur", "Squirtel", "Pikachu", "Eevee", "Pidgey" };
  55. bool listViewEditMode = false;
  56. int listViewExScrollIndex = 0;
  57. int listViewExActive = -1;
  58. int listViewExFocus = -1;
  59. const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
  60. int listViewExElementsEnable[8] = {1, 0, 1, 1, 0, 0, 1};
  61. bool listViewExEditMode = false;
  62. char multiTextBoxText[141] = "Multi text box";
  63. bool multiTextBoxEditMode = false;
  64. bool forceSquaredChecked = false;
  65. //----------------------------------------------------------------------------------
  66. // Custom GUI font loading
  67. //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
  68. //GuiFont(font);
  69. SetTargetFPS(60);
  70. //--------------------------------------------------------------------------------------
  71. // Main game loop
  72. while (!WindowShouldClose()) // Detect window close button or ESC key
  73. {
  74. // Update
  75. //----------------------------------------------------------------------------------
  76. // TODO: Implement required update logic
  77. //----------------------------------------------------------------------------------
  78. // Draw
  79. //----------------------------------------------------------------------------------
  80. BeginDrawing();
  81. ClearBackground(GetColor(style[DEFAULT_BACKGROUND_COLOR]));
  82. // raygui: controls drawing
  83. //----------------------------------------------------------------------------------
  84. if (dropDown000EditMode || dropDown001EditMode) GuiLock();
  85. //GuiDisable();
  86. // First GUI column
  87. forceSquaredChecked = GuiCheckBoxEx((Rectangle){ 25, 108, 15, 15 }, forceSquaredChecked, "Force Square");
  88. if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, 25, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
  89. if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
  90. if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
  91. if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "SAMPLE TEXT")) { }
  92. // NOTE: GuiDropdownBox must draw at the end of the column
  93. if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, dropdownBox001TextList, 5, &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
  94. if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, dropdownBox000TextList, 3, &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
  95. // Second GUI column
  96. if (GuiListView((Rectangle){ 185, 25, 120, 100 }, listViewList, 6, &listViewScrollIndex, &listViewActive, listViewEditMode)) listViewEditMode = !listViewEditMode;
  97. if (GuiListViewEx((Rectangle){ 185, 155, 120, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
  98. if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(listViewExList[listViewExFocus], 195, 370, 20, RED);
  99. // Third GUI column
  100. if (GuiTextBoxMulti((Rectangle){ 325, 25, 225, 175 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
  101. //GuiEnable();
  102. GuiUnlock();
  103. // Fourth GUI column
  104. GuiLock();
  105. GuiState(GUI_STATE_NORMAL); if (GuiButton((Rectangle){ 600, 25, 125, 30 }, "NORMAL")) { }
  106. GuiState(GUI_STATE_FOCUSED); if (GuiButton((Rectangle){ 600, 65, 125, 30 }, "FOCUSED")) { }
  107. GuiState(GUI_STATE_PRESSED); if (GuiButton((Rectangle){ 600, 105, 125, 30 }, "PRESSED")) { }
  108. GuiState(GUI_STATE_DISABLED); if (GuiButton((Rectangle){ 600, 145, 125, 30 }, "DISABLED")) { }
  109. GuiState(GUI_STATE_NORMAL);
  110. GuiUnlock();
  111. //----------------------------------------------------------------------------------
  112. EndDrawing();
  113. //----------------------------------------------------------------------------------
  114. }
  115. // De-Initialization
  116. //--------------------------------------------------------------------------------------
  117. CloseWindow(); // Close window and OpenGL context
  118. //--------------------------------------------------------------------------------------
  119. return 0;
  120. }