Mercurial
comparison postdog/slider_example.c @ 116:7bd795bac997
[Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 07 Jan 2026 04:52:17 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 115:96db6c3f38d6 | 116:7bd795bac997 |
|---|---|
| 1 | |
| 2 /******************************************************************************************* | |
| 3 * | |
| 4 * raygui - custom file dialog to load image | |
| 5 * | |
| 6 * DEPENDENCIES: | |
| 7 * raylib 4.0 - Windowing/input management and drawing. | |
| 8 * raygui 3.0 - Immediate-mode GUI controls. | |
| 9 * | |
| 10 * COMPILATION (Windows - MinGW): | |
| 11 * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 | |
| 12 * | |
| 13 * LICENSE: zlib/libpng | |
| 14 * | |
| 15 * Copyright (c) 2016-2024 Ramon Santamaria (@raysan5) | |
| 16 * | |
| 17 **********************************************************************************************/ | |
| 18 | |
| 19 #include "third_party/raylib/include/raylib.h" | |
| 20 | |
| 21 #define RAYGUI_IMPLEMENTATION | |
| 22 #include "third_party/raylib/include/raygui.h" | |
| 23 | |
| 24 #undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again | |
| 25 | |
| 26 #define GUI_WINDOW_FILE_DIALOG_IMPLEMENTATION | |
| 27 #include "postdog/gui_window_file_dialog.h" | |
| 28 #define POSTDOG_PATHS "/Users/mrjunejune/zenbu/postdog/history" | |
| 29 | |
| 30 | |
| 31 //------------------------------------------------------------------------------------ | |
| 32 // Program main entry point | |
| 33 //------------------------------------------------------------------------------------ | |
| 34 int main() | |
| 35 { | |
| 36 // Initialization | |
| 37 //--------------------------------------------------------------------------------------- | |
| 38 int screenWidth = 800; | |
| 39 int screenHeight = 560; | |
| 40 | |
| 41 InitWindow(screenWidth, screenHeight, "raygui - custom modal dialog"); | |
| 42 SetExitKey(0); | |
| 43 | |
| 44 // Custom file dialog | |
| 45 GuiWindowFileDialogState fileDialogState = InitGuiWindowFileDialog(POSTDOG_PATHS); | |
| 46 | |
| 47 bool exitWindow = false; | |
| 48 | |
| 49 char fileNameToLoad[512] = { 0 }; | |
| 50 | |
| 51 Texture texture = { 0 }; | |
| 52 | |
| 53 SetTargetFPS(60); | |
| 54 //-------------------------------------------------------------------------------------- | |
| 55 | |
| 56 // Main game loop | |
| 57 while (!exitWindow) // Detect window close button or ESC key | |
| 58 { | |
| 59 // Update | |
| 60 //---------------------------------------------------------------------------------- | |
| 61 exitWindow = WindowShouldClose(); | |
| 62 | |
| 63 if (fileDialogState.SelectFilePressed) | |
| 64 { | |
| 65 // Load image file (if supported extension) | |
| 66 if (IsFileExtension(fileDialogState.fileNameText, ".png")) | |
| 67 { | |
| 68 strcpy(fileNameToLoad, TextFormat("%s" PATH_SEPERATOR "%s", fileDialogState.dirPathText, fileDialogState.fileNameText)); | |
| 69 UnloadTexture(texture); | |
| 70 texture = LoadTexture(fileNameToLoad); | |
| 71 } | |
| 72 | |
| 73 fileDialogState.SelectFilePressed = false; | |
| 74 } | |
| 75 //---------------------------------------------------------------------------------- | |
| 76 | |
| 77 // Draw | |
| 78 //---------------------------------------------------------------------------------- | |
| 79 BeginDrawing(); | |
| 80 | |
| 81 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); | |
| 82 | |
| 83 DrawTexture(texture, GetScreenWidth()/2 - texture.width/2, GetScreenHeight()/2 - texture.height/2 - 5, WHITE); | |
| 84 DrawRectangleLines(GetScreenWidth()/2 - texture.width/2, GetScreenHeight()/2 - texture.height/2 - 5, texture.width, texture.height, BLACK); | |
| 85 | |
| 86 DrawText(fileNameToLoad, 208, GetScreenHeight() - 20, 10, GRAY); | |
| 87 | |
| 88 // raygui: controls drawing | |
| 89 //---------------------------------------------------------------------------------- | |
| 90 if (fileDialogState.windowActive) GuiLock(); | |
| 91 | |
| 92 if (GuiButton((Rectangle){ 20, 20, 140, 30 }, GuiIconText(ICON_FILE_OPEN, "Open Image"))) fileDialogState.windowActive = true; | |
| 93 | |
| 94 GuiUnlock(); | |
| 95 | |
| 96 // GUI: Dialog Window | |
| 97 //-------------------------------------------------------------------------------- | |
| 98 GuiWindowFileDialog(&fileDialogState); | |
| 99 //-------------------------------------------------------------------------------- | |
| 100 | |
| 101 //---------------------------------------------------------------------------------- | |
| 102 | |
| 103 EndDrawing(); | |
| 104 //---------------------------------------------------------------------------------- | |
| 105 } | |
| 106 | |
| 107 // De-Initialization | |
| 108 //-------------------------------------------------------------------------------------- | |
| 109 UnloadTexture(texture); // Unload texture | |
| 110 | |
| 111 CloseWindow(); // Close window and OpenGL context | |
| 112 //-------------------------------------------------------------------------------------- | |
| 113 | |
| 114 return 0; | |
| 115 } |