@Override public void uncaughtException(Thread thread, Throwable thrown) { listener.handleError("Uncaught exception thrown in " + thread.toString(), thrown); if (needClose.get()) { // listener.handleError() has requested the // context to close. Satisfy request. deinitInThread(); } } });
/** * 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); }
@Override public void create(boolean waitFor) { if (created.get()) { LOGGER.warning("create() called when display is already created!"); return; } mainThread = Thread.currentThread(); run(); }
destroyContext(); createContext(settings); } catch (Exception ex) { LOGGER.log(Level.SEVERE, "Failed to set display settings!", ex); if (frameRateLimit != getSettings().getFrameRate()) { setFrameRateLimit(getSettings().getFrameRate()); setFrameRateLimit(20);
@Override public void run() { if (listener == null) { throw new IllegalStateException("SystemListener is not set on context!" + "Must set with JmeContext.setSystemListener()."); } LOGGER.log(Level.FINE, "Using LWJGL {0}", Version.getVersion()); if (!initInThread()) { LOGGER.log(Level.SEVERE, "Display initialization failed. Cannot continue."); return; } while (true) { runLoop(); if (needClose.get()) { break; } if (glfwWindowShouldClose(window) == true) { listener.requestClose(false); } } deinitInThread(); }
loadNatives(); timer = new NanoTimer(); createContext(settings); printContextInitInfo();
public void update() { if (!context.isRenderable()) { return; } while (!keyInputEvents.isEmpty()) { listener.onKeyEvent(keyInputEvents.poll()); } }
public void setNativeCursor(JmeCursor jmeCursor) { if (jmeCursor != null) { Long glfwCursor = jmeToGlfwCursorMap.get(jmeCursor); if (glfwCursor == null) { glfwCursor = createGlfwCursor(jmeCursor); jmeToGlfwCursorMap.put(jmeCursor, glfwCursor); } glfwSetCursor(context.getWindowHandle(), glfwCursor); } else { glfwSetCursor(context.getWindowHandle(), MemoryUtil.NULL); } }
/** * De-initialize in the OpenGL thread. */ protected void deinitInThread() { listener.destroy(); destroyContext(); super.internalDestroy(); LOGGER.fine("Display destroyed."); }
private void onCursorPos(long window, double xpos, double ypos) { int x = (int) Math.round(xpos); int y = context.getSettings().getHeight() - (int) Math.round(ypos); if (mouseX == 0) { mouseX = x; } if (mouseY == 0) { mouseY = y; } xDelta = x - mouseX; yDelta = y - mouseY; mouseX = x; mouseY = y; if (xDelta != 0 || yDelta != 0) { final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(x, y, xDelta, yDelta, mouseWheel, 0); mouseMotionEvent.setTime(getInputTimeNanos()); mouseMotionEvents.add(mouseMotionEvent); } }
public void destroy() { if (!context.isRenderable()) { return; } keyCallback.free(); logger.fine("Keyboard destroyed."); }
public void initialize() { glfwSetCursorPosCallback(context.getWindowHandle(), cursorPosCallback = new GLFWCursorPosCallback() { @Override public void invoke(long window, double xpos, double ypos) { onCursorPos(window, xpos, ypos); } }); glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() { @Override public void invoke(final long window, final double xOffset, final double yOffset) { onWheelScroll(window, xOffset, yOffset * WHEEL_SCALE); } }); glfwSetMouseButtonCallback(context.getWindowHandle(), mouseButtonCallback = new GLFWMouseButtonCallback() { @Override public void invoke(final long window, final int button, final int action, final int mods) { onMouseButton(window, button, action, mods); } }); setCursorVisible(cursorVisible); logger.fine("Mouse created."); initialized = true; }
/** * 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."); }