2023-06-02 06:03:36 +00:00
// Initialization
2023-06-03 07:15:38 +00:00
//---------------------------------------------------------------------------------------
let screenWidth = 690 ;
let screenHeight = 560 ;
2023-06-02 06:03:36 +00:00
initWindow ( screenWidth , screenHeight , "raygui - controls test suite" ) ;
setExitKey ( 0 ) ;
// GUI controls initialization
//----------------------------------------------------------------------------------
2023-06-03 07:15:38 +00:00
let dropdownBox000Active = { active : 0 } ;
2023-06-02 06:03:36 +00:00
let dropDown000EditMode = false ;
2023-06-03 07:15:38 +00:00
let dropdownBox001Active = { active : 0 } ;
2023-06-02 06:03:36 +00:00
let dropDown001EditMode = false ;
2023-06-03 07:15:38 +00:00
let spinner001Value = { value : 0 } ;
2023-06-02 06:03:36 +00:00
let spinnerEditMode = false ;
2023-06-03 07:15:38 +00:00
let valueBox002Value = { value : 0 } ;
2023-06-02 06:03:36 +00:00
let valueBoxEditMode = false ;
2023-06-04 11:41:18 +00:00
let textBoxText = { text : "Text box" } ;
2023-06-02 06:03:36 +00:00
let textBoxEditMode = false ;
2023-06-03 07:15:38 +00:00
let listViewScrollIndex = { scrollIndex : 0 } ;
2023-06-02 06:03:36 +00:00
let listViewActive = - 1 ;
let listViewExScrollIndex = 0 ;
let listViewExActive = 2 ;
let listViewExFocus = - 1 ;
let listViewExList = [ "This" , "is" , "a" , "list view" , "with" , "disable" , "elements" , "amazing!" ] ;
let multiTextBoxText = "Multi text box" ;
let multiTextBoxEditMode = false ;
let colorPickerValue = RED ;
2023-06-03 07:15:38 +00:00
let sliderValue = 50 ;
2023-06-02 06:03:36 +00:00
let sliderBarValue = 60 ;
let progressValue = 0.4 ;
let forceSquaredChecked = false ;
let alphaValue = 0.5 ;
let comboBoxActive = 1 ;
let toggleGroupActive = 0 ;
2023-06-03 07:15:38 +00:00
let viewScroll = new Vector2 ( 0 , 0 ) ;
2023-06-02 06:03:36 +00:00
//----------------------------------------------------------------------------------
// Custom GUI font loading
2023-06-03 07:15:38 +00:00
//let font = loadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
//guiSetFont(font);
2023-06-02 06:03:36 +00:00
let exitWindow = false ;
let showMessageBox = false ;
2023-06-04 20:31:15 +00:00
let textInput = { text : "" } ;
2023-06-02 06:03:36 +00:00
let showTextInputBox = false ;
2023-06-03 07:15:38 +00:00
let textInputFileName = "" ;
2023-06-02 06:03:36 +00:00
setTargetFPS ( 60 ) ;
//--------------------------------------------------------------------------------------
// Main game loop
while ( ! exitWindow ) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
exitWindow = windowShouldClose ( ) ;
if ( isKeyPressed ( KEY _ESCAPE ) ) showMessageBox = ! showMessageBox ;
if ( isKeyDown ( KEY _LEFT _CONTROL ) && isKeyPressed ( KEY _S ) ) showTextInputBox = true ;
if ( isFileDropped ( ) )
{
2023-06-03 07:15:38 +00:00
let droppedFiles = loadDroppedFiles ( ) ;
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
if ( ( droppedFiles . length > 0 ) && isFileExtension ( droppedFiles [ 0 ] , ".rgs" ) ) guiLoadStyle ( droppedFiles [ 0 ] ) ;
2023-06-02 06:03:36 +00:00
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
beginDrawing ( ) ;
clearBackground ( getColor ( guiGetStyle ( DEFAULT , BACKGROUND _COLOR ) ) ) ;
// raygui: controls drawing
//----------------------------------------------------------------------------------
// Check all possible events that require GuiLock
if ( dropDown000EditMode ||
dropDown001EditMode ) guiLock ( ) ;
// First GUI column
2023-06-03 07:15:38 +00:00
//guiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
forceSquaredChecked = guiCheckBox ( new Rectangle ( 25 , 108 , 15 , 15 ) , "FORCE CHECK!" , forceSquaredChecked ) ;
2023-06-02 06:03:36 +00:00
guiSetStyle ( TEXTBOX , TEXT _ALIGNMENT , TEXT _ALIGN _CENTER ) ;
2023-06-03 07:15:38 +00:00
//guiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
if ( guiSpinner ( new Rectangle ( 25 , 135 , 125 , 30 ) , null , spinner001Value , 0 , 100 , spinnerEditMode ) ) spinnerEditMode = ! spinnerEditMode ;
if ( guiValueBox ( new Rectangle ( 25 , 175 , 125 , 30 ) , null , valueBox002Value , 0 , 100 , valueBoxEditMode ) ) valueBoxEditMode = ! valueBoxEditMode ;
2023-06-02 06:03:36 +00:00
guiSetStyle ( TEXTBOX , TEXT _ALIGNMENT , TEXT _ALIGN _LEFT ) ;
2023-06-04 20:31:15 +00:00
if ( guiTextBox ( new Rectangle ( 25 , 215 , 125 , 30 ) , textBoxText , textBoxEditMode ) ) textBoxEditMode = ! textBoxEditMode ;
2023-06-02 06:03:36 +00:00
guiSetStyle ( BUTTON , TEXT _ALIGNMENT , TEXT _ALIGN _CENTER ) ;
2023-06-03 07:15:38 +00:00
if ( guiButton ( new Rectangle ( 25 , 255 , 125 , 30 ) , guiIconText ( ICON _FILE _SAVE , "Save File" ) ) ) showTextInputBox = true ;
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
guiGroupBox ( new Rectangle ( 25 , 310 , 125 , 150 ) , "STATES" ) ;
//guiLock();
2023-06-02 06:03:36 +00:00
guiSetState ( STATE _NORMAL ) ; if ( guiButton ( new Rectangle ( 30 , 320 , 115 , 30 ) , "NORMAL" ) ) { }
guiSetState ( STATE _FOCUSED ) ; if ( guiButton ( new Rectangle ( 30 , 355 , 115 , 30 ) , "FOCUSED" ) ) { }
guiSetState ( STATE _PRESSED ) ; if ( guiButton ( new Rectangle ( 30 , 390 , 115 , 30 ) , "#15#PRESSED" ) ) { }
guiSetState ( STATE _DISABLED ) ; if ( guiButton ( new Rectangle ( 30 , 425 , 115 , 30 ) , "DISABLED" ) ) { }
guiSetState ( STATE _NORMAL ) ;
2023-06-03 07:15:38 +00:00
//guiUnlock();
2023-06-02 06:03:36 +00:00
comboBoxActive = guiComboBox ( new Rectangle ( 25 , 470 , 125 , 30 ) , "ONE;TWO;THREE;FOUR" , comboBoxActive ) ;
// NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
2023-06-03 07:15:38 +00:00
guiUnlock ( ) ;
guiSetStyle ( DROPDOWNBOX , TEXT _ALIGNMENT , TEXT _ALIGN _LEFT ) ;
if ( guiDropdownBox ( new Rectangle ( 25 , 65 , 125 , 30 ) , "#01#ONE;#02#TWO;#03#THREE;#04#FOUR" , dropdownBox001Active , dropDown001EditMode ) ) dropDown001EditMode = ! dropDown001EditMode ;
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
guiSetStyle ( DROPDOWNBOX , TEXT _ALIGNMENT , TEXT _ALIGN _CENTER ) ;
if ( guiDropdownBox ( new Rectangle ( 25 , 25 , 125 , 30 ) , "ONE;TWO;THREE" , dropdownBox000Active , dropDown000EditMode ) ) dropDown000EditMode = ! dropDown000EditMode ;
2023-06-02 06:03:36 +00:00
// Second GUI column
2023-06-03 07:15:38 +00:00
listViewActive = guiListView ( new Rectangle ( 165 , 25 , 140 , 140 ) , "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey" , listViewScrollIndex , listViewActive ) ;
//listViewExActive = guiListViewEx(new Rectangle(165, 180, 140, 200), listViewExList, 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive);
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
toggleGroupActive = guiToggleGroup ( new Rectangle ( 165 , 400 , 140 , 25 ) , "#1#ONE\n#3#TWO\n#8#THREE\n#23#" , toggleGroupActive ) ;
2023-06-02 06:03:36 +00:00
// Third GUI column
2023-06-03 07:15:38 +00:00
guiPanel ( new Rectangle ( 320 , 25 , 225 , 140 ) , "Panel Info" ) ;
colorPickerValue = guiColorPicker ( new Rectangle ( 320 , 185 , 196 , 192 ) , null , colorPickerValue ) ;
2023-06-02 06:03:36 +00:00
2023-06-03 21:35:35 +00:00
sliderValue = guiSlider ( new Rectangle ( 355 , 400 , 165 , 20 ) , "TEST" , Math . floor ( sliderValue ) , sliderValue , - 50 , 100 ) ;
sliderBarValue = guiSliderBar ( new Rectangle ( 320 , 430 , 200 , 20 ) , null , Math . floor ( sliderBarValue ) , sliderBarValue , 0 , 100 ) ;
2023-06-03 07:15:38 +00:00
progressValue = guiProgressBar ( new Rectangle ( 320 , 460 , 200 , 20 ) , null , null , progressValue , 0 , 1 ) ;
2023-06-02 06:03:36 +00:00
// NOTE: View rectangle could be used to perform some scissor test
2023-06-03 07:15:38 +00:00
let view = guiScrollPanel ( new Rectangle ( 560 , 25 , 102 , 354 ) , null , new Rectangle ( 560 , 25 , 300 , 1200 ) , viewScroll ) ;
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
guiGrid ( new Rectangle ( 560 , 25 + 180 + 195 , 100 , 120 ) , null , 20 , 2 ) ;
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
guiStatusBar ( new Rectangle ( 0 , getScreenHeight ( ) - 20 , getScreenWidth ( ) , 20 ) , "This is a status bar" ) ;
2023-06-02 06:03:36 +00:00
2023-06-03 07:15:38 +00:00
alphaValue = guiColorBarAlpha ( new Rectangle ( 320 , 490 , 200 , 30 ) , null , alphaValue ) ;
2023-06-02 06:03:36 +00:00
if ( showMessageBox )
{
2023-06-03 07:15:38 +00:00
drawRectangle ( 0 , 0 , getScreenWidth ( ) , getScreenHeight ( ) , fade ( RAYWHITE , 0.8 ) ) ;
let result = guiMessageBox ( new Rectangle ( getScreenWidth ( ) / 2 - 125 , getScreenHeight ( ) / 2 - 50 , 250 , 100 ) , guiIconText ( ICON _EXIT , "Close Window" ) , "Do you really want to exit?" , "Yes;No" ) ;
2023-06-02 06:03:36 +00:00
if ( ( result == 0 ) || ( result == 2 ) ) showMessageBox = false ;
else if ( result == 1 ) exitWindow = true ;
}
2023-06-04 20:31:15 +00:00
if ( showTextInputBox )
{
drawRectangle ( 0 , 0 , getScreenWidth ( ) , getScreenHeight ( ) , fade ( RAYWHITE , 0.8 ) ) ;
let result = guiTextInputBox ( new Rectangle ( getScreenWidth ( ) / 2 - 120 , getScreenHeight ( ) / 2 - 60 , 240 , 140 ) , "Save" , guiIconText ( ICON _FILE _SAVE , "Save file as..." ) , "Ok;Cancel" , textInput , null ) ;
if ( result == 1 )
{
// TODO: Validate textInput value and save
textInputFileName = textInput . text
}
if ( ( result == 0 ) || ( result == 1 ) || ( result == 2 ) )
{
showTextInputBox = false ;
textInput . text = ""
}
}
2023-06-02 06:03:36 +00:00
//----------------------------------------------------------------------------------
2023-06-03 07:15:38 +00:00
endDrawing ( ) ;
2023-06-02 06:03:36 +00:00
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
2023-06-03 07:15:38 +00:00
closeWindow ( ) ; // Close window and OpenGL context
//--------------------------------------------------------------------------------------