diff --git a/src/main/java/speiger/src/coreengine/rendering/input/divices/Keyboard.java b/src/main/java/speiger/src/coreengine/rendering/input/divices/Keyboard.java new file mode 100644 index 0000000..0b1b3de --- /dev/null +++ b/src/main/java/speiger/src/coreengine/rendering/input/divices/Keyboard.java @@ -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 { + @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 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) {} + } +} diff --git a/src/main/java/speiger/src/coreengine/rendering/input/divices/Mouse.java b/src/main/java/speiger/src/coreengine/rendering/input/divices/Mouse.java index bb35e96..1f3bb4e 100644 --- a/src/main/java/speiger/src/coreengine/rendering/input/divices/Mouse.java +++ b/src/main/java/speiger/src/coreengine/rendering/input/divices/Mouse.java @@ -28,21 +28,12 @@ public class Mouse extends AbstractDevice { 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 { 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) {