|
| 1 | +/******************************************************************************************* |
| 2 | +* |
| 3 | +* raylib [core] example - directory files |
| 4 | +* |
| 5 | +* Example complexity rating: [★☆☆☆] 1/4 |
| 6 | +* |
| 7 | +* Example originally created with raylib 5.5, last time updated with raylib 5.6 |
| 8 | +* |
| 9 | +* Example contributed by Hugo ARNAL (@hugoarnal) and reviewed by Ramon Santamaria (@raysan5) |
| 10 | +* |
| 11 | +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, |
| 12 | +* BSD-like license that allows static linking with closed source software |
| 13 | +* |
| 14 | +* Copyright (c) 2025 Hugo ARNAL (@hugoarnal) |
| 15 | +* |
| 16 | +********************************************************************************************/ |
| 17 | + |
| 18 | +#include "raylib.h" |
| 19 | + |
| 20 | +//------------------------------------------------------------------------------------ |
| 21 | +// Program main entry point |
| 22 | +//------------------------------------------------------------------------------------ |
| 23 | +int main(void) |
| 24 | +{ |
| 25 | + // Initialization |
| 26 | + //-------------------------------------------------------------------------------------- |
| 27 | + const int screenWidth = 800; |
| 28 | + const int screenHeight = 450; |
| 29 | + |
| 30 | + InitWindow(screenWidth, screenHeight, "raylib [core] example - directory files"); |
| 31 | + |
| 32 | + char *directory = "."; |
| 33 | + FilePathList files = LoadDirectoryFiles(directory); |
| 34 | + |
| 35 | + SetTargetFPS(60); |
| 36 | + //-------------------------------------------------------------------------------------- |
| 37 | + |
| 38 | + // Main game loop |
| 39 | + while (!WindowShouldClose()) // Detect window close button or ESC key |
| 40 | + { |
| 41 | + // Update |
| 42 | + //---------------------------------------------------------------------------------- |
| 43 | + |
| 44 | + // Draw |
| 45 | + //---------------------------------------------------------------------------------- |
| 46 | + BeginDrawing(); |
| 47 | + |
| 48 | + ClearBackground(RAYWHITE); |
| 49 | + |
| 50 | + DrawText(TextFormat("Files in directory \"%s\":", directory), 100, 40, 20, DARKGRAY); |
| 51 | + |
| 52 | + for (int i = 0; i < (int)files.count; i++) { |
| 53 | + float alpha = i % 2 == 0 ? 0.5f : 0.3f; |
| 54 | + DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, alpha)); |
| 55 | + |
| 56 | + DrawText(files.paths[i], 120, 100 + 40*i, 10, GRAY); |
| 57 | + } |
| 58 | + EndDrawing(); |
| 59 | + //---------------------------------------------------------------------------------- |
| 60 | + } |
| 61 | + |
| 62 | + // De-Initialization |
| 63 | + //-------------------------------------------------------------------------------------- |
| 64 | + |
| 65 | + UnloadDirectoryFiles(files); |
| 66 | + |
| 67 | + CloseWindow(); // Close window and OpenGL context |
| 68 | + //-------------------------------------------------------------------------------------- |
| 69 | + |
| 70 | + return 0; |
| 71 | +} |
0 commit comments