Added virtual Mouse input

This commit is contained in:
Speiger 2024-05-20 16:51:58 +02:00
parent 61d48be579
commit 867733cdfc
3 changed files with 15 additions and 9 deletions

View File

@ -32,16 +32,11 @@ public class NewInputTest {
//TODO implement window close requests
while(true) {
GLFW.glfwPollEvents();
window.update();
window.beginFrame();
window.handleInput();
window.finishFrame();
try {
Thread.sleep(100);
}
catch(InterruptedException e) {
e.printStackTrace();
}
try { Thread.sleep(100); }
catch(InterruptedException e) { e.printStackTrace(); }
}
}
}

View File

@ -82,6 +82,16 @@ public class Mouse extends AbstractDevice<MouseData, MouseTask> {
return data == null ? Vec2i.ZERO : data.scroll();
}
public void setPosition(long windowId, int x, int y) {
MouseData data = get(windowId);
if(data == null || (data.position.x() == x && data.position.y() == y)) return;
data.position.set(x, y);
GLFW.glfwSetCursorPos(windowId, x, y);
}
public void pressButton(long window, int button, boolean press) { click(window, button, press ? GLFW.GLFW_PRESS : GLFW.GLFW_RELEASE, 0); }
public void scrollMouse(long window, int xScroll, int yScroll) { scroll(window, xScroll, yScroll); }
public interface MouseTask {
public void process(Mouse mouse);
}

View File

@ -138,7 +138,8 @@ public class Window {
}
}
public void update() {
public void beginFrame() {
GLFW.glfwMakeContextCurrent(id);
if(flags.isFlagSet(WINDOW_CHANGE)) updateViewport();
}