Skip to content

Commit

Permalink
Created an event to be called when key callback is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
PanJohnny committed Oct 25, 2023
1 parent e9176f3 commit d47f13a
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.panjohnny.pjgl.adapt.lwjgl;

import com.panjohnny.pjgl.adapt.Adaptation;
import com.panjohnny.pjgl.api.event.PJGLEvent;
import com.panjohnny.pjgl.core.adapters.KeyboardAdapter;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWKeyCallbackI;

@Adaptation("lwjgl@pjgl")
public class GLFWKeyboard implements KeyboardAdapter, GLFWKeyCallbackI {
private final boolean[] keys;
public PJGLEvent<KeyCallbackParams> GLFW_INVOKE = new PJGLEvent<>();

public GLFWKeyboard() {
this.keys = new boolean[GLFW.GLFW_KEY_LAST];
Expand Down Expand Up @@ -40,5 +42,10 @@ public void invoke(long window, int key, int scancode, int action, int mods) {
if (key >= 0 && key < keys.length) {
keys[key] = action != GLFW.GLFW_RELEASE;
}
GLFW_INVOKE.call(new KeyCallbackParams(window, key, scancode, action, mods));
}

public record KeyCallbackParams(long window, int key, int scancode, int action, int mods) {

}
}

0 comments on commit d47f13a

Please sign in to comment.