From afd8b95450c3a0f55e590b73ece260be6c1f93a1 Mon Sep 17 00:00:00 2001 From: Merlin Nimier-David Date: Fri, 5 Dec 2025 15:18:01 +0100 Subject: [PATCH 1/3] Add customizable drag & drop callback (GLFW) --- include/polyscope/options.h | 4 ++++ src/options.cpp | 1 + src/render/opengl/gl_engine_glfw.cpp | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) 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/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/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"); From 2dc2cd4a154edd53e0fa73a444abe3702a83d71b Mon Sep 17 00:00:00 2001 From: Merlin Nimier-David Date: Tue, 9 Dec 2025 11:14:14 +0100 Subject: [PATCH 2/3] Clear callbacks at shutdown --- src/polyscope.cpp | 3 +++ 1 file changed, 3 insertions(+) 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(); From 0fa98f30dbefc27ae0715295cd8bdec2e1f9b711 Mon Sep 17 00:00:00 2001 From: Merlin Nimier-David Date: Wed, 10 Dec 2025 15:17:12 +0100 Subject: [PATCH 3/3] Slice plane: make center & normal getters public --- include/polyscope/slice_plane.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(); };