Add the ability to change the screenshot folder at runtime (#1172)

This commit is contained in:
Alexander Bock
2020-11-16 14:22:56 +01:00
parent 73d920d40d
commit 8d7300a242
4 changed files with 34 additions and 0 deletions

View File

@@ -925,6 +925,9 @@ void setSgctDelegateFunctions() {
return currentWindow->swapGroupFrameNumber();
};
sgctDelegate.setScreenshotFolder = [](std::string path) {
Settings::instance().setCapturePath(std::move(path));
};
}
void checkCommandLineForSettings(int& argc, char** argv, bool& hasSGCT, bool& hasProfile,

View File

@@ -100,6 +100,8 @@ struct WindowDelegate {
Frustum (*frustumMode)() = []() { return Frustum::Mono; };
uint64_t (*swapGroupFrameNumber)() = []() { return uint64_t(0); };
void (*setScreenshotFolder)(std::string) = [](std::string) {};
};
} // namespace openspace

View File

@@ -1522,6 +1522,13 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
"",
"Remove all registered virtual properties"
},
{
"setScreenshotFolder",
&luascriptfunctions::setScreenshotFolder,
{},
"string",
"Sets the folder used for storing screenshots or session recording frames"
},
{
"addTag",
&luascriptfunctions::addTag,

View File

@@ -27,6 +27,7 @@
#include <openspace/properties/triggerproperty.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <filesystem>
namespace openspace::luascriptfunctions {
@@ -182,6 +183,27 @@ int removeAllVirtualProperties(lua_State* L) {
return 0;
}
int setScreenshotFolder(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setScreenshotFolder");
std::string arg = ghoul::lua::value<std::string>(L);
lua_pop(L, 0);
std::string folder = FileSys.absolutePath(arg);
if (!std::filesystem::exists(folder)) {
std::filesystem::create_directory(folder);
}
FileSys.registerPathToken(
"${SCREENSHOTS}",
folder,
ghoul::filesystem::FileSystem::Override::Yes
);
global::windowDelegate->setScreenshotFolder(folder);
return 0;
}
/**
* \ingroup LuaScripts
* addTag()