controls_test_suite.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 = 600;
  36. int screenHeight = 600;
  37. InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
  38. // GUI controls initialization
  39. //----------------------------------------------------------------------------------
  40. int dropdownBox000Active = 0;
  41. bool dropDown000EditMode = false;
  42. int dropdownBox001Active = 0;
  43. bool dropDown001EditMode = false;
  44. int spinner001Value = 0;
  45. bool spinnerEditMode = false;
  46. int valueBox002Value = 0;
  47. bool valueBoxEditMode = false;
  48. char textBoxText[64] = "Text box";
  49. bool textBoxEditMode = false;
  50. int listViewScrollIndex = 0;
  51. int listViewActive = -1;
  52. const char *listViewList[6] = { "Charmander", "Bulbasaur", "Squirtel", "Pikachu", "Eevee", "Pidgey" };
  53. bool listViewEditMode = false;
  54. int listViewExScrollIndex = 0;
  55. int listViewExActive = -1;
  56. int listViewExFocus = -1;
  57. const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
  58. int listViewExElementsEnable[8] = {1, 0, 1, 1, 0, 0, 1};
  59. bool listViewExEditMode = false;
  60. char multiTextBoxText[141] = "Multi text box";
  61. bool multiTextBoxEditMode = false;
  62. Color colorPickerValue = RED;
  63. int sliderValue = 50;
  64. int sliderBarValue = 60;
  65. float progressValue = 0.4f;
  66. bool forceSquaredChecked = false;
  67. int comboBoxActive = 1;
  68. int toggleGroupActive = 0;
  69. //----------------------------------------------------------------------------------
  70. // Custom GUI font loading
  71. //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
  72. //GuiFont(font);
  73. SetTargetFPS(60);
  74. //--------------------------------------------------------------------------------------
  75. // Main game loop
  76. while (!WindowShouldClose()) // Detect window close button or ESC key
  77. {
  78. // Update
  79. //----------------------------------------------------------------------------------
  80. // TODO: Implement required update logic
  81. //----------------------------------------------------------------------------------
  82. // Draw
  83. //----------------------------------------------------------------------------------
  84. BeginDrawing();
  85. ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
  86. // raygui: controls drawing
  87. //----------------------------------------------------------------------------------
  88. if (dropDown000EditMode || dropDown001EditMode) GuiLock();
  89. //GuiDisable();
  90. // First GUI column
  91. forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "Force Square", forceSquaredChecked);
  92. if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, 25, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
  93. if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
  94. if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
  95. if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "SAMPLE TEXT")) { }
  96. GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "CONTROL STATES");
  97. GuiLock();
  98. GuiState(GUI_STATE_NORMAL); if (GuiButton((Rectangle){ 30, 320, 115, 30 }, "NORMAL")) { }
  99. GuiState(GUI_STATE_FOCUSED); if (GuiButton((Rectangle){ 30, 355, 115, 30 }, "FOCUSED")) { }
  100. GuiState(GUI_STATE_PRESSED); if (GuiButton((Rectangle){ 30, 390, 115, 30 }, "PRESSED")) { }
  101. GuiState(GUI_STATE_DISABLED); if (GuiButton((Rectangle){ 30, 425, 115, 30 }, "DISABLED")) { }
  102. GuiState(GUI_STATE_NORMAL);
  103. GuiUnlock();
  104. comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive);
  105. // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
  106. if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, "ONE;TWO;THREE;FOUR", &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
  107. if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
  108. // Second GUI column
  109. if (GuiListView((Rectangle){ 165, 25, 140, 140 }, listViewList, 6, &listViewScrollIndex, &listViewActive, listViewEditMode)) listViewEditMode = !listViewEditMode;
  110. if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
  111. if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 390, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON);
  112. toggleGroupActive = GuiToggleGroupEx((Rectangle){ 165, 400, 140, 25 }, "ONE;TWO;THREE;FOUR", toggleGroupActive, 4, 1);
  113. // Third GUI column
  114. if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
  115. colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
  116. sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, -50, 100, " ", true);
  117. sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, " ", true);
  118. progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true);
  119. //GuiEnable();
  120. GuiUnlock();
  121. //----------------------------------------------------------------------------------
  122. EndDrawing();
  123. //----------------------------------------------------------------------------------
  124. }
  125. // De-Initialization
  126. //--------------------------------------------------------------------------------------
  127. CloseWindow(); // Close window and OpenGL context
  128. //--------------------------------------------------------------------------------------
  129. return 0;
  130. }