@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); } }
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);
deinitInThread(); createContext(settings); printContextInitInfo(); initOpenCL(window);
@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)) { listener.requestClose(false); } } deinitInThread(); }
@Override public void update() { // Manage cursor animation if (currentCursor != null && currentCursor.length > 1) { double now = glfwGetTime(); double frameTime = (glfwGetTime() - currentCursorFrameStartTime) * 1000; if (currentCursorDelays == null || frameTime >= currentCursorDelays.get(currentCursorFrame)) { currentCursorFrame = ++currentCursorFrame % currentCursor.length; currentCursorFrameStartTime = now; glfwSetCursor(context.getWindowHandle(), currentCursor[currentCursorFrame]); } } // Process events while (!mouseMotionEvents.isEmpty()) { listener.onMouseMotionEvent(mouseMotionEvents.poll()); } while (!mouseButtonEvents.isEmpty()) { listener.onMouseButtonEvent(mouseButtonEvents.poll()); } }
createContext(settings); printContextInitInfo(); initOpenCL(window);
@Override public void update() { if (!context.isRenderable()) { return; } while (!keyInputEvents.isEmpty()) { listener.onKeyEvent(keyInputEvents.poll()); } }
/** * De-initialize in the OpenGL thread. */ protected void deinitInThread() { listener.destroy(); destroyContext(); super.internalDestroy(); LOGGER.fine("Display destroyed."); }
/** * Convert array of images to array of {@link GLFWImage}. */ private GLFWImage[] imagesToGLFWImages(final Object[] images) { final GLFWImage[] out = new GLFWImage[images.length]; for (int i = 0; i < images.length; i++) { final BufferedImage image = (BufferedImage) images[i]; out[i] = imageToGLFWImage(image); } return out; }
/** * Set custom icons to the window of this application. */ protected void setWindowIcon(final AppSettings settings) { final Object[] icons = settings.getIcons(); if (icons == null) return; final GLFWImage[] images = imagesToGLFWImages(icons); try (final GLFWImage.Buffer iconSet = GLFWImage.malloc(images.length)) { for (int i = images.length - 1; i >= 0; i--) { final GLFWImage image = images[i]; iconSet.put(i, image); } glfwSetWindowIcon(window, iconSet); } }
@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(); } } });
private void onCursorPos(long window, double xpos, double ypos) { int xDelta; int yDelta; 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); } }
@Override public void setNativeCursor(final JmeCursor jmeCursor) { if (jmeCursor != null) { final long[] glfwCursor = jmeToGlfwCursorMap.computeIfAbsent(jmeCursor, GlfwMouseInput::createGlfwCursor); currentCursorFrame = 0; currentCursor = glfwCursor; currentCursorDelays = null; currentCursorFrameStartTime = glfwGetTime(); if (jmeCursor.getImagesDelay() != null) { currentCursorDelays = jmeCursor.getImagesDelay(); } glfwSetCursor(context.getWindowHandle(), glfwCursor[currentCursorFrame]); } else { currentCursor = null; currentCursorDelays = null; glfwSetCursor(context.getWindowHandle(), MemoryUtil.NULL); } }
@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)) { listener.requestClose(false); } } deinitInThread(); }
@Override public void destroy() { if (!context.isRenderable()) { return; } keyCallback.close(); charCallback.close(); logger.fine("Keyboard destroyed."); }
/** * De-initialize in the OpenGL thread. */ protected void deinitInThread() { listener.destroy(); destroyContext(); super.internalDestroy(); LOGGER.fine("Display destroyed."); }
/** * Convert array of images to array of {@link GLFWImage}. */ private GLFWImage[] imagesToGLFWImages(final Object[] images) { final GLFWImage[] out = new GLFWImage[images.length]; for (int i = 0; i < images.length; i++) { final BufferedImage image = (BufferedImage) images[i]; out[i] = imageToGLFWImage(image); } return out; }
/** * Set custom icons to the window of this application. */ protected void setWindowIcon(final AppSettings settings) { final Object[] icons = settings.getIcons(); if (icons == null) return; final GLFWImage[] images = imagesToGLFWImages(icons); try (final GLFWImage.Buffer iconSet = GLFWImage.malloc(images.length)) { for (int i = images.length - 1; i >= 0; i--) { final GLFWImage image = images[i]; iconSet.put(i, image); } glfwSetWindowIcon(window, iconSet); } }
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 initialize() { if (!context.isRenderable()) { return; glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() { @Override public void invoke(final long window, final int key, final int scancode, final int action, final int mods) { glfwSetCharCallback(context.getWindowHandle(), charCallback = new GLFWCharCallback() { @Override public void invoke(final long window, final int codepoint) {