LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: GLFW.glfwSetDropCallback  (Read 496 times)

Lobo

  • Newbie
  • *
  • Offline Offline
  • Posts: 23
GLFW.glfwSetDropCallback
« on: October 31, 2016, 21:12:21 »

Hi,

I'm trying to use the dropCallback of GLFW

Code: [Select]
GLFW.glfwSetDropCallback(window, dropCallBack = new GLFWDropCallback()
{
@Override
public void invoke(long window, int count, long names)
{
        }
});

In the documentation I only find that "names" is a pointer to the array of UTF-8 encoded path names of the dropped files.
But I dont have any glue how to get a readable string from the long.

I dont find anything about this function in the forum.

Would be great if someone could help me.

Thanks a lot and best regards
Lobo
Logged

Kai

  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 900
Re: GLFW.glfwSetDropCallback
« Reply #1 on: October 31, 2016, 21:46:06 »

This will do:
Code: [Select]
public void invoke(long window, int count, long names) {
    PointerBuffer charPointers = MemoryUtil.memPointerBuffer(names, count);
    for (int i = 0; i < count; i++) {
        String name = MemoryUtil.memUTF8(charPointers.get(i));
        System.err.println(name); // <- test: print out the path
    }
    // We MUST NOT call MemoryUtil.memFree(charPointers), because
    // the memory is managed by GLFW internally.
}
Logged

Lobo

  • Newbie
  • *
  • Offline Offline
  • Posts: 23
Re: GLFW.glfwSetDropCallback
« Reply #2 on: November 01, 2016, 06:44:13 »

Perfect. Thanks a lot!
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1805
Re: GLFW.glfwSetDropCallback
« Reply #3 on: November 01, 2016, 08:56:12 »

There's also a shortcut available:

Code: [Select]
glfwSetDropCallback(window, (windowHnd, count, names) -> {
for ( int i = 0; i < count; i++ ) {
String name = GLFWDropCallback.getName(names, i);
System.err.println(name);
}
});
Logged