Started work on keyboard
This commit is contained in:
parent
5540f1c042
commit
ab9d11f165
|
@ -0,0 +1,51 @@
|
|||
package speiger.src.coreengine.rendering.input.divices;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import speiger.src.coreengine.rendering.input.divices.Keyboard.KeyTask;
|
||||
import speiger.src.coreengine.rendering.input.divices.Keyboard.KeyboardData;
|
||||
import speiger.src.coreengine.rendering.input.window.Window;
|
||||
|
||||
|
||||
public class Keyboard extends AbstractDevice<KeyboardData, KeyTask> {
|
||||
@Override
|
||||
public void reset(long windowId) {}
|
||||
@Override
|
||||
protected KeyboardData createData(long windowId) { return new KeyboardData(); }
|
||||
@Override
|
||||
protected void process(KeyTask task) {}
|
||||
|
||||
@Override
|
||||
protected void registerCallbacks(Window window) {
|
||||
super.registerCallbacks(window);
|
||||
window.addCallback(this::keyPress, GLFW::glfwSetKeyCallback);
|
||||
window.addCallback(this::charTyped, GLFW::glfwSetCharCallback);
|
||||
}
|
||||
|
||||
private void keyPress(long window, int key, int scancode, int action, int mods) { push(window, new KeyPressed(window, key, scancode, action, mods)); }
|
||||
|
||||
private void charTyped(long window, int codepoint) { push(window, new CharTyped(window, codepoint)); }
|
||||
|
||||
public static class KeyboardData {
|
||||
BiPredicate<Integer, Keyboard> filter;
|
||||
boolean[] pressedKeys = new boolean[350];
|
||||
boolean[] nonConsumedKeys = new boolean[350];
|
||||
|
||||
}
|
||||
|
||||
public static interface KeyTask {
|
||||
public void process(Keyboard board);
|
||||
}
|
||||
|
||||
public record KeyPressed(long window, int key, int scancode, int action, int mods) implements KeyTask {
|
||||
@Override
|
||||
public void process(Keyboard board) {}
|
||||
}
|
||||
|
||||
public record CharTyped(long window, int codepoint) implements KeyTask {
|
||||
@Override
|
||||
public void process(Keyboard board) {}
|
||||
}
|
||||
}
|
|
@ -28,21 +28,12 @@ public class Mouse extends AbstractDevice<MouseData, MouseTask> {
|
|||
window.addCallback(this::scroll, GLFW::glfwSetScrollCallback);
|
||||
}
|
||||
|
||||
private void move(long window, double x, double y) {
|
||||
push(window, new Move(window, x, y));
|
||||
}
|
||||
|
||||
private void click(long window, int button, int action, int mods) {
|
||||
push(window, new Click(window, button, action, mods));
|
||||
}
|
||||
|
||||
private void enter(long window, boolean enter) {
|
||||
push(window, new Enter(window, enter));
|
||||
}
|
||||
|
||||
private void scroll(long window, double xoffset, double yoffset) {
|
||||
push(window, new Scroll(window, xoffset, yoffset));
|
||||
}
|
||||
//@formatter:off
|
||||
private void move(long window, double x, double y) { push(window, new Move(window, x, y)); }
|
||||
private void click(long window, int button, int action, int mods) { push(window, new Click(window, button, action, mods)); }
|
||||
private void enter(long window, boolean enter) { push(window, new Enter(window, enter)); }
|
||||
private void scroll(long window, double xoffset, double yoffset) { push(window, new Scroll(window, xoffset, yoffset)); }
|
||||
//@formatter:on
|
||||
|
||||
public static class MouseData {
|
||||
IntSet buttons = new IntOpenHashSet();
|
||||
|
@ -57,11 +48,13 @@ public class Mouse extends AbstractDevice<MouseData, MouseTask> {
|
|||
scroll.negate();
|
||||
}
|
||||
|
||||
//@formatter:off
|
||||
public int x() { return position.x(); }
|
||||
public int y() { return position.y(); }
|
||||
public boolean pressed(int button) { return buttons.contains(button); }
|
||||
public Vec2i motion() { return motion; }
|
||||
public Vec2i scroll() { return scroll; }
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
public int x(long windowId) {
|
||||
|
|
Loading…
Reference in New Issue