commit
099ebeaec9
@ -540,8 +540,10 @@ public class LegacyApplication implements Application, SystemListener {
|
|||||||
* Internal use only.
|
* Internal use only.
|
||||||
*/
|
*/
|
||||||
public void reshape(int w, int h){
|
public void reshape(int w, int h){
|
||||||
|
if (renderManager != null) {
|
||||||
renderManager.notifyReshape(w, h);
|
renderManager.notifyReshape(w, h);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restarts the context, applying any changed settings.
|
* Restarts the context, applying any changed settings.
|
||||||
|
@ -36,13 +36,21 @@ import com.jme3.input.KeyInput;
|
|||||||
import com.jme3.input.RawInputListener;
|
import com.jme3.input.RawInputListener;
|
||||||
import com.jme3.input.event.KeyInputEvent;
|
import com.jme3.input.event.KeyInputEvent;
|
||||||
import com.jme3.system.lwjgl.LwjglWindow;
|
import com.jme3.system.lwjgl.LwjglWindow;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFWCharCallback;
|
||||||
import org.lwjgl.glfw.GLFWKeyCallback;
|
import org.lwjgl.glfw.GLFWKeyCallback;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.logging.Logger;
|
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 {
|
public class GlfwKeyInput implements KeyInput {
|
||||||
|
|
||||||
@ -52,6 +60,7 @@ public class GlfwKeyInput implements KeyInput {
|
|||||||
private RawInputListener listener;
|
private RawInputListener listener;
|
||||||
private boolean initialized;
|
private boolean initialized;
|
||||||
private GLFWKeyCallback keyCallback;
|
private GLFWKeyCallback keyCallback;
|
||||||
|
private GLFWCharCallback charCallback;
|
||||||
private Queue<KeyInputEvent> keyInputEvents = new LinkedList<KeyInputEvent>();
|
private Queue<KeyInputEvent> keyInputEvents = new LinkedList<KeyInputEvent>();
|
||||||
|
|
||||||
public GlfwKeyInput(LwjglWindow context) {
|
public GlfwKeyInput(LwjglWindow context) {
|
||||||
@ -66,14 +75,38 @@ public class GlfwKeyInput implements KeyInput {
|
|||||||
glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
|
glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long window, int key, int scancode, int action, int mods) {
|
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);
|
int jmeKey = GlfwKeyMap.toJmeKeyCode(key);
|
||||||
final KeyInputEvent evt = new KeyInputEvent(jmeKey, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action);
|
|
||||||
evt.setTime(getInputTimeNanos());
|
final KeyInputEvent event = new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action);
|
||||||
keyInputEvents.add(evt);
|
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;
|
initialized = true;
|
||||||
logger.fine("Keyboard created.");
|
logger.fine("Keyboard created.");
|
||||||
@ -100,6 +133,7 @@ public class GlfwKeyInput implements KeyInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keyCallback.release();
|
keyCallback.release();
|
||||||
|
charCallback.release();
|
||||||
logger.fine("Keyboard destroyed.");
|
logger.fine("Keyboard destroyed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ public class GlfwMouseInput implements MouseInput {
|
|||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(GlfwMouseInput.class.getName());
|
private static final Logger logger = Logger.getLogger(GlfwMouseInput.class.getName());
|
||||||
|
|
||||||
|
private static final int WHEEL_SCALE = 120;
|
||||||
|
|
||||||
private LwjglWindow context;
|
private LwjglWindow context;
|
||||||
private RawInputListener listener;
|
private RawInputListener listener;
|
||||||
private boolean cursorVisible = true;
|
private boolean cursorVisible = true;
|
||||||
@ -136,7 +138,7 @@ public class GlfwMouseInput implements MouseInput {
|
|||||||
glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() {
|
glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(final long window, final double xOffset, final double yOffset) {
|
public void invoke(final long window, final double xOffset, final double yOffset) {
|
||||||
onWheelScroll(window, xOffset, yOffset);
|
onWheelScroll(window, xOffset, yOffset * WHEEL_SCALE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -213,7 +215,7 @@ public class GlfwMouseInput implements MouseInput {
|
|||||||
|
|
||||||
// TODO: currently animated cursors are not supported
|
// TODO: currently animated cursors are not supported
|
||||||
IntBuffer imageData = jmeCursor.getImagesData();
|
IntBuffer imageData = jmeCursor.getImagesData();
|
||||||
ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity());
|
ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity() * 4);
|
||||||
buf.asIntBuffer().put(imageData);
|
buf.asIntBuffer().put(imageData);
|
||||||
|
|
||||||
glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);
|
glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user