2018-10-09 11:58:04 +02:00
/*******************************************************************************************
*
2018-11-08 10:41:31 +01:00
* raygui - controls test suite
*
* TEST CONTROLS :
* - GuiDropdownBox ( )
* - GuiValueBox ( )
* - GuiSpinner ( )
* - GuiTextBox ( )
* - GuiTextBoxMulti ( )
* - GuiListView ( )
*
* DEPENDENCIES :
2018-11-08 10:53:24 +01:00
* raylib 2.1 - Windowing / input management and drawing .
* raygui 2.0 - Immediate - mode GUI controls .
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
*
2018-11-08 10:41:31 +01:00
* Copyright ( c ) 2018 raylib technologies ( @ raylibtech )
2018-10-09 11:58:04 +02:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "raylib.h"
# define RAYGUI_IMPLEMENTATION
# include "../../src/raygui.h"
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main ( )
{
// Initialization
//---------------------------------------------------------------------------------------
2019-01-09 00:43:33 +01:00
int screenWidth = 690 ;
2019-02-14 16:25:33 +01:00
int screenHeight = 560 ;
2018-10-09 11:58:04 +02: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 ;
int dropdownBox001Active = 0 ;
bool dropDown001EditMode = false ;
2018-10-09 13:46:13 +02:00
2018-10-30 12:55:48 +01:00
int spinner001Value = 0 ;
2018-10-09 13:46:13 +02:00
bool spinnerEditMode = false ;
2018-10-30 12:55:48 +01:00
int valueBox002Value = 0 ;
2018-10-09 13:46:13 +02:00
bool valueBoxEditMode = false ;
2018-10-30 12:55:48 +01:00
char textBoxText [ 64 ] = " Text box " ;
2018-10-09 13:46:13 +02:00
bool textBoxEditMode = false ;
2018-10-30 12:55:48 +01:00
2018-11-13 18:16:37 +01:00
int listViewScrollIndex = 0 ;
2018-10-30 12:55:48 +01:00
int listViewActive = - 1 ;
2018-10-16 17:43:46 +02:00
bool listViewEditMode = false ;
2018-10-23 17:44:44 +02:00
2018-10-30 12:55:48 +01:00
int listViewExScrollIndex = 0 ;
int listViewExActive = - 1 ;
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! " } ;
2018-10-30 12:55:48 +01:00
int listViewExElementsEnable [ 8 ] = { 1 , 0 , 1 , 1 , 0 , 0 , 1 } ;
bool listViewExEditMode = false ;
2018-10-29 19:41:51 +01:00
2018-10-30 12:55:48 +01:00
char multiTextBoxText [ 141 ] = " Multi text box " ;
2018-11-13 12:56:12 +01:00
bool multiTextBoxEditMode = false ;
Color colorPickerValue = RED ;
2018-10-30 12:55:48 +01:00
2018-11-13 18:16:37 +01:00
int sliderValue = 50 ;
int sliderBarValue = 60 ;
float progressValue = 0.4f ;
2018-10-30 12:55:48 +01:00
bool forceSquaredChecked = false ;
2018-11-20 11:21:41 +01:00
int comboBoxActive = 1 ;
2018-11-28 17:17:14 +01:00
int toggleGroupActive = 0 ;
2019-01-09 00:43:33 +01:00
Vector2 viewScroll = { 0 , 0 } ;
2018-10-09 11:58:04 +02:00
//----------------------------------------------------------------------------------
2018-10-18 17:19:09 +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);
//GuiFont(font);
2019-02-22 18:33:35 +01:00
bool exitWindow = false ;
bool showMessageBox = false ;
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 ( ) ;
if ( IsKeyPressed ( KEY_ESCAPE ) ) showMessageBox = true ;
2018-10-09 11:58:04 +02:00
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing ( ) ;
2018-11-13 12:56:12 +01:00
ClearBackground ( GetColor ( GuiGetStyle ( DEFAULT , BACKGROUND_COLOR ) ) ) ;
2018-10-10 13:58:16 +02:00
2018-10-09 11:58:04 +02:00
// raygui: controls drawing
//----------------------------------------------------------------------------------
2018-10-16 12:34:45 +02:00
if ( dropDown000EditMode | | dropDown001EditMode ) GuiLock ( ) ;
2018-10-24 12:45:04 +02:00
//GuiDisable();
2018-10-24 14:05:55 +02:00
2018-10-30 12:55:48 +01:00
// First GUI column
2018-12-23 14:23:56 +01:00
forceSquaredChecked = GuiCheckBox ( ( Rectangle ) { 25 , 108 , 15 , 15 } , " Force Square " , forceSquaredChecked ) ;
2019-02-18 18:06:36 +01:00
GuiSetStyle ( TEXTBOX , TEXT_ALIGNMENT , GUI_TEXT_ALIGN_CENTER ) ;
2019-02-08 12:52:26 +01:00
if ( GuiSpinner ( ( Rectangle ) { 25 , 135 , 125 , 30 } , & spinner001Value , 0 , 100 , spinnerEditMode ) ) spinnerEditMode = ! spinnerEditMode ;
2018-10-30 12:55:48 +01:00
if ( GuiValueBox ( ( Rectangle ) { 25 , 175 , 125 , 30 } , & valueBox002Value , 0 , 100 , valueBoxEditMode ) ) valueBoxEditMode = ! valueBoxEditMode ;
2019-02-18 18:06:36 +01:00
GuiSetStyle ( TEXTBOX , TEXT_ALIGNMENT , GUI_TEXT_ALIGN_LEFT ) ;
2018-10-30 12:55:48 +01:00
if ( GuiTextBox ( ( Rectangle ) { 25 , 215 , 125 , 30 } , textBoxText , 64 , textBoxEditMode ) ) textBoxEditMode = ! textBoxEditMode ;
2019-02-05 19:20:34 +01:00
2019-02-14 16:25:33 +01:00
GuiSetStyle ( BUTTON , TEXT_ALIGNMENT , GUI_TEXT_ALIGN_LEFT ) ;
if ( GuiButton ( ( Rectangle ) { 25 , 255 , 125 , 30 } , " #04#SAMPLE TEXT " ) ) { } ;
2018-11-13 12:56:12 +01:00
2019-02-14 17:02:02 +01:00
GuiGroupBox ( ( Rectangle ) { 25 , 310 , 125 , 150 } , " STATES " ) ;
2018-11-13 12:56:12 +01:00
GuiLock ( ) ;
GuiState ( GUI_STATE_NORMAL ) ; if ( GuiButton ( ( Rectangle ) { 30 , 320 , 115 , 30 } , " NORMAL " ) ) { }
GuiState ( GUI_STATE_FOCUSED ) ; if ( GuiButton ( ( Rectangle ) { 30 , 355 , 115 , 30 } , " FOCUSED " ) ) { }
2019-02-14 16:25:33 +01:00
GuiState ( GUI_STATE_PRESSED ) ; if ( GuiButton ( ( Rectangle ) { 30 , 390 , 115 , 30 } , " #15#PRESSED " ) ) { }
2018-11-13 12:56:12 +01:00
GuiState ( GUI_STATE_DISABLED ) ; if ( GuiButton ( ( Rectangle ) { 30 , 425 , 115 , 30 } , " DISABLED " ) ) { }
2019-02-14 16:25:33 +01:00
GuiState ( GUI_STATE_NORMAL ) ;
2018-11-13 12:56:12 +01:00
GuiUnlock ( ) ;
2018-12-23 14:23:56 +01:00
comboBoxActive = GuiComboBox ( ( Rectangle ) { 25 , 470 , 125 , 30 } , " ONE;TWO;THREE;FOUR " , comboBoxActive ) ;
2018-11-20 11:21:41 +01:00
2018-11-13 12:56:12 +01:00
// NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
2019-02-14 17:02:02 +01:00
GuiSetStyle ( DROPDOWNBOX , TEXT_ALIGNMENT , GUI_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-02-14 17:02:02 +01:00
GuiSetStyle ( DROPDOWNBOX , TEXT_ALIGNMENT , GUI_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 ;
2018-10-30 12:55:48 +01:00
// Second GUI column
2019-02-14 16:25:33 +01:00
if ( GuiListView ( ( Rectangle ) { 165 , 25 , 140 , 140 } , " Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey " , & listViewActive , & listViewScrollIndex , listViewEditMode ) ) listViewEditMode = ! listViewEditMode ;
2019-01-16 17:21:11 +01:00
if ( GuiListViewEx ( ( Rectangle ) { 165 , 180 , 140 , 200 } , listViewExList , 8 , listViewExElementsEnable , & listViewExActive , & listViewExFocus , & listViewExScrollIndex , listViewExEditMode ) ) listViewExEditMode = ! listViewExEditMode ;
2019-02-14 16:25:33 +01:00
if ( listViewExFocus > = 0 & & listViewExFocus < 8 ) DrawText ( FormatText ( " FOCUS: %s " , listViewExList [ listViewExFocus ] ) , 165 , 385 , 10 , listViewExElementsEnable [ listViewExFocus ] ? LIME : MAROON ) ;
2018-10-30 12:55:48 +01:00
2019-02-14 16:25:33 +01:00
toggleGroupActive = GuiToggleGroup ( ( Rectangle ) { 165 , 400 , 140 , 25 } , " #1#ONE \n #3#TWO \n #8#THREE \n #23# " , toggleGroupActive ) ;
2018-11-28 17:17:14 +01:00
2018-10-30 12:55:48 +01:00
// Third GUI column
2018-11-13 18:16:37 +01:00
if ( GuiTextBoxMulti ( ( Rectangle ) { 320 , 25 , 225 , 140 } , multiTextBoxText , 141 , multiTextBoxEditMode ) ) multiTextBoxEditMode = ! multiTextBoxEditMode ;
colorPickerValue = GuiColorPicker ( ( Rectangle ) { 320 , 185 , 196 , 192 } , colorPickerValue ) ;
2018-10-30 12:55:48 +01:00
2019-02-14 17:02:02 +01:00
sliderValue = GuiSlider ( ( Rectangle ) { 370 , 400 , 200 , 20 } , " #49#TEST " , sliderValue , - 50 , 100 , true ) ;
2019-02-05 19:20:34 +01:00
sliderBarValue = GuiSliderBar ( ( Rectangle ) { 320 , 430 , 200 , 20 } , NULL , sliderBarValue , 0 , 100 , true ) ;
progressValue = GuiProgressBar ( ( Rectangle ) { 320 , 460 , 200 , 20 } , NULL , progressValue , 0 , 1 , true ) ;
2019-02-14 16:25:33 +01:00
2019-02-12 12:54:26 +01:00
Rectangle view = GuiScrollPanel ( ( Rectangle ) { 560 , 25 , 100 , 160 } , ( Rectangle ) { 560 , 25 , 100 , 400 } , & viewScroll ) ;
2019-01-09 00:43:33 +01:00
2019-02-18 18:06:36 +01:00
GuiSetStyle ( DEFAULT , INNER_PADDING , 10 ) ;
GuiStatusBar ( ( Rectangle ) { 0 , GetScreenHeight ( ) - 20 , GetScreenWidth ( ) , 20 } , " This is a status bar " ) ;
GuiSetStyle ( DEFAULT , INNER_PADDING , 2 ) ;
2019-02-22 18:33:35 +01:00
if ( showMessageBox )
{
DrawRectangle ( 0 , 0 , GetScreenWidth ( ) , GetScreenHeight ( ) , Fade ( RAYWHITE , 0.7f ) ) ;
int message = GuiMessageBox ( ( Rectangle ) { GetScreenWidth ( ) / 2 - 125 , GetScreenHeight ( ) / 2 - 50 , 250 , 100 } , " Closing rTexPacker " , " Do you really want to exit? " , " Yes;No " ) ;
if ( ( message = = 0 ) | | ( message = = 2 ) ) showMessageBox = false ;
else if ( message = = 1 ) exitWindow = true ;
}
2019-02-14 16:25:33 +01:00
2018-11-13 12:56:12 +01:00
//GuiEnable();
2018-10-16 12:34:45 +02:00
GuiUnlock ( ) ;
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 ;
}