Skip to content

Commit 0ff26c2

Browse files
merlinNDnmwsharp
authored andcommitted
Add customizable drag & drop callback (GLFW)
1 parent 61fc32a commit 0ff26c2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

include/polyscope/options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <functional>
66
#include <string>
77
#include <tuple>
8+
#include <vector>
89

910
#include "imgui.h"
1011

@@ -141,6 +142,9 @@ extern std::function<void()> configureImGuiStyleCallback;
141142
// assign your own function to create custom styles. If this callback is null, default fonts will be used.
142143
extern std::function<std::tuple<ImFontAtlas*, ImFont*, ImFont*>()> prepareImGuiFontsCallback;
143144

145+
// A callback function which will be invoked when a file is dropped on the Polyscope window. No action is taken by default.
146+
extern std::function<void(const std::vector<std::string>&)> filesDroppedCallback;
147+
144148
// === Backend and low-level options
145149

146150
// When using the EGL backend, which device to try to initialize with

src/options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ bool renderScene = true;
6666
bool openImGuiWindowForUserCallback = true;
6767
std::function<void()> configureImGuiStyleCallback = configureImGuiStyle;
6868
std::function<std::tuple<ImFontAtlas*, ImFont*, ImFont*>()> prepareImGuiFontsCallback = prepareImGuiFonts;
69+
std::function<void(const std::vector<std::string>&)> filesDroppedCallback = nullptr;
6970

7071
// Backend and low-level options
7172
int eglDeviceIndex = -1; // means "try all of them"

src/render/opengl/gl_engine_glfw.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,21 @@ void GLEngineGLFW::initialize() {
8080

8181
setWindowResizable(view::windowResizable);
8282

83-
// === Initialize openGL
84-
// Load openGL functions (using GLAD)
83+
// Drag & drop support
84+
glfwSetDropCallback(mainWindow, [](GLFWwindow* window, int path_count, const char* paths[]) {
85+
if (!options::filesDroppedCallback)
86+
return;
87+
88+
std::vector<std::string> pathsVec(path_count);
89+
for (int i = 0; i < path_count; i++) {
90+
pathsVec[i] = paths[i];
91+
}
92+
options::filesDroppedCallback(pathsVec);
93+
});
94+
95+
96+
// === Initialize openGL
97+
// Load openGL functions (using GLAD)
8598
#ifndef __APPLE__
8699
if (!gladLoadGL()) {
87100
exception("ERROR: Failed to load openGL using GLAD");

0 commit comments

Comments
 (0)