2018-10-09 11:58:04 +02:00
/*******************************************************************************************
*
2018-11-08 10:41:31 +01:00
* raygui - controls test suite
*
* TEST CONTROLS :
* - GuiDropdownBox ( )
2019-09-02 23:18:25 +02:00
* - GuiCheckBox ( )
2018-11-08 10:41:31 +01:00
* - GuiSpinner ( )
2019-09-02 23:18:25 +02:00
* - GuiValueBox ( )
2018-11-08 10:41:31 +01:00
* - GuiTextBox ( )
2019-09-02 23:18:25 +02:00
* - GuiButton ( )
* - GuiComboBox ( )
2018-11-08 10:41:31 +01:00
* - GuiListView ( )
2019-09-02 23:18:25 +02:00
* - GuiToggleGroup ( )
* - GuiColorPicker ( )
* - GuiSlider ( )
* - GuiSliderBar ( )
* - GuiProgressBar ( )
* - GuiColorBarAlpha ( )
* - GuiScrollPanel ( )
*
2018-11-08 10:41:31 +01:00
*
* DEPENDENCIES :
2023-04-20 14:24:15 +02:00
* raylib 4.5 - Windowing / input management and drawing
* raygui 3.5 - Immediate - mode GUI controls with custom styling and icons
2018-11-08 10:41:31 +01:00
*
* COMPILATION ( Windows - MinGW ) :
* gcc - o $ ( NAME_PART ) . exe $ ( FILE_NAME ) - I . . / . . / src - lraylib - lopengl32 - lgdi32 - std = c99
2018-10-09 11:58:04 +02:00
*
* LICENSE : zlib / libpng
*
2023-01-01 16:00:38 +01:00
* Copyright ( c ) 2016 - 2023 Ramon Santamaria ( @ raysan5 )
2018-10-09 11:58:04 +02:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "raylib.h"
# define RAYGUI_IMPLEMENTATION
2021-12-21 23:26:30 +01:00
//#define RAYGUI_CUSTOM_ICONS // It requires providing gui_icons.h in the same directory
//#include "gui_icons.h" // External icons data provided, it can be generated with rGuiIcons tool
2018-10-09 11:58:04 +02:00
# include "../../src/raygui.h"
2023-07-04 18:57:04 +02:00
// raygui embedded styles
# include "../styles/style_cyber.h" // raygui style: cyber
# include "../styles/style_jungle.h" // raygui style: jungle
# include "../styles/style_lavanda.h" // raygui style: lavanda
# include "../styles/style_dark.h" // raygui style: dark
# include "../styles/style_bluish.h" // raygui style: bluish
# include "../styles/style_terminal.h" // raygui style: terminal
2021-10-05 18:33:02 +02:00
2018-10-09 11:58:04 +02:00
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main ( )
{
// Initialization
//---------------------------------------------------------------------------------------
2021-10-05 14:10:35 +02:00
const int screenWidth = 690 ;
const int screenHeight = 560 ;
2021-03-19 20:12:50 +01:00
2018-11-08 10:41:31 +01:00
InitWindow ( screenWidth , screenHeight , " raygui - controls test suite " ) ;
2019-02-22 18:33:35 +01:00
SetExitKey ( 0 ) ;
2018-10-09 11:58:04 +02:00
2018-11-08 10:41:31 +01:00
// GUI controls initialization
2018-10-09 11:58:04 +02:00
//----------------------------------------------------------------------------------
2018-10-30 12:55:48 +01:00
int dropdownBox000Active = 0 ;
bool dropDown000EditMode = false ;
2021-03-19 20:12:50 +01:00
2018-10-30 12:55:48 +01:00
int dropdownBox001Active = 0 ;
2021-03-19 20:12:50 +01:00
bool dropDown001EditMode = false ;
2018-10-30 12:55:48 +01:00
int spinner001Value = 0 ;
2018-10-09 13:46:13 +02:00
bool spinnerEditMode = false ;
2021-03-19 20:12:50 +01:00
2018-10-30 12:55:48 +01:00
int valueBox002Value = 0 ;
2018-10-09 13:46:13 +02:00
bool valueBoxEditMode = false ;
2021-03-19 20:12:50 +01:00
2018-10-30 12:55:48 +01:00
char textBoxText [ 64 ] = " Text box " ;
2018-10-09 13:46:13 +02:00
bool textBoxEditMode = false ;
2021-03-19 20:12:50 +01:00
2018-11-13 18:16:37 +01:00
int listViewScrollIndex = 0 ;
2018-10-30 12:55:48 +01:00
int listViewActive = - 1 ;
2019-08-07 00:37:54 +02:00
2018-10-30 12:55:48 +01:00
int listViewExScrollIndex = 0 ;
2019-08-07 00:37:54 +02:00
int listViewExActive = 2 ;
2018-10-31 14:36:36 +01:00
int listViewExFocus = - 1 ;
2019-02-12 12:54:26 +01:00
const char * listViewExList [ 8 ] = { " This " , " is " , " a " , " list view " , " with " , " disable " , " elements " , " amazing! " } ;
2019-08-16 16:30:37 +02:00
2020-03-11 16:00:09 +01:00
char multiTextBoxText [ 256 ] = " Multi text box " ;
2018-11-13 12:56:12 +01:00
bool multiTextBoxEditMode = false ;
Color colorPickerValue = RED ;
2021-03-19 20:12:50 +01:00
2023-05-27 11:34:45 +02:00
float sliderValue = 50.0f ;
float sliderBarValue = 60 ;
2018-11-13 18:16:37 +01:00
float progressValue = 0.4f ;
2021-03-19 20:12:50 +01:00
2018-10-30 12:55:48 +01:00
bool forceSquaredChecked = false ;
2021-03-19 20:12:50 +01:00
2019-07-03 01:29:18 +02:00
float alphaValue = 0.5f ;
2021-03-19 20:12:50 +01:00
2023-07-04 18:57:04 +02:00
//int comboBoxActive = 1;
int visualStyleActive = 0 ;
int prevVisualStyleActive = 0 ;
2021-03-19 20:12:50 +01:00
2018-11-28 17:17:14 +01:00
int toggleGroupActive = 0 ;
2021-03-19 20:12:50 +01:00
2019-01-09 00:43:33 +01:00
Vector2 viewScroll = { 0 , 0 } ;
2018-10-09 11:58:04 +02:00
//----------------------------------------------------------------------------------
2019-08-08 22:56:56 +02:00
2018-11-08 10:41:31 +01:00
// Custom GUI font loading
2018-10-30 12:55:48 +01:00
//Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
2019-08-26 00:56:58 +02:00
//GuiSetFont(font);
2021-03-19 20:12:50 +01:00
2019-02-22 18:33:35 +01:00
bool exitWindow = false ;
bool showMessageBox = false ;
2021-03-19 20:12:50 +01:00
2019-08-02 17:19:00 +02:00
char textInput [ 256 ] = { 0 } ;
bool showTextInputBox = false ;
2021-03-19 20:12:50 +01:00
2019-08-10 13:12:40 +02:00
char textInputFileName [ 256 ] = { 0 } ;
2018-10-09 11:58:04 +02:00
SetTargetFPS ( 60 ) ;
//--------------------------------------------------------------------------------------
// Main game loop
2019-02-22 18:33:35 +01:00
while ( ! exitWindow ) // Detect window close button or ESC key
2018-10-09 11:58:04 +02:00
{
// Update
//----------------------------------------------------------------------------------
2019-02-22 18:33:35 +01:00
exitWindow = WindowShouldClose ( ) ;
2021-03-19 20:12:50 +01:00
2019-02-22 19:18:09 +01:00
if ( IsKeyPressed ( KEY_ESCAPE ) ) showMessageBox = ! showMessageBox ;
2021-03-19 20:12:50 +01:00
2019-08-02 17:19:00 +02:00
if ( IsKeyDown ( KEY_LEFT_CONTROL ) & & IsKeyPressed ( KEY_S ) ) showTextInputBox = true ;
2021-03-19 20:12:50 +01:00
2019-06-25 18:40:02 +02:00
if ( IsFileDropped ( ) )
{
2022-06-29 19:18:10 +02:00
FilePathList droppedFiles = LoadDroppedFiles ( ) ;
2021-03-19 20:12:50 +01:00
2022-06-29 19:18:10 +02:00
if ( ( droppedFiles . count > 0 ) & & IsFileExtension ( droppedFiles . paths [ 0 ] , " .rgs " ) ) GuiLoadStyle ( droppedFiles . paths [ 0 ] ) ;
2021-03-19 20:12:50 +01:00
2022-06-29 19:18:10 +02:00
UnloadDroppedFiles ( droppedFiles ) ; // Clear internal buffers
2019-06-25 18:40:02 +02:00
}
2023-07-04 18:57:04 +02:00
progressValue + = 0.002f ;
//if (progressValue >= 1.0f) progressValue = 0.0f;
if ( IsKeyPressed ( KEY_SPACE ) ) progressValue = 0.2f ;
if ( visualStyleActive ! = prevVisualStyleActive )
{
GuiLoadStyleDefault ( ) ;
switch ( visualStyleActive )
{
case 0 : break ; // Default style
case 1 : GuiLoadStyleJungle ( ) ; break ;
case 2 : GuiLoadStyleLavanda ( ) ; break ;
case 3 : GuiLoadStyleDark ( ) ; break ;
case 4 : GuiLoadStyleBluish ( ) ; break ;
case 5 : GuiLoadStyleCyber ( ) ; break ;
case 6 : GuiLoadStyleTerminal ( ) ; break ;
default : break ;
}
GuiSetStyle ( LABEL , TEXT_ALIGNMENT , TEXT_ALIGN_LEFT ) ;
prevVisualStyleActive = visualStyleActive ;
}
2018-10-09 11:58:04 +02:00
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing ( ) ;
2018-11-13 12:56:12 +01:00
ClearBackground ( GetColor ( GuiGetStyle ( DEFAULT , BACKGROUND_COLOR ) ) ) ;
2021-03-19 20:12:50 +01:00
2018-10-09 11:58:04 +02:00
// raygui: controls drawing
//----------------------------------------------------------------------------------
2023-03-07 18:52:35 +01:00
// Check all possible events that require GuiLock
2023-05-08 18:57:19 +02:00
if ( dropDown000EditMode | |
2023-03-07 18:52:35 +01:00
dropDown001EditMode ) GuiLock ( ) ;
2021-03-19 20:12:50 +01:00
2018-10-30 12:55:48 +01:00
// First GUI column
2022-05-21 12:08:18 +02:00
//GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
2023-05-27 11:34:45 +02:00
GuiCheckBox ( ( Rectangle ) { 25 , 108 , 15 , 15 } , " FORCE CHECK! " , & forceSquaredChecked ) ;
2021-03-19 20:12:50 +01:00
2022-05-21 12:08:18 +02:00
GuiSetStyle ( TEXTBOX , TEXT_ALIGNMENT , TEXT_ALIGN_CENTER ) ;
//GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
2019-08-18 17:59:00 +02:00
if ( GuiSpinner ( ( Rectangle ) { 25 , 135 , 125 , 30 } , NULL , & spinner001Value , 0 , 100 , spinnerEditMode ) ) spinnerEditMode = ! spinnerEditMode ;
if ( GuiValueBox ( ( Rectangle ) { 25 , 175 , 125 , 30 } , NULL , & valueBox002Value , 0 , 100 , valueBoxEditMode ) ) valueBoxEditMode = ! valueBoxEditMode ;
2022-05-21 12:08:18 +02:00
GuiSetStyle ( TEXTBOX , TEXT_ALIGNMENT , TEXT_ALIGN_LEFT ) ;
2018-10-30 12:55:48 +01:00
if ( GuiTextBox ( ( Rectangle ) { 25 , 215 , 125 , 30 } , textBoxText , 64 , textBoxEditMode ) ) textBoxEditMode = ! textBoxEditMode ;
2021-03-19 20:12:50 +01:00
2022-05-21 12:08:18 +02:00
GuiSetStyle ( BUTTON , TEXT_ALIGNMENT , TEXT_ALIGN_CENTER ) ;
2021-03-19 20:12:50 +01:00
2022-05-21 12:08:18 +02:00
if ( GuiButton ( ( Rectangle ) { 25 , 255 , 125 , 30 } , GuiIconText ( ICON_FILE_SAVE , " Save File " ) ) ) showTextInputBox = true ;
2021-03-19 20:12:50 +01:00
2019-02-14 17:02:02 +01:00
GuiGroupBox ( ( Rectangle ) { 25 , 310 , 125 , 150 } , " STATES " ) ;
2021-10-05 11:23:58 +02:00
//GuiLock();
2022-05-21 12:08:18 +02:00
GuiSetState ( STATE_NORMAL ) ; if ( GuiButton ( ( Rectangle ) { 30 , 320 , 115 , 30 } , " NORMAL " ) ) { }
GuiSetState ( STATE_FOCUSED ) ; if ( GuiButton ( ( Rectangle ) { 30 , 355 , 115 , 30 } , " FOCUSED " ) ) { }
GuiSetState ( STATE_PRESSED ) ; if ( GuiButton ( ( Rectangle ) { 30 , 390 , 115 , 30 } , " #15#PRESSED " ) ) { }
GuiSetState ( STATE_DISABLED ) ; if ( GuiButton ( ( Rectangle ) { 30 , 425 , 115 , 30 } , " DISABLED " ) ) { }
GuiSetState ( STATE_NORMAL ) ;
2021-10-05 11:23:58 +02:00
//GuiUnlock();
2021-03-19 20:12:50 +01:00
2023-07-04 18:57:04 +02:00
GuiComboBox ( ( Rectangle ) { 25 , 470 , 125 , 30 } , " default;Jungle;Lavanda;Dark;Bluish;Cyber;Terminal " , & visualStyleActive ) ;
2021-03-19 20:12:50 +01:00
2018-11-13 12:56:12 +01:00
// NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
2023-03-07 18:52:35 +01:00
GuiUnlock ( ) ;
2022-05-21 12:08:18 +02:00
GuiSetStyle ( DROPDOWNBOX , TEXT_ALIGNMENT , TEXT_ALIGN_LEFT ) ;
2019-02-14 16:25:33 +01:00
if ( GuiDropdownBox ( ( Rectangle ) { 25 , 65 , 125 , 30 } , " #01#ONE;#02#TWO;#03#THREE;#04#FOUR " , & dropdownBox001Active , dropDown001EditMode ) ) dropDown001EditMode = ! dropDown001EditMode ;
2019-08-07 00:37:54 +02:00
2022-05-21 12:08:18 +02:00
GuiSetStyle ( DROPDOWNBOX , TEXT_ALIGNMENT , TEXT_ALIGN_CENTER ) ;
2018-12-23 14:23:56 +01:00
if ( GuiDropdownBox ( ( Rectangle ) { 25 , 25 , 125 , 30 } , " ONE;TWO;THREE " , & dropdownBox000Active , dropDown000EditMode ) ) dropDown000EditMode = ! dropDown000EditMode ;
2019-08-07 00:37:54 +02:00
// Second GUI column
2023-05-27 11:34:45 +02:00
GuiListView ( ( Rectangle ) { 165 , 25 , 140 , 140 } , " Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey " , & listViewScrollIndex , & listViewActive ) ;
GuiListViewEx ( ( Rectangle ) { 165 , 180 , 140 , 200 } , listViewExList , 8 , & listViewExScrollIndex , & listViewExActive , & listViewExFocus ) ;
2019-08-07 00:37:54 +02:00
2023-05-27 11:34:45 +02:00
//GuiToggle((Rectangle){ 165, 400, 140, 25 }, "#1#ONE", &toggleGroupActive);
GuiToggleGroup ( ( Rectangle ) { 165 , 400 , 140 , 25 } , " #1#ONE \n #3#TWO \n #8#THREE \n #23# " , & toggleGroupActive ) ;
2021-03-19 20:12:50 +01:00
2018-10-30 12:55:48 +01:00
// Third GUI column
2023-04-20 14:24:15 +02:00
GuiPanel ( ( Rectangle ) { 320 , 25 , 225 , 140 } , " Panel Info " ) ;
2023-05-27 11:34:45 +02:00
GuiColorPicker ( ( Rectangle ) { 320 , 185 , 196 , 192 } , NULL , & colorPickerValue ) ;
2021-03-19 20:12:50 +01:00
2023-07-04 18:57:04 +02:00
//GuiDisable();
2023-05-27 11:34:45 +02:00
GuiSlider ( ( Rectangle ) { 355 , 400 , 165 , 20 } , " TEST " , TextFormat ( " %2.2f " , sliderValue ) , & sliderValue , - 50 , 100 ) ;
GuiSliderBar ( ( Rectangle ) { 320 , 430 , 200 , 20 } , NULL , TextFormat ( " %i " , ( int ) sliderBarValue ) , & sliderBarValue , 0 , 100 ) ;
2023-07-04 18:57:04 +02:00
GuiProgressBar ( ( Rectangle ) { 320 , 460 , 200 , 20 } , NULL , TextFormat ( " %i%% " , ( int ) ( progressValue * 100 ) ) , & progressValue , 0.0f , 1.0f ) ;
GuiEnable ( ) ;
2019-02-14 16:25:33 +01:00
2019-08-16 16:30:37 +02:00
// NOTE: View rectangle could be used to perform some scissor test
2023-05-27 11:34:45 +02:00
Rectangle view = { 0 } ;
GuiScrollPanel ( ( Rectangle ) { 560 , 25 , 102 , 354 } , NULL , ( Rectangle ) { 560 , 25 , 300 , 1200 } , & viewScroll , & view ) ;
2022-02-05 18:35:55 +01:00
2023-05-27 11:34:45 +02:00
Vector2 mouseCell = { 0 } ;
GuiGrid ( ( Rectangle ) { 560 , 25 + 180 + 195 , 100 , 120 } , NULL , 20 , 2 , & mouseCell ) ;
2021-03-19 20:12:50 +01:00
2022-06-01 20:40:42 +02:00
GuiStatusBar ( ( Rectangle ) { 0 , ( float ) GetScreenHeight ( ) - 20 , ( float ) GetScreenWidth ( ) , 20 } , " This is a status bar " ) ;
2021-03-19 20:12:50 +01:00
2023-05-27 11:34:45 +02:00
GuiColorBarAlpha ( ( Rectangle ) { 320 , 490 , 200 , 30 } , NULL , & alphaValue ) ;
2019-08-07 00:37:54 +02:00
2019-02-22 18:33:35 +01:00
if ( showMessageBox )
{
2019-02-22 19:18:09 +01:00
DrawRectangle ( 0 , 0 , GetScreenWidth ( ) , GetScreenHeight ( ) , Fade ( RAYWHITE , 0.8f ) ) ;
2022-06-01 20:40:42 +02:00
int result = GuiMessageBox ( ( Rectangle ) { ( float ) GetScreenWidth ( ) / 2 - 125 , ( float ) GetScreenHeight ( ) / 2 - 50 , 250 , 100 } , GuiIconText ( ICON_EXIT , " Close Window " ) , " Do you really want to exit? " , " Yes;No " ) ;
2021-03-19 20:12:50 +01:00
2019-08-02 17:19:00 +02:00
if ( ( result = = 0 ) | | ( result = = 2 ) ) showMessageBox = false ;
else if ( result = = 1 ) exitWindow = true ;
}
2021-03-19 20:12:50 +01:00
2019-08-02 17:19:00 +02:00
if ( showTextInputBox )
{
DrawRectangle ( 0 , 0 , GetScreenWidth ( ) , GetScreenHeight ( ) , Fade ( RAYWHITE , 0.8f ) ) ;
2022-06-01 20:40:42 +02:00
int result = GuiTextInputBox ( ( Rectangle ) { ( float ) GetScreenWidth ( ) / 2 - 120 , ( float ) GetScreenHeight ( ) / 2 - 60 , 240 , 140 } , " Save " , GuiIconText ( ICON_FILE_SAVE , " Save file as... " ) , " Ok;Cancel " , textInput , 255 , NULL ) ;
2021-03-19 20:12:50 +01:00
2019-08-10 13:12:40 +02:00
if ( result = = 1 )
{
// TODO: Validate textInput value and save
2021-03-19 20:12:50 +01:00
2023-07-04 18:57:04 +02:00
TextCopy ( textInputFileName , textInput ) ;
2019-08-10 13:12:40 +02:00
}
2021-03-19 20:12:50 +01:00
if ( ( result = = 0 ) | | ( result = = 1 ) | | ( result = = 2 ) )
2019-08-10 13:12:40 +02:00
{
showTextInputBox = false ;
2023-07-04 18:57:04 +02:00
TextCopy ( textInput , " \0 " ) ;
2019-08-10 13:12:40 +02:00
}
2019-02-22 18:33:35 +01:00
}
2018-10-09 11:58:04 +02:00
//----------------------------------------------------------------------------------
EndDrawing ( ) ;
//----------------------------------------------------------------------------------
}
2018-11-08 10:41:31 +01:00
2018-10-09 11:58:04 +02:00
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow ( ) ; // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0 ;
}