controls_test_suite.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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) 2019 raylib technologies (@raylibtech)
  23. *
  24. **********************************************************************************************/
  25. #include "raylib.h"
  26. #define RAYGUI_IMPLEMENTATION
  27. #define RAYGUI_RICONS_SUPPORT
  28. #include "../../src/raygui.h"
  29. //------------------------------------------------------------------------------------
  30. // Program main entry point
  31. //------------------------------------------------------------------------------------
  32. int main()
  33. {
  34. // Initialization
  35. //---------------------------------------------------------------------------------------
  36. int screenWidth = 690;
  37. int screenHeight = 560;
  38. InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
  39. SetExitKey(0);
  40. // GUI controls initialization
  41. //----------------------------------------------------------------------------------
  42. int dropdownBox000Active = 0;
  43. bool dropDown000EditMode = false;
  44. int dropdownBox001Active = 0;
  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 = 0;
  53. int listViewActive = -1;
  54. bool listViewEditMode = false;
  55. int listViewExScrollIndex = 0;
  56. int listViewExActive = -1;
  57. int listViewExFocus = -1;
  58. const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
  59. int listViewExElementsEnable[8] = {1, 0, 1, 1, 0, 0, 1};
  60. bool listViewExEditMode = false;
  61. char multiTextBoxText[141] = "Multi text box";
  62. bool multiTextBoxEditMode = false;
  63. Color colorPickerValue = RED;
  64. int sliderValue = 50;
  65. int sliderBarValue = 60;
  66. float progressValue = 0.4f;
  67. bool forceSquaredChecked = false;
  68. float alphaValue = 0.5f;
  69. int comboBoxActive = 1;
  70. int toggleGroupActive = 0;
  71. Vector2 viewScroll = { 0, 0 };
  72. //----------------------------------------------------------------------------------
  73. // Custom GUI font loading
  74. //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
  75. //GuiFont(font);
  76. bool exitWindow = false;
  77. bool showMessageBox = false;
  78. SetTargetFPS(60);
  79. //--------------------------------------------------------------------------------------
  80. // Main game loop
  81. while (!exitWindow) // Detect window close button or ESC key
  82. {
  83. // Update
  84. //----------------------------------------------------------------------------------
  85. exitWindow = WindowShouldClose();
  86. if (IsKeyPressed(KEY_ESCAPE)) showMessageBox = !showMessageBox;
  87. if (IsFileDropped())
  88. {
  89. int dropsCount = 0;
  90. char **droppedFiles = GetDroppedFiles(&dropsCount);
  91. if ((dropsCount > 0) && IsFileExtension(droppedFiles[0], ".rgs")) GuiLoadStyle(droppedFiles[0]);
  92. ClearDroppedFiles(); // Clear internal buffers
  93. }
  94. //----------------------------------------------------------------------------------
  95. // Draw
  96. //----------------------------------------------------------------------------------
  97. BeginDrawing();
  98. ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
  99. // raygui: controls drawing
  100. //----------------------------------------------------------------------------------
  101. if (dropDown000EditMode || dropDown001EditMode) GuiLock();
  102. //GuiDisable();
  103. // First GUI column
  104. forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "Force Square", forceSquaredChecked);
  105. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
  106. if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
  107. if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
  108. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT);
  109. if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
  110. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
  111. //if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "#05#Open File")) { };
  112. if (GuiButton((Rectangle){ 25, 255, 125, 30 }, GuiIconText(RICON_FILE_OPEN, "Open File"))) { };
  113. GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "STATES");
  114. GuiLock();
  115. GuiState(GUI_STATE_NORMAL); if (GuiButton((Rectangle){ 30, 320, 115, 30 }, "NORMAL")) { }
  116. GuiState(GUI_STATE_FOCUSED); if (GuiButton((Rectangle){ 30, 355, 115, 30 }, "FOCUSED")) { }
  117. GuiState(GUI_STATE_PRESSED); if (GuiButton((Rectangle){ 30, 390, 115, 30 }, "#15#PRESSED")) { }
  118. GuiState(GUI_STATE_DISABLED); if (GuiButton((Rectangle){ 30, 425, 115, 30 }, "DISABLED")) { }
  119. GuiState(GUI_STATE_NORMAL);
  120. GuiUnlock();
  121. comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive);
  122. // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
  123. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT);
  124. if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, "#01#ONE;#02#TWO;#03#THREE;#04#FOUR", &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
  125. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
  126. if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
  127. // Second GUI column
  128. if (GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewActive, &listViewScrollIndex, listViewEditMode)) listViewEditMode = !listViewEditMode;
  129. if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, listViewExElementsEnable, &listViewExActive, &listViewExFocus, &listViewExScrollIndex, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
  130. //if ((listViewExFocus >= 0) && (listViewExFocus < 8)) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 385, 10, (listViewExElementsEnable[listViewExFocus] > 0)? LIME : MAROON);
  131. toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive);
  132. // Third GUI column
  133. if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
  134. colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
  135. sliderValue = GuiSlider((Rectangle){ 370, 400, 200, 20 }, "#49#TEST", sliderValue, -50, 100, true);
  136. sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, sliderBarValue, 0, 100, true);
  137. progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, progressValue, 0, 1, true);
  138. Rectangle view = GuiScrollPanel((Rectangle){ 560, 25, 100, 160 }, (Rectangle){ 560, 25, 200, 400 }, &viewScroll);
  139. GuiSetStyle(DEFAULT, INNER_PADDING, 10);
  140. GuiStatusBar((Rectangle){ 0, GetScreenHeight() - 20, GetScreenWidth(), 20 }, "This is a status bar");
  141. GuiSetStyle(DEFAULT, INNER_PADDING, 2);
  142. alphaValue = GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, alphaValue);
  143. if (showMessageBox)
  144. {
  145. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f));
  146. 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");
  147. if ((message == 0) || (message == 2)) showMessageBox = false;
  148. else if (message == 1) exitWindow = true;
  149. }
  150. //GuiEnable();
  151. GuiUnlock();
  152. //----------------------------------------------------------------------------------
  153. EndDrawing();
  154. //----------------------------------------------------------------------------------
  155. }
  156. // De-Initialization
  157. //--------------------------------------------------------------------------------------
  158. CloseWindow(); // Close window and OpenGL context
  159. //--------------------------------------------------------------------------------------
  160. return 0;
  161. }