diff --git a/include/polyscope/options.h b/include/polyscope/options.h index 27163c5c..a65035cd 100644 --- a/include/polyscope/options.h +++ b/include/polyscope/options.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "imgui.h" @@ -141,6 +142,9 @@ extern std::function configureImGuiStyleCallback; // assign your own function to create custom styles. If this callback is null, default fonts will be used. extern std::function()> prepareImGuiFontsCallback; +// A callback function which will be invoked when a file is dropped on the Polyscope window. No action is taken by default. +extern std::function&)> filesDroppedCallback; + // === Backend and low-level options // When using the EGL backend, which device to try to initialize with diff --git a/include/polyscope/slice_plane.h b/include/polyscope/slice_plane.h index f1286011..ecb617f8 100644 --- a/include/polyscope/slice_plane.h +++ b/include/polyscope/slice_plane.h @@ -49,6 +49,8 @@ class SlicePlane { void setPose(glm::vec3 planePosition, glm::vec3 planeNormal); // == Some getters and setters + glm::vec3 getCenter(); + glm::vec3 getNormal(); bool getActive(); void setActive(bool newVal); @@ -104,8 +106,6 @@ class SlicePlane { void setSliceAttributes(render::ShaderProgram& p); void createVolumeSliceProgram(); void prepare(); - glm::vec3 getCenter(); - glm::vec3 getNormal(); void updateWidgetEnabled(); }; diff --git a/src/options.cpp b/src/options.cpp index fb229bc8..5ad8f665 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -66,6 +66,7 @@ bool renderScene = true; bool openImGuiWindowForUserCallback = true; std::function configureImGuiStyleCallback = configureImGuiStyle; std::function()> prepareImGuiFontsCallback = prepareImGuiFonts; +std::function&)> filesDroppedCallback = nullptr; // Backend and low-level options int eglDeviceIndex = -1; // means "try all of them" diff --git a/src/polyscope.cpp b/src/polyscope.cpp index 9d9b360e..aa5f46ca 100644 --- a/src/polyscope.cpp +++ b/src/polyscope.cpp @@ -1167,6 +1167,9 @@ void shutdown(bool allowMidFrameShutdown) { removeAllSlicePlanes(); clearMessages(); state::userCallback = nullptr; + options::configureImGuiStyleCallback = nullptr; + options::prepareImGuiFontsCallback = nullptr; + options::filesDroppedCallback = nullptr; // Shut down the render engine render::engine->shutdown(); diff --git a/src/render/opengl/gl_engine_glfw.cpp b/src/render/opengl/gl_engine_glfw.cpp index 5f49aa20..34f619ec 100644 --- a/src/render/opengl/gl_engine_glfw.cpp +++ b/src/render/opengl/gl_engine_glfw.cpp @@ -80,8 +80,21 @@ void GLEngineGLFW::initialize() { setWindowResizable(view::windowResizable); -// === Initialize openGL -// Load openGL functions (using GLAD) + // Drag & drop support + glfwSetDropCallback(mainWindow, [](GLFWwindow* window, int path_count, const char* paths[]) { + if (!options::filesDroppedCallback) + return; + + std::vector pathsVec(path_count); + for (int i = 0; i < path_count; i++) { + pathsVec[i] = paths[i]; + } + options::filesDroppedCallback(pathsVec); + }); + + + // === Initialize openGL + // Load openGL functions (using GLAD) #ifndef __APPLE__ if (!gladLoadGL()) { exception("ERROR: Failed to load openGL using GLAD");