From 7c63e389b865c9a55bfd1a74cc5f568ac5f32e8e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 5 Oct 2021 14:10:35 +0200 Subject: [PATCH] Reviewed examples for latest raygui/raylib --- .../controls_test_suite/controls_test_suite.c | 7 +--- .../custom_file_dialog/custom_file_dialog.c | 8 ++-- examples/custom_file_dialog/gui_file_dialog.h | 4 +- examples/image_exporter/image_exporter.c | 8 ++-- .../image_raw_importer/image_raw_importer.c | 7 ++-- examples/portable_window/portable_window.c | 11 +++-- examples/property_list/property_list.c | 42 +++++++++++-------- examples/property_list/test.props | 27 ++++++++++++ examples/scroll_panel/gui_scroll_panel.c | 8 ++-- .../textbox_extended_demo.c | 1 - examples/text_editor/text_editor.c | 2 - 11 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 examples/property_list/test.props diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 7a3d70e..93faf01 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -37,11 +37,8 @@ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" -#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -49,8 +46,8 @@ int main() { // Initialization //--------------------------------------------------------------------------------------- - int screenWidth = 690; - int screenHeight = 560; + const int screenWidth = 690; + const int screenHeight = 560; InitWindow(screenWidth, screenHeight, "raygui - controls test suite"); SetExitKey(0); diff --git a/examples/custom_file_dialog/custom_file_dialog.c b/examples/custom_file_dialog/custom_file_dialog.c index 869c596..4a662a5 100644 --- a/examples/custom_file_dialog/custom_file_dialog.c +++ b/examples/custom_file_dialog/custom_file_dialog.c @@ -3,26 +3,24 @@ * raygui - custom file dialog to load image * * DEPENDENCIES: -* raylib 2.6-dev - Windowing/input management and drawing. -* raygui 2.6-dev - Immediate-mode GUI controls. +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.0 - Immediate-mode GUI controls. * * COMPILATION (Windows - MinGW): * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * * LICENSE: zlib/libpng * -* Copyright (c) 2020 Ramon Santamaria (@raysan5) +* Copyright (c) 2016-2021 Ramon Santamaria (@raysan5) * **********************************************************************************************/ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" #undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again - #define GUI_FILE_DIALOG_IMPLEMENTATION #include "gui_file_dialog.h" diff --git a/examples/custom_file_dialog/gui_file_dialog.h b/examples/custom_file_dialog/gui_file_dialog.h index 22bb38e..f635557 100644 --- a/examples/custom_file_dialog/gui_file_dialog.h +++ b/examples/custom_file_dialog/gui_file_dialog.h @@ -18,7 +18,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2019-2020 Ramon Santamaria (@raysan5) +* Copyright (c) 2019-2021 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -257,7 +257,7 @@ void GuiFileDialog(GuiFileDialogState *state) //------------------------------------------------------------------------------------ DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), 0.85f)); - state->fileDialogActive = !GuiWindowBox((Rectangle){ state->position.x + 0, state->position.y + 0, winWidth, winHeight }, "#198#LuaJIT | Select File Dialog"); + state->fileDialogActive = !GuiWindowBox((Rectangle){ state->position.x + 0, state->position.y + 0, winWidth, winHeight }, "#198# Select File Dialog"); if (GuiButton((Rectangle){ state->position.x + winWidth - 50, state->position.y + 35, 40, 25 }, "< ..")) // || IsKeyReleased(KEY_DPAD_Y)) { diff --git a/examples/image_exporter/image_exporter.c b/examples/image_exporter/image_exporter.c index 678c12f..79821ce 100644 --- a/examples/image_exporter/image_exporter.c +++ b/examples/image_exporter/image_exporter.c @@ -3,25 +3,23 @@ * raygui - image exporter * * DEPENDENCIES: -* raylib 2.1 - Windowing/input management and drawing. -* raygui 2.0 - Immediate-mode GUI controls. +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.0 - Immediate-mode GUI controls. * * COMPILATION (Windows - MinGW): * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * * LICENSE: zlib/libpng * -* Copyright (c) 2020 Ramon Santamaria (@raysan5) +* Copyright (c) 2015-2021 Ramon Santamaria (@raysan5) * ********************************************************************************************/ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ diff --git a/examples/image_raw_importer/image_raw_importer.c b/examples/image_raw_importer/image_raw_importer.c index 6f80453..dfe887a 100644 --- a/examples/image_raw_importer/image_raw_importer.c +++ b/examples/image_raw_importer/image_raw_importer.c @@ -3,22 +3,21 @@ * raygui - image raw importer * * DEPENDENCIES: -* raylib 2.1 - Windowing/input management and drawing. -* raygui 2.0 - Immediate-mode GUI controls. +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.0 - Immediate-mode GUI controls. * * COMPILATION (Windows - MinGW): * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * * LICENSE: zlib/libpng * -* Copyright (c) 2020 Ramon Santamaria (@raysan5) +* Copyright (c) 2015-2021 Ramon Santamaria (@raysan5) * **********************************************************************************************/ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" #include // Required for: strcpy() diff --git a/examples/portable_window/portable_window.c b/examples/portable_window/portable_window.c index b69655a..1f8e2db 100644 --- a/examples/portable_window/portable_window.c +++ b/examples/portable_window/portable_window.c @@ -3,22 +3,21 @@ * raygui - portable window * * DEPENDENCIES: -* raylib 2.1 - Windowing/input management and drawing. -* raygui 2.0 - Immediate-mode GUI controls. +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.0 - Immediate-mode GUI controls. * * COMPILATION (Windows - MinGW): * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * * LICENSE: zlib/libpng * -* Copyright (c) 2020 Ramon Santamaria (@raysan5) +* Copyright (c) 2016-2021 Ramon Santamaria (@raysan5) * **********************************************************************************************/ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" //------------------------------------------------------------------------------------ @@ -28,8 +27,8 @@ int main() { // Initialization //--------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 600; + const int screenWidth = 800; + const int screenHeight = 600; SetConfigFlags(FLAG_WINDOW_UNDECORATED); InitWindow(screenWidth, screenHeight, "raygui - portable window"); diff --git a/examples/property_list/property_list.c b/examples/property_list/property_list.c index 1854075..72050d0 100644 --- a/examples/property_list/property_list.c +++ b/examples/property_list/property_list.c @@ -1,24 +1,23 @@ /******************************************************************************************* * -* raygui - a custom property list control +* raygui - custom property list control * * DEPENDENCIES: -* raylib 3.0 -* raygui 2.7 +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.0 - Immediate-mode GUI controls. * * COMPILATION (Windows - MinGW): * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * * LICENSE: zlib/libpng * -* Copyright (c) 2020 Vlad Adrian (@Demizdor - https://github.com/Demizdor) +* Copyright (c) 2020-2021 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5) * **********************************************************************************************/ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" #undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again @@ -26,8 +25,6 @@ #define GUI_PROPERTY_LIST_IMPLEMENTATION #include "dm_property_list.h" -#define SCREEN_WIDTH 800 -#define SCREEN_HEIGHT 450 #define SIZEOF(A) (sizeof(A)/sizeof(A[0])) //------------------------------------------------------------------------------------ @@ -37,7 +34,11 @@ int main() { // Initialization //--------------------------------------------------------------------------------------- - + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raygui - property list"); + GuiDMProperty prop[] = { PBOOL("Bool", 0, true), PSECTION("#102#SECTION", 0, 2), @@ -52,17 +53,17 @@ int main() PVEC4("Vec4", 0, 12, 13, 14, 15), PCOLOR("Color", 0, 0, 255, 0, 255), }; - int focus = 0, scroll = 0; // needed by GuiDMPropertyList() - - InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raygui - property list"); - SetTargetFPS(60); + int focus = 0, scroll = 0; // Needed by GuiDMPropertyList() + GuiLoadStyleDefault(); - // adjust the default raygui style a bit + + // Tweak the default raygui style a bit GuiSetStyle(LISTVIEW, LIST_ITEMS_HEIGHT, 24); GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, 12); - //-------------------------------------------------------------------------------------- + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key @@ -70,11 +71,12 @@ int main() // Draw //---------------------------------------------------------------------------------- BeginDrawing(); + ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); - GuiGrid((Rectangle){0,0,SCREEN_WIDTH,SCREEN_HEIGHT},20.0f, 2); // draw a fancy grid + GuiGrid((Rectangle){0, 0, screenWidth, screenHeight},20.0f, 2); // Draw a fancy grid - GuiDMPropertyList((Rectangle){(SCREEN_WIDTH - 180)/2, (SCREEN_HEIGHT - 280)/2, 180, 280}, prop, SIZEOF(prop), &focus, &scroll); + GuiDMPropertyList((Rectangle){(screenWidth - 180)/2, (screenHeight - 280)/2, 180, 280}, prop, SIZEOF(prop), &focus, &scroll); if (prop[0].value.vbool >= 1) { @@ -84,9 +86,13 @@ int main() EndDrawing(); //---------------------------------------------------------------------------------- } - + + // De-Initialization + //-------------------------------------------------------------------------------------- GuiDMSaveProperties("test.props", prop, SIZEOF(prop)); // Save properties to `test.props` file at exit - CloseWindow(); // Close window and OpenGL context + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- return 0; } diff --git a/examples/property_list/test.props b/examples/property_list/test.props new file mode 100644 index 0000000..3208dd0 --- /dev/null +++ b/examples/property_list/test.props @@ -0,0 +1,27 @@ +# +# Property types: +# b // Bool +# i // Int +# f // Float +# t // Text +# l // Select +# g // Section (Group) +# v2 // Vector 2D +# v3 // Vector 3D +# v4 // Vector 4D +# r // Rectangle +# c // Color +# + +b Bool 0 1 +g #102#SECTION 0 2 +i Int 0 123 0 0 1 +f Float 0 0.990000 0.000000 0.000000 1.000000 3 +t Text 1 Hello! 30 +l Select 0 ONE;TWO;THREE;FOUR 3 +i Int Range 0 32 0 100 1 +r Rect 1 0 0 100 200 +v2 Vec2 1 20.000000 20.000000 +v3 Vec3 1 12.000000 13.000000 14.000000 +v4 Vec4 1 12.000000 13.000000 14.000000 15.000000 +c Color 1 94 68 197 160 diff --git a/examples/scroll_panel/gui_scroll_panel.c b/examples/scroll_panel/gui_scroll_panel.c index 96c2baf..c2bc898 100644 --- a/examples/scroll_panel/gui_scroll_panel.c +++ b/examples/scroll_panel/gui_scroll_panel.c @@ -6,18 +6,18 @@ * - GuiScrollPanel() * * DEPENDENCIES: -* raylib 2.4 - Windowing/input management and drawing. -* raygui 2.0 - Immediate-mode GUI controls. +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.0 - Immediate-mode GUI controls. * * COMPILATION (Windows - MinGW): * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * * COMPILATION (Linux - gcc): -* gcc -o $(NAME_PART) $(FILE_NAME) -I../../src -lraylib -std=c99 +* gcc -o $(NAME_PART) $(FILE_NAME) -I../../src -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -std=c99 * * LICENSE: zlib/libpng * -* Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5) +* Copyright (c) 2019-2021 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5) * **********************************************************************************************/ diff --git a/examples/text_box_selection/textbox_extended_demo.c b/examples/text_box_selection/textbox_extended_demo.c index a4a45a9..3e2d403 100644 --- a/examples/text_box_selection/textbox_extended_demo.c +++ b/examples/text_box_selection/textbox_extended_demo.c @@ -24,7 +24,6 @@ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" #undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again diff --git a/examples/text_editor/text_editor.c b/examples/text_editor/text_editor.c index e697bba..90de5f7 100644 --- a/examples/text_editor/text_editor.c +++ b/examples/text_editor/text_editor.c @@ -21,10 +21,8 @@ #include "raylib.h" #define RAYGUI_IMPLEMENTATION -#define RAYGUI_SUPPORT_RICONS #include "../../src/raygui.h" - //---------------------------------------------------------------------------------- // Defines and Macros //----------------------------------------------------------------------------------