From b5b6ebd97cfb72f13a18db92ae0282a5f4a8910d Mon Sep 17 00:00:00 2001 From: javasabr Date: Tue, 29 Mar 2016 06:47:36 +0300 Subject: [PATCH 1/4] fixed the input of chars for UI. --- .../com/jme3/input/lwjgl/GlfwKeyInput.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java index cd87cc70a..e0fa70b92 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java @@ -36,13 +36,21 @@ import com.jme3.input.KeyInput; import com.jme3.input.RawInputListener; import com.jme3.input.event.KeyInputEvent; import com.jme3.system.lwjgl.LwjglWindow; + +import org.lwjgl.glfw.GLFWCharCallback; import org.lwjgl.glfw.GLFWKeyCallback; import java.util.LinkedList; import java.util.Queue; import java.util.logging.Logger; -import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LAST; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; +import static org.lwjgl.glfw.GLFW.GLFW_PRESS; +import static org.lwjgl.glfw.GLFW.GLFW_REPEAT; +import static org.lwjgl.glfw.GLFW.glfwGetTime; +import static org.lwjgl.glfw.GLFW.glfwSetCharCallback; +import static org.lwjgl.glfw.GLFW.glfwSetKeyCallback; public class GlfwKeyInput implements KeyInput { @@ -52,6 +60,7 @@ public class GlfwKeyInput implements KeyInput { private RawInputListener listener; private boolean initialized; private GLFWKeyCallback keyCallback; + private GLFWCharCallback charCallback; private Queue keyInputEvents = new LinkedList(); public GlfwKeyInput(LwjglWindow context) { @@ -66,14 +75,38 @@ public class GlfwKeyInput implements KeyInput { glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { + + if (key < 0 || key > GLFW_KEY_LAST) { + return; + } + int jmeKey = GlfwKeyMap.toJmeKeyCode(key); - final KeyInputEvent evt = new KeyInputEvent(jmeKey, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action); - evt.setTime(getInputTimeNanos()); - keyInputEvents.add(evt); + + final KeyInputEvent event = new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action); + event.setTime(getInputTimeNanos()); + + keyInputEvents.add(event); } }); - glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1); + glfwSetCharCallback(context.getWindowHandle(), charCallback = new GLFWCharCallback() { + + @Override + public void invoke(long window, int codepoint) { + + final char keyChar = (char) codepoint; + + final KeyInputEvent pressed = new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, true, false); + pressed.setTime(getInputTimeNanos()); + + keyInputEvents.add(pressed); + + final KeyInputEvent released = new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, false, false); + released.setTime(getInputTimeNanos()); + + keyInputEvents.add(released); + } + }); initialized = true; logger.fine("Keyboard created."); @@ -100,6 +133,7 @@ public class GlfwKeyInput implements KeyInput { } keyCallback.release(); + charCallback.release(); logger.fine("Keyboard destroyed."); } From 7a3a0627c2b0c46e929ec98255457ca5ff5fc812 Mon Sep 17 00:00:00 2001 From: javasabr Date: Tue, 29 Mar 2016 06:48:40 +0300 Subject: [PATCH 2/4] fixed the scroll of mouse and the buffer overflow. --- .../src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java index bf5478cba..89f60fb7f 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java @@ -136,7 +136,7 @@ public class GlfwMouseInput implements MouseInput { glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() { @Override public void invoke(final long window, final double xOffset, final double yOffset) { - onWheelScroll(window, xOffset, yOffset); + onWheelScroll(window, xOffset, yOffset * 120); } }); @@ -213,7 +213,7 @@ public class GlfwMouseInput implements MouseInput { // TODO: currently animated cursors are not supported IntBuffer imageData = jmeCursor.getImagesData(); - ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity()); + ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity() * 4); buf.asIntBuffer().put(imageData); glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf); From 98f1bfc0c15fef8e8653d420fbc7a60d75e15bad Mon Sep 17 00:00:00 2001 From: javasabr Date: Tue, 29 Mar 2016 06:48:47 +0300 Subject: [PATCH 3/4] fixed NPE --- jme3-core/src/main/java/com/jme3/app/LegacyApplication.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/app/LegacyApplication.java b/jme3-core/src/main/java/com/jme3/app/LegacyApplication.java index e861ef66b..d796ba309 100644 --- a/jme3-core/src/main/java/com/jme3/app/LegacyApplication.java +++ b/jme3-core/src/main/java/com/jme3/app/LegacyApplication.java @@ -540,7 +540,9 @@ public class LegacyApplication implements Application, SystemListener { * Internal use only. */ public void reshape(int w, int h){ - renderManager.notifyReshape(w, h); + if (renderManager != null) { + renderManager.notifyReshape(w, h); + } } /** From 85e284a7b00afef820e962445dffd54f37c6edc8 Mon Sep 17 00:00:00 2001 From: javasabr Date: Tue, 29 Mar 2016 19:13:00 +0300 Subject: [PATCH 4/4] moved the magic number to constant --- .../src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java index 89f60fb7f..17c91aa33 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java @@ -67,6 +67,8 @@ public class GlfwMouseInput implements MouseInput { private static final Logger logger = Logger.getLogger(GlfwMouseInput.class.getName()); + private static final int WHEEL_SCALE = 120; + private LwjglWindow context; private RawInputListener listener; private boolean cursorVisible = true; @@ -136,7 +138,7 @@ public class GlfwMouseInput implements MouseInput { glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() { @Override public void invoke(final long window, final double xOffset, final double yOffset) { - onWheelScroll(window, xOffset, yOffset * 120); + onWheelScroll(window, xOffset, yOffset * WHEEL_SCALE); } });