Skip to content

Commit

Permalink
Support separate dir for screenshots
Browse files Browse the repository at this point in the history
Signed-off-by: Per Hallsmark <[email protected]>
  • Loading branch information
saxofon committed Jan 19, 2025
1 parent 79facde commit 53dbb3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ RLAPI bool ExportDataAsCode(const unsigned char *data, int dataSize, const char
RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string
RLAPI void UnloadFileText(char *text); // Unload file text data allocated by LoadFileText()
RLAPI bool SaveFileText(const char *fileName, char *text); // Save text data to file (write), string must be '\0' terminated, returns true on success
RLAPI bool SetScreenshotPath(const char *screenshotPath); // Set directory where screenshots are stored, string must be '\0' terminated, dir must exist, returns true on success
//------------------------------------------------------------------

// File system functions
Expand Down
15 changes: 14 additions & 1 deletion src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ typedef struct CoreData {
} Window;
struct {
const char *basePath; // Base path for data storage
const char *screenshotPath; // Path for screenshot storage

} Storage;
struct {
Expand Down Expand Up @@ -671,6 +672,10 @@ void InitWindow(int width, int height, const char *title)
InitPlatform();
//--------------------------------------------------------------

// Now that InitPlatform() has been made, we have a valid basePath.
// Lets default ScreenshotPath to it.
CORE.Storage.screenshotPath = CORE.Storage.basePath;

// Initialize rlgl default data (buffers and shaders)
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
Expand Down Expand Up @@ -1849,6 +1854,14 @@ void UnloadRandomSequence(int *sequence)
#endif
}

bool SetScreenshotPath(const char *screenshotDir)
{
// TODO: verify directory exist
CORE.Storage.screenshotPath = screenshotDir;

return true;
}

// Takes a screenshot of current screen
// NOTE: Provided fileName should not contain paths, saving to working directory
void TakeScreenshot(const char *fileName)
Expand All @@ -1862,7 +1875,7 @@ void TakeScreenshot(const char *fileName)
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };

char path[512] = { 0 };
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, GetFileName(fileName)));
strcpy(path, TextFormat("%s/%s", CORE.Storage.screenshotPath, GetFileName(fileName)));

ExportImage(image, path); // WARNING: Module required: rtextures
RL_FREE(imgData);
Expand Down

0 comments on commit 53dbb3d

Please sign in to comment.