public void destroy() { if (!context.isRenderable()) { return; } keyCallback.free(); logger.fine("Keyboard destroyed."); }
public void update() { if (!context.isRenderable()) { return; } while (!keyInputEvents.isEmpty()) { listener.onKeyEvent(keyInputEvents.poll()); } }
/** * Set the position of the cursor on the display. * @param x the x position of the cursor (pixel). * @param y the y position of the cursor (pixel). */ public void setCursorPosition(int x, int y) { if (!context.isRenderable()) { return; } glfwSetCursorPos(context.getWindowHandle(), x, y); }
/** * Hide the active cursor within the display. */ public void hideActiveCursor() { if (!context.isRenderable()) { return; } if (cursorVisible) { glfwSetInputMode(context.getWindowHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } }
@Override public void destroy() { if (!context.isRenderable()) { return; } cursorPosCallback.free(); scrollCallback.free(); mouseButtonCallback.free(); for (long glfwCursor : jmeToGlfwCursorMap.values()) { glfwDestroyCursor(glfwCursor); } logger.fine("Mouse destroyed."); }
@Override public void setCursorVisible(boolean visible) { cursorVisible = visible; if (!context.isRenderable()) { return; } if (cursorVisible) { glfwSetInputMode(context.getWindowHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); } else { glfwSetInputMode(context.getWindowHandle(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); } }
public void initialize() { if (!context.isRenderable()) { return; } glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { scancode = GlfwKeyMap.toJmeKeyCode(key); if( key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT ) { shift_pressed = (action == GLFW_PRESS); } else if( key >= 'A' && key <= 'Z' && !shift_pressed ) { key += 32; // make lowercase } else if( key >= 'a' && key <= 'z' && shift_pressed ) { key -= 32; // make uppercase } final KeyInputEvent evt = new KeyInputEvent(scancode, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action); evt.setTime(getInputTimeNanos()); keyInputEvents.add(evt); } }); glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1); initialized = true; logger.fine("Keyboard created."); }