Hello Guest

GLFW.glfwSetDropCallback

  • 3 Replies
  • 1439 Views
*

Offline Lobo

  • *
  • 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

*

Kai

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.
}
« Last Edit: October 31, 2016, 22:10:52 by Kai »

*

Offline Lobo

  • *
  • 23
Re: GLFW.glfwSetDropCallback
« Reply #2 on: November 01, 2016, 06:44:13 »
Perfect. Thanks a lot!

*

Offline spasi

  • *****
  • 1990
    • WebHotelier
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);
}
});