controls_test_suite.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 = 690;
  36. int screenHeight = 560;
  37. InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
  38. SetExitKey(0);
  39. // GUI controls initialization
  40. //----------------------------------------------------------------------------------
  41. int dropdownBox000Active = 0;
  42. bool dropDown000EditMode = false;
  43. int dropdownBox001Active = 0;
  44. bool dropDown001EditMode = false;
  45. int spinner001Value = 0;
  46. bool spinnerEditMode = false;
  47. int valueBox002Value = 0;
  48. bool valueBoxEditMode = false;
  49. char textBoxText[64] = "Text box";
  50. bool textBoxEditMode = false;
  51. int listViewScrollIndex = 0;
  52. int listViewActive = -1;
  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. Vector2 viewScroll = { 0, 0 };
  70. //----------------------------------------------------------------------------------
  71. // Custom GUI font loading
  72. //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
  73. //GuiFont(font);
  74. bool exitWindow = false;
  75. bool showMessageBox = false;
  76. SetTargetFPS(60);
  77. //--------------------------------------------------------------------------------------
  78. // Main game loop
  79. while (!exitWindow) // Detect window close button or ESC key
  80. {
  81. // Update
  82. //----------------------------------------------------------------------------------
  83. exitWindow = WindowShouldClose();
  84. if (IsKeyPressed(KEY_ESCAPE)) showMessageBox = !showMessageBox;
  85. //----------------------------------------------------------------------------------
  86. // Draw
  87. //----------------------------------------------------------------------------------
  88. BeginDrawing();
  89. ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
  90. // raygui: controls drawing
  91. //----------------------------------------------------------------------------------
  92. if (dropDown000EditMode || dropDown001EditMode) GuiLock();
  93. //GuiDisable();
  94. // First GUI column
  95. forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "Force Square", forceSquaredChecked);
  96. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
  97. if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
  98. if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
  99. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT);
  100. if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
  101. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT);
  102. if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "#04#SAMPLE TEXT")) { };
  103. GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "STATES");
  104. GuiLock();
  105. GuiState(GUI_STATE_NORMAL); if (GuiButton((Rectangle){ 30, 320, 115, 30 }, "NORMAL")) { }
  106. GuiState(GUI_STATE_FOCUSED); if (GuiButton((Rectangle){ 30, 355, 115, 30 }, "FOCUSED")) { }
  107. GuiState(GUI_STATE_PRESSED); if (GuiButton((Rectangle){ 30, 390, 115, 30 }, "#15#PRESSED")) { }
  108. GuiState(GUI_STATE_DISABLED); if (GuiButton((Rectangle){ 30, 425, 115, 30 }, "DISABLED")) { }
  109. GuiState(GUI_STATE_NORMAL);
  110. GuiUnlock();
  111. comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive);
  112. // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
  113. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT);
  114. if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, "#01#ONE;#02#TWO;#03#THREE;#04#FOUR", &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
  115. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
  116. if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
  117. // Second GUI column
  118. if (GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewActive, &listViewScrollIndex, listViewEditMode)) listViewEditMode = !listViewEditMode;
  119. if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, listViewExElementsEnable, &listViewExActive, &listViewExFocus, &listViewExScrollIndex, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
  120. if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 385, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON);
  121. toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive);
  122. // Third GUI column
  123. if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
  124. colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
  125. sliderValue = GuiSlider((Rectangle){ 370, 400, 200, 20 }, "#49#TEST", sliderValue, -50, 100, true);
  126. sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, sliderBarValue, 0, 100, true);
  127. progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, progressValue, 0, 1, true);
  128. Rectangle view = GuiScrollPanel((Rectangle){ 560, 25, 100, 160 }, (Rectangle){ 560, 25, 100, 400 }, &viewScroll);
  129. GuiSetStyle(DEFAULT, INNER_PADDING, 10);
  130. GuiStatusBar((Rectangle){ 0, GetScreenHeight() - 20, GetScreenWidth(), 20 }, "This is a status bar");
  131. GuiSetStyle(DEFAULT, INNER_PADDING, 2);
  132. if (showMessageBox)
  133. {
  134. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f));
  135. int message = GuiMessageBox((Rectangle){ GetScreenWidth()/2 - 125, GetScreenHeight()/2 - 50, 250, 100 }, GuiIconText(RICON_EXIT, "Closing rTexPacker"), "Do you really want to exit?", "Yes;No");
  136. if ((message == 0) || (message == 2)) showMessageBox = false;
  137. else if (message == 1) exitWindow = true;
  138. }
  139. //GuiEnable();
  140. GuiUnlock();
  141. //----------------------------------------------------------------------------------
  142. EndDrawing();
  143. //----------------------------------------------------------------------------------
  144. }
  145. // De-Initialization
  146. //--------------------------------------------------------------------------------------
  147. CloseWindow(); // Close window and OpenGL context
  148. //--------------------------------------------------------------------------------------
  149. return 0;
  150. }