36 lines
1.0 KiB
Java
36 lines
1.0 KiB
Java
package speiger.src.coreengine.rendering.input;
|
|
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
|
|
import org.lwjgl.glfw.GLFW;
|
|
import org.lwjgl.glfw.GLFWDropCallback;
|
|
|
|
import speiger.src.coreengine.rendering.input.events.FileDropEvent;
|
|
import speiger.src.coreengine.rendering.input.window.ScaledResolution;
|
|
import speiger.src.coreengine.rendering.input.window.Window;
|
|
import speiger.src.coreengine.utils.eventbus.EventBus;
|
|
|
|
public class DropListener
|
|
{
|
|
EventBus bus;
|
|
ScaledResolution resolution;
|
|
|
|
public DropListener(Window window, EventBus bus) {
|
|
window.addCallback(T -> GLFW.glfwSetDropCallback(T, this::onFileDropped));
|
|
resolution = window.getUIFrame();
|
|
this.bus = bus;
|
|
}
|
|
|
|
public void onFileDropped(long windowId, int count, long names) {
|
|
int x = Mouse.getX();
|
|
int y = Mouse.getY();
|
|
for(int i = 0;i<count;i++) {
|
|
Path file = Paths.get(GLFWDropCallback.getName(names, i));
|
|
if(Files.notExists(file)) continue;
|
|
bus.post(new FileDropEvent(file, windowId, x, y, resolution));
|
|
}
|
|
}
|
|
}
|