REVIEWED: Move screen capture logic to rcore.c
, available for all platforms
This commit is contained in:
parent
daf227a185
commit
3ff6026917
3 changed files with 39 additions and 115 deletions
|
@ -1658,61 +1658,6 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
||||||
|
|
||||||
// Check the exit key to set close window
|
// Check the exit key to set close window
|
||||||
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE);
|
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE);
|
||||||
|
|
||||||
#if defined(SUPPORT_SCREEN_CAPTURE)
|
|
||||||
if ((key == GLFW_KEY_F12) && (action == GLFW_PRESS))
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (mods & GLFW_MOD_CONTROL)
|
|
||||||
{
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
gifRecording = false;
|
|
||||||
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
|
|
||||||
SaveFileData(TextFormat("%s/screenrec%03i.gif", CORE.Storage.basePath, screenshotCounter), result.data, (unsigned int)result.dataSize);
|
|
||||||
msf_gif_free(result);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "SYSTEM: Finish animated GIF recording");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gifRecording = true;
|
|
||||||
gifFrameCounter = 0;
|
|
||||||
|
|
||||||
Vector2 scale = GetWindowScaleDPI();
|
|
||||||
msf_gif_begin(&gifState, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
|
|
||||||
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)
|
|
||||||
if ((key == GLFW_KEY_F11) && (action == GLFW_PRESS))
|
|
||||||
{
|
|
||||||
eventsRecording = !eventsRecording;
|
|
||||||
|
|
||||||
// On finish recording, we export events into a file
|
|
||||||
if (!eventsRecording) ExportAutomationEvents("eventsrec.rep");
|
|
||||||
}
|
|
||||||
else if ((key == GLFW_KEY_F9) && (action == GLFW_PRESS))
|
|
||||||
{
|
|
||||||
LoadAutomationEvents("eventsrec.rep");
|
|
||||||
eventsPlaying = true;
|
|
||||||
|
|
||||||
TRACELOG(LOG_WARNING, "eventsPlaying enabled!");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3 Char Key Callback, runs on key down (gets equivalent unicode char value)
|
// GLFW3 Char Key Callback, runs on key down (gets equivalent unicode char value)
|
||||||
|
|
|
@ -1044,65 +1044,6 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
||||||
|
|
||||||
// Check the exit key to set close window
|
// Check the exit key to set close window
|
||||||
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE);
|
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE);
|
||||||
|
|
||||||
#if defined(SUPPORT_SCREEN_CAPTURE)
|
|
||||||
if ((key == GLFW_KEY_F12) && (action == GLFW_PRESS))
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (mods & GLFW_MOD_CONTROL)
|
|
||||||
{
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
gifRecording = false;
|
|
||||||
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
|
|
||||||
SaveFileData(TextFormat("%s/screenrec%03i.gif", CORE.Storage.basePath, screenshotCounter), result.data, (unsigned int)result.dataSize);
|
|
||||||
msf_gif_free(result);
|
|
||||||
|
|
||||||
// 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)));
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "SYSTEM: Finish animated GIF recording");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gifRecording = true;
|
|
||||||
gifFrameCounter = 0;
|
|
||||||
|
|
||||||
Vector2 scale = GetWindowScaleDPI();
|
|
||||||
msf_gif_begin(&gifState, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
|
|
||||||
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)
|
|
||||||
if ((key == GLFW_KEY_F11) && (action == GLFW_PRESS))
|
|
||||||
{
|
|
||||||
eventsRecording = !eventsRecording;
|
|
||||||
|
|
||||||
// On finish recording, we export events into a file
|
|
||||||
if (!eventsRecording) ExportAutomationEvents("eventsrec.rep");
|
|
||||||
}
|
|
||||||
else if ((key == GLFW_KEY_F9) && (action == GLFW_PRESS))
|
|
||||||
{
|
|
||||||
LoadAutomationEvents("eventsrec.rep");
|
|
||||||
eventsPlaying = true;
|
|
||||||
|
|
||||||
TRACELOG(LOG_WARNING, "eventsPlaying enabled!");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3 Char Key Callback, runs on key down (gets equivalent unicode char value)
|
// GLFW3 Char Key Callback, runs on key down (gets equivalent unicode char value)
|
||||||
|
|
40
src/rcore.c
40
src/rcore.c
|
@ -739,6 +739,44 @@ void EndDrawing(void)
|
||||||
PollInputEvents(); // Poll user events (before next frame update)
|
PollInputEvents(); // Poll user events (before next frame update)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_SCREEN_CAPTURE)
|
||||||
|
if (IsKeyPressed(KEY_F12))
|
||||||
|
{
|
||||||
|
#if defined(SUPPORT_GIF_RECORDING)
|
||||||
|
if (IsKeyDown(KEY_LEFT_CONTROL))
|
||||||
|
{
|
||||||
|
if (gifRecording)
|
||||||
|
{
|
||||||
|
gifRecording = false;
|
||||||
|
|
||||||
|
MsfGifResult result = msf_gif_end(&gifState);
|
||||||
|
|
||||||
|
SaveFileData(TextFormat("%s/screenrec%03i.gif", CORE.Storage.basePath, screenshotCounter), result.data, (unsigned int)result.dataSize);
|
||||||
|
msf_gif_free(result);
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "SYSTEM: Finish animated GIF recording");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gifRecording = true;
|
||||||
|
gifFrameCounter = 0;
|
||||||
|
|
||||||
|
Vector2 scale = GetWindowScaleDPI();
|
||||||
|
msf_gif_begin(&gifState, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
|
||||||
|
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)
|
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
||||||
// Events recording and playing logic
|
// Events recording and playing logic
|
||||||
if (eventsRecording) RecordAutomationEvent(CORE.Time.frameCounter);
|
if (eventsRecording) RecordAutomationEvent(CORE.Time.frameCounter);
|
||||||
|
@ -748,7 +786,7 @@ void EndDrawing(void)
|
||||||
if (CORE.Time.frameCounter >= eventCount) eventsPlaying = false;
|
if (CORE.Time.frameCounter >= eventCount) eventsPlaying = false;
|
||||||
PlayAutomationEvent(CORE.Time.frameCounter);
|
PlayAutomationEvent(CORE.Time.frameCounter);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // SUPPORT_EVENTS_AUTOMATION
|
||||||
|
|
||||||
CORE.Time.frameCounter++;
|
CORE.Time.frameCounter++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue