Skip to content

Instantly share code, notes, and snippets.

@chrisdill
Created June 20, 2021 17:30
Show Gist options
  • Save chrisdill/28fbaa9b66bfc19f84efbb107e4ed871 to your computer and use it in GitHub Desktop.
Save chrisdill/28fbaa9b66bfc19f84efbb107e4ed871 to your computer and use it in GitHub Desktop.
Testing changes to tools in core(gifs/screenshots/events) to make it easier to maintain/modify.
// Built in tools for learning and testing
static void UpdateTools()
{
#if defined(SUPPORT_SCREEN_CAPTURE)
// Check screen capture key (raylib key: KEY_F12)
if (IsKeyPressed(KEY_F12))
{
#if defined(SUPPORT_GIF_RECORDING) && defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP)
if (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL))
{
if (gifRecording)
{
gifRecording = false;
MsfGifResult result = msf_gif_end(&gifState);
char path[512] = { 0 };
#if defined(PLATFORM_ANDROID)
strcpy(path, CORE.Android.internalDataPath);
strcat(path, TextFormat("./screenrec%03i.gif", screenshotCounter));
#elif defined(PLATFORM_UWP)
strcat(path, TextFormat("%s/screenrec%03i.gif", CORE.UWP.internalDataPath, screenshotCounter));
#else
strcpy(path, TextFormat("./screenrec%03i.gif", screenshotCounter));
#endif
SaveFileData(path, result.data, (unsigned int)result.dataSize);
msf_gif_free(result);
#if defined(PLATFORM_WEB)
// Download file from MEMFS (emscripten memory filesystem)
// saveFileFromMEMFSToDisk() function is defined in raylib/templates/web_shel/shell.html
emscripten_run_script(TextFormat("saveFileFromMEMFSToDisk('%s','%s')", TextFormat("screenrec%03i.gif", screenshotCounter - 1), TextFormat("screenrec%03i.gif", screenshotCounter - 1)));
#endif
TRACELOG(LOG_INFO, "SYSTEM: Finish animated GIF recording");
}
else
{
gifRecording = true;
gifFramesCounter = 0;
msf_gif_begin(&gifState, CORE.Window.screen.width, CORE.Window.screen.height);
screenshotCounter++;
TRACELOG(LOG_INFO, "SYSTEM: Start animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter));
}
}
else
#endif // SUPPORT_GIF_RECORDING
{
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
screenshotCounter++;
}
}
#endif // SUPPORT_SCREEN_CAPTURE
#if defined(SUPPORT_EVENTS_AUTOMATION) && defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
else if (IsKeyPressed(KEY_F11))
{
eventsRecording = !eventsRecording;
// On finish recording, we export events into a file
if (!eventsRecording) ExportAutomationEvents("eventsrec.rep");
}
else if (IsKeyPressed(KEY_F9))
{
LoadAutomationEvents("eventsrec.rep");
eventsPlaying = true;
TRACELOG(LOG_WARNING, "eventsPlaying enabled!");
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment