mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-12 14:40:00 -06:00
Add drag and drop support for images and assets (#1497)
This commit is contained in:
@@ -83,6 +83,7 @@
|
||||
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
|
||||
#include <glbinding/glbinding.h>
|
||||
#include <glbinding-aux/types_to_string.h>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
@@ -1444,6 +1445,52 @@ void OpenSpaceEngine::touchExitCallback(TouchInput input) {
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::handleDragDrop(const std::string& file) {
|
||||
std::filesystem::path f(file);
|
||||
|
||||
ghoul::lua::LuaState s(ghoul::lua::LuaState::IncludeStandardLibrary::Yes);
|
||||
std::string absolutePath = absPath("${SCRIPTS}/drag_drop_handler.lua");
|
||||
int status = luaL_loadfile(s, absolutePath.c_str());
|
||||
if (status != LUA_OK) {
|
||||
std::string error = lua_tostring(s, -1);
|
||||
LERROR(error);
|
||||
return;
|
||||
}
|
||||
|
||||
ghoul::lua::push(s, file);
|
||||
lua_setglobal(s, "filename");
|
||||
|
||||
std::string basename = f.filename().string();
|
||||
ghoul::lua::push(s, basename);
|
||||
lua_setglobal(s, "basename");
|
||||
|
||||
std::string extension = f.extension().string();
|
||||
std::transform(
|
||||
extension.begin(), extension.end(),
|
||||
extension.begin(),
|
||||
[](char c) { return static_cast<char>(::tolower(c)); }
|
||||
);
|
||||
ghoul::lua::push(s, extension);
|
||||
lua_setglobal(s, "extension");
|
||||
|
||||
status = lua_pcall(s, 0, 1, 0);
|
||||
if (status != LUA_OK) {
|
||||
std::string error = lua_tostring(s, -1);
|
||||
LERROR(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lua_isnil(s, -1)) {
|
||||
LWARNING(fmt::format("Unhandled file dropped: {}", file));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string script = ghoul::lua::value<std::string>(s);
|
||||
global::scriptEngine->queueScript(
|
||||
script,
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<std::byte> OpenSpaceEngine::encode() {
|
||||
ZoneScoped
|
||||
|
||||
Reference in New Issue
Block a user