diff options
| author | Ray <[email protected]> | 2022-06-11 23:24:13 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2022-06-11 23:24:13 +0200 |
| commit | b8f67c628553cb9199f51efc9b20eb5991d58e8f (patch) | |
| tree | 9a5dd90da94402c4505b4e6952d0f831743ee7ee /examples | |
| parent | f7744404d672743b01970429f7c5f4c9136f2c7c (diff) | |
| download | raylib-b8f67c628553cb9199f51efc9b20eb5991d58e8f.tar.gz raylib-b8f67c628553cb9199f51efc9b20eb5991d58e8f.zip | |
WARNING: BREAKING: REDESIGNED: Filepath loading API
REDESIGNED: `LoadDirectoryFiles()`
ADDED: `LoadDirectoryFilesEx()`
REDESIGNED: `LoadDroppedFiles()`
ADDED: `IsPathFile()`
This BIG BREAKING change simplifies the functions and gives more control to the user:
- A new `struct FilePathList` has been added to avoid exposing complex pointers.
- User is responsible of memory loading/unloading
- Filepaths loading support recursive directories and file extension filters
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/core/core_drop_files.c | 13 | ||||
| -rw-r--r-- | examples/models/models_loading.c | 25 | ||||
| -rw-r--r-- | examples/models/models_skybox.c | 13 | ||||
| -rw-r--r-- | examples/text/text_draw_3d.c | 14 | ||||
| -rw-r--r-- | examples/text/text_font_filters.c | 10 |
5 files changed, 38 insertions, 37 deletions
diff --git a/examples/core/core_drop_files.c b/examples/core/core_drop_files.c index 129ced10..0a1a71e9 100644 --- a/examples/core/core_drop_files.c +++ b/examples/core/core_drop_files.c @@ -22,8 +22,7 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); - int count = 0; - char **droppedFiles = { 0 }; + FilePathList droppedFiles = { 0 }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -35,7 +34,11 @@ int main(void) //---------------------------------------------------------------------------------- if (IsFileDropped()) { - droppedFiles = LoadDroppedFiles(&count); + // Is some files have been previously loaded, unload them + if (droppedFiles.count > 0) UnloadDroppedFiles(droppedFiles); + + // Load new dropped files + droppedFiles = LoadDroppedFiles(); } //---------------------------------------------------------------------------------- @@ -55,7 +58,7 @@ int main(void) if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); - DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY); + DrawText(droppedFiles.paths[i], 120, 100 + 40*i, 10, GRAY); } DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY); @@ -67,7 +70,7 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- - UnloadDroppedFiles(); // Clear internal buffers + UnloadDroppedFiles(droppedFiles); // Unload files memory CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/models/models_loading.c b/examples/models/models_loading.c index 7d4543cd..ee3811ee 100644 --- a/examples/models/models_loading.c +++ b/examples/models/models_loading.c @@ -67,35 +67,34 @@ int main(void) // Load new models/textures on drag&drop if (IsFileDropped()) { - int count = 0; - char **droppedFiles = LoadDroppedFiles(&count); + FilePathList droppedFiles = LoadDroppedFiles(); - if (count == 1) // Only support one file dropped + if (droppedFiles.count == 1) // Only support one file dropped { - if (IsFileExtension(droppedFiles[0], ".obj") || - IsFileExtension(droppedFiles[0], ".gltf") || - IsFileExtension(droppedFiles[0], ".glb") || - IsFileExtension(droppedFiles[0], ".vox") || - IsFileExtension(droppedFiles[0], ".iqm")) // Model file formats supported + if (IsFileExtension(droppedFiles.paths[0], ".obj") || + IsFileExtension(droppedFiles.paths[0], ".gltf") || + IsFileExtension(droppedFiles.paths[0], ".glb") || + IsFileExtension(droppedFiles.paths[0], ".vox") || + IsFileExtension(droppedFiles.paths[0], ".iqm")) // Model file formats supported { - UnloadModel(model); // Unload previous model - model = LoadModel(droppedFiles[0]); // Load new model + UnloadModel(model); // Unload previous model + model = LoadModel(droppedFiles.paths[0]); // Load new model model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set current map diffuse texture bounds = GetMeshBoundingBox(model.meshes[0]); // TODO: Move camera position from target enough distance to visualize model properly } - else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported + else if (IsFileExtension(droppedFiles.paths[0], ".png")) // Texture file formats supported { // Unload current model texture and load new one UnloadTexture(texture); - texture = LoadTexture(droppedFiles[0]); + texture = LoadTexture(droppedFiles.paths[0]); model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; } } - UnloadDroppedFiles(); // Clear internal buffers + UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory } // Select model on mouse click diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index b5e0102d..88202aee 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -97,18 +97,17 @@ int main(void) // Load new cubemap texture on drag&drop if (IsFileDropped()) { - int count = 0; - char **droppedFiles = LoadDroppedFiles(&count); + FilePathList droppedFiles = LoadDroppedFiles(); - if (count == 1) // Only support one file dropped + if (droppedFiles.count == 1) // Only support one file dropped { - if (IsFileExtension(droppedFiles[0], ".png;.jpg;.hdr;.bmp;.tga")) + if (IsFileExtension(droppedFiles.paths[0], ".png;.jpg;.hdr;.bmp;.tga")) { // Unload current cubemap texture and load new one UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture); if (useHDR) { - Texture2D panorama = LoadTexture(droppedFiles[0]); + Texture2D panorama = LoadTexture(droppedFiles.paths[0]); // Generate cubemap from panorama texture skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); @@ -116,7 +115,7 @@ int main(void) } else { - Image img = LoadImage(droppedFiles[0]); + Image img = LoadImage(droppedFiles.paths[0]); skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(img, CUBEMAP_LAYOUT_AUTO_DETECT); UnloadImage(img); } @@ -125,7 +124,7 @@ int main(void) } } - UnloadDroppedFiles(); // Clear internal buffers + UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory } //---------------------------------------------------------------------------------- diff --git a/examples/text/text_draw_3d.c b/examples/text/text_draw_3d.c index c82629de..d4b057ec 100644 --- a/examples/text/text_draw_3d.c +++ b/examples/text/text_draw_3d.c @@ -141,22 +141,22 @@ int main(void) // Handle font files dropped if (IsFileDropped()) { - int count = 0; - char **droppedFiles = LoadDroppedFiles(&count); + FilePathList droppedFiles = LoadDroppedFiles(); // NOTE: We only support first ttf file dropped - if (IsFileExtension(droppedFiles[0], ".ttf")) + if (IsFileExtension(droppedFiles.paths[0], ".ttf")) { UnloadFont(font); - font = LoadFontEx(droppedFiles[0], fontSize, 0, 0); + font = LoadFontEx(droppedFiles.paths[0], fontSize, 0, 0); } - else if (IsFileExtension(droppedFiles[0], ".fnt")) + else if (IsFileExtension(droppedFiles.paths[0], ".fnt")) { UnloadFont(font); - font = LoadFont(droppedFiles[0]); + font = LoadFont(droppedFiles.paths[0]); fontSize = font.baseSize; } - UnloadDroppedFiles(); + + UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory } // Handle Events diff --git a/examples/text/text_font_filters.c b/examples/text/text_font_filters.c index 5fb8fc47..32ae11a6 100644 --- a/examples/text/text_font_filters.c +++ b/examples/text/text_font_filters.c @@ -79,16 +79,16 @@ int main(void) // Load a dropped TTF file dynamically (at current fontSize) if (IsFileDropped()) { - int count = 0; - char **droppedFiles = LoadDroppedFiles(&count); + FilePathList droppedFiles = LoadDroppedFiles(); // NOTE: We only support first ttf file dropped - if (IsFileExtension(droppedFiles[0], ".ttf")) + if (IsFileExtension(droppedFiles.paths[0], ".ttf")) { UnloadFont(font); - font = LoadFontEx(droppedFiles[0], (int)fontSize, 0, 0); - UnloadDroppedFiles(); + font = LoadFontEx(droppedFiles.paths[0], (int)fontSize, 0, 0); } + + UnloadDroppedFiles(droppedFiles); // Unload filepaths from memory } //---------------------------------------------------------------------------------- |
