My input handler seems to have trouble handling clicks, and will hang on a given state in my [icode]Button[/icode] class too long.
Here is my input handler:
public Input(long window) {
Arrays.fill(states, false);
keyCallback = new GLFWKeyCallback() {
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
boolean down = action == GLFW.GLFW_PRESS;
int keycode = key;
if (states[key] && !down) {
for (Adapter adapter : adapters) {
adapter.key(keycode);
}
}
states[key] = down;
}
};
GLFW.glfwSetKeyCallback(window, keyCallback);
mouseStateCallback = new GLFWMouseButtonCallback() {
@Override
public void invoke(long window, int button, int action, int mods) {
boolean down = GLFW.glfwGetMouseButton(window, button) == GLFW.GLFW_PRESS;
if (!down && mouseDown) {
@@ for (Adapter adapter : adapters) {
@@ adapter.click(x, y);
@@ }
}
mouseDown = down;
}
};
GLFW.glfwSetMouseButtonCallback(window, mouseStateCallback);
cursorCallback = new GLFWCursorPosCallback() {
@Override
public void invoke(long window, double mousex, double mousey) {
@@ boolean down = GLFW.glfwGetMouseButton(window, GLFW.GLFW_MOUSE_BUTTON_1) == GLFW.GLFW_PRESS;
@@ if (!down && mouseDown) {
@@ for (Adapter adapter : adapters) {
@@ adapter.click(mousex, mousey);
@@ }
}
mouseDown = down;
x = mousex;
y = mousey;
for (Adapter adapter : adapters) {
adapter.mouse(x, y, mouseDown);
}
}
};
GLFW.glfwSetCursorPosCallback(window, cursorCallback);
cursorEnterCallback = new GLFWCursorEnterCallback() {
@Override
public void invoke(long window, int entered) {
inScreen = entered == GL11.GL_TRUE;
}
};
GLFW.glfwSetCursorEnterCallback(window, cursorEnterCallback);
}
The lag shouldn’t be caused by the rendering itself because it renders one line of text (using a vertex buffer object for each glyph) and renders one vertex buffer object for the button. However, when my Adapter interfaces handle the input, there is a hangup where they sometimes don’t even receive the event.
Any help would be appreciated.