controls_test_suite.bmx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. SuperStrict
  2. Framework Ray.GUI
  3. Import Text.Format
  4. Import BRL.FileSystem
  5. Local formatter:TFormatter = TFormatter.Create("%2.2f")
  6. ' Initialization
  7. '---------------------------------------------------------------------------------------
  8. Local screenWidth:Int = 690
  9. Local screenHeight:Int = 560
  10. InitWindow(screenWidth, screenHeight, "raygui - controls test suite")
  11. SetExitKey(0)
  12. ' GUI controls initialization
  13. '----------------------------------------------------------------------------------
  14. Local dropdownBox000Active:Int = 0
  15. Local dropDown000EditMode:Int = False
  16. Local dropdownBox001Active:Int = 0
  17. Local dropDown001EditMode:Int = False
  18. Local spinner001Value:Int = 0
  19. Local spinnerEditMode:Int = False
  20. Local valueBox002Value:Int = 0
  21. Local valueBoxEditMode:Int = False
  22. Local textBoxText:String = "Text box"
  23. Local textBoxEditMode:Int = False
  24. Local listViewScrollIndex:Int = 0
  25. Local listViewActive:Int = -1
  26. Local listViewExScrollIndex:Int = 0
  27. Local listViewExActive:Int = 2
  28. Local listViewExFocus:Int = -1
  29. Local listViewExList:String[] = ["This", "is", "a", "list view", "with", "disable", "elements", "amazing!"]
  30. Local multiTextBoxText:String = "Multi text box"
  31. Local multiTextBoxEditMode:Int = False
  32. Local colorPickerValue:RColor = RED
  33. Local SliderValue:Int = 50
  34. Local sliderBarValue:Int = 60
  35. Local progressValue:Float = 0.4
  36. Local forceSquaredChecked:Int = False
  37. Local alphaValue:Float = 0.5
  38. Local comboBoxActive:Int = 1
  39. Local toggleGroupActive:Int = 0
  40. Local viewScroll:RVector2
  41. '----------------------------------------------------------------------------------
  42. ' Custom GUI font loading
  43. 'Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0)
  44. 'GuiSetFont(font)
  45. Local exitWindow:Int = False
  46. Local showMessageBox:Int = False
  47. Local textInput:String
  48. Local showTextInputBox:Int = False
  49. Local textInputFileName:String
  50. SetTargetFPS(60)
  51. '--------------------------------------------------------------------------------------
  52. ' Main game loop
  53. While Not exitWindow ' Detect window close button or ESC key
  54. ' Update
  55. '----------------------------------------------------------------------------------
  56. exitWindow = WindowShouldClose()
  57. If IsKeyPressed(KEY_ESCAPE) Then
  58. showMessageBox = Not showMessageBox
  59. End If
  60. If IsKeyDown(KEY_LEFT_CONTROL) And IsKeyPressed(KEY_S) Then
  61. showTextInputBox = True
  62. End If
  63. If IsFileDropped() Then
  64. Local droppedFiles:String[] = GetDroppedFiles()
  65. If droppedFiles.length And ExtractExt(droppedFiles[0]) = "rgs" Then
  66. GuiLoadStyle(droppedFiles[0])
  67. End If
  68. End If
  69. '----------------------------------------------------------------------------------
  70. ' Draw
  71. '----------------------------------------------------------------------------------
  72. BeginDrawing()
  73. ClearBackground(GetColor(GuiGetStyle(GUI_DEFAULT, BACKGROUND_COLOR)))
  74. ' raygui: controls drawing
  75. '----------------------------------------------------------------------------------
  76. If dropDown000EditMode Or dropDown001EditMode Then
  77. GuiLock()
  78. End If
  79. 'GuiDisable()
  80. ' First GUI column
  81. 'GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT)
  82. forceSquaredChecked = GuiCheckBox(New RRectangle(25, 108, 15, 15), "FORCE CHECK!", forceSquaredChecked)
  83. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER)
  84. 'GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT)
  85. If GuiSpinner(New RRectangle(25, 135, 125, 30), Null, spinner001Value, 0, 100, spinnerEditMode) Then
  86. spinnerEditMode = Not spinnerEditMode
  87. End If
  88. If GuiValueBox(New RRectangle(25, 175, 125, 30), Null, valueBox002Value, 0, 100, valueBoxEditMode) Then
  89. valueBoxEditMode = Not valueBoxEditMode
  90. End If
  91. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT)
  92. If GuiTextBox(New RRectangle(25, 215, 125, 30), textBoxText, 64, textBoxEditMode) Then
  93. textBoxEditMode = Not textBoxEditMode
  94. End If
  95. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER)
  96. If GuiButton(New RRectangle(25, 255, 125, 30), GuiIconText(RICON_FILE_SAVE, "Save File")) Then
  97. showTextInputBox = True
  98. End If
  99. GuiGroupBox(New RRectangle(25, 310, 125, 150), "STATES")
  100. GuiLock()
  101. GuiSetState(GUI_STATE_NORMAL)
  102. If GuiButton(New RRectangle(30, 320, 115, 30), "NORMAL") Then
  103. ' ...
  104. End If
  105. GuiSetState(GUI_STATE_FOCUSED)
  106. If GuiButton(New RRectangle(30, 355, 115, 30), "FOCUSED") Then
  107. ' ...
  108. End If
  109. GuiSetState(GUI_STATE_PRESSED)
  110. If GuiButton(New RRectangle(30, 390, 115, 30), "#15#PRESSED") Then
  111. ' ...
  112. End If
  113. GuiSetState(GUI_STATE_DISABLED)
  114. If GuiButton(New RRectangle(30, 425, 115, 30), "DISABLED") Then
  115. ' ...
  116. End If
  117. GuiSetState(GUI_STATE_NORMAL)
  118. GuiUnlock()
  119. comboBoxActive = GuiComboBox(New RRectangle(25, 470, 125, 30), "ONE;TWO;THREE;FOUR;", comboBoxActive)
  120. ' NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
  121. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT)
  122. If GuiDropdownBox(New RRectangle(25, 65, 125, 30), "#01#ONE;#02#TWO;#03#THREE;#04#FOUR;", dropdownBox001Active, dropDown001EditMode) Then
  123. dropDown001EditMode = Not dropDown001EditMode
  124. End If
  125. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER)
  126. If GuiDropdownBox(New RRectangle(25, 25, 125, 30), "ONE;TWO;THREE;", dropdownBox000Active, dropDown000EditMode) Then
  127. dropDown000EditMode = Not dropDown000EditMode
  128. End If
  129. ' Second GUI column
  130. listViewActive = GuiListView(New RRectangle(165, 25, 140, 140), "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey;", listViewScrollIndex, listViewActive)
  131. listViewExActive = GuiListViewEx(New RRectangle(165, 180, 140, 200), listViewExList, listViewExFocus, listViewExScrollIndex, listViewExActive)
  132. toggleGroupActive = GuiToggleGroup(New RRectangle(165, 400, 140, 25), "#1#ONE~n#3#TWO~n#8#THREE~n#23#", toggleGroupActive)
  133. ' Third GUI column
  134. If GuiTextBoxMulti(New RRectangle(320, 25, 225, 140), multiTextBoxText, 141, multiTextBoxEditMode) Then
  135. multiTextBoxEditMode = Not multiTextBoxEditMode
  136. End If
  137. colorPickerValue = GuiColorPicker(New RRectangle(320, 185, 196, 192), colorPickerValue)
  138. SliderValue = GuiSlider(New RRectangle(355, 400, 165, 20), "TEST", formatter.Clear().Arg(Float(SliderValue)).Format(), SliderValue, -50, 100)
  139. sliderBarValue = GuiSliderBar(New RRectangle(320, 430, 200, 20), Null, Int(sliderBarValue), sliderBarValue, 0, 100)
  140. progressValue = GuiProgressBar(New RRectangle(320, 460, 200, 20), Null, Null, progressValue, 0, 1)
  141. ' NOTE: View rectangle could be used to perform some scissor test
  142. Local view:RRectangle = GuiScrollPanel(New RRectangle(560, 25, 100, 160), New RRectangle(560, 25, 200, 400), viewScroll)
  143. GuiStatusBar(New RRectangle(0, GetScreenHeight() - 20, GetScreenWidth(), 20), "This is a status bar")
  144. alphaValue = GuiColorBarAlpha(New RRectangle(320, 490, 200, 30), alphaValue)
  145. If showMessageBox Then
  146. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8))
  147. Local result:Int = GuiMessageBox(New RRectangle(GetScreenWidth()/2 - 125, GetScreenHeight()/2 - 50, 250, 100), GuiIconText(RICON_EXIT, "Close Window"), "Do you really want to exit?", "Yes;No")
  148. If (result = 0) Or (result = 2) Then
  149. showMessageBox = False
  150. Else If result = 1 Then
  151. exitWindow = True
  152. End If
  153. End If
  154. If showTextInputBox Then
  155. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8))
  156. Local result:Int = GuiTextInputBox(New RRectangle(GetScreenWidth()/2 - 120, GetScreenHeight()/2 - 60, 240, 140), GuiIconText(RICON_FILE_SAVE, "Save file as..."), "Introduce a save file name", "Ok;Cancel", textInput)
  157. If result = 1 Then
  158. ' TODO: Validate textInput value and save
  159. textInputFileName = textInput
  160. End If
  161. If (result = 0) Or (result = 1) Or (result = 2) Then
  162. showTextInputBox = False
  163. textInput = Null
  164. End If
  165. End If
  166. GuiUnlock()
  167. '----------------------------------------------------------------------------------
  168. EndDrawing()
  169. '----------------------------------------------------------------------------------
  170. Wend
  171. ' De-Initialization
  172. '--------------------------------------------------------------------------------------
  173. CloseWindow() ' Close window and OpenGL context
  174. '--------------------------------------------------------------------------------------