|
|
@ -20,23 +20,23 @@ import org.lwjgl.opengl.Display; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Lwjgl Input Module. |
|
|
|
* Lwjgl Input Module. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Ondřej Hruška (MightyPork) |
|
|
|
* @author Ondřej Hruška (MightyPork) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
|
|
|
|
|
|
|
|
/** Current mouse position */ |
|
|
|
/** Current mouse position */ |
|
|
|
private static final Vect mousePos = new Vect() { |
|
|
|
private static final Vect mousePos = new Vect() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double x() |
|
|
|
public double x() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE; |
|
|
|
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE; |
|
|
|
|
|
|
|
|
|
|
|
return Mouse.getX(); |
|
|
|
return Mouse.getX(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double y() |
|
|
|
public double y() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -45,8 +45,8 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
return Display.getHeight() - Mouse.getY(); |
|
|
|
return Display.getHeight() - Mouse.getY(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void initDevices() |
|
|
|
protected void initDevices() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -58,13 +58,13 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
throw new RuntimeException("Failed to initialize input devices.", e); |
|
|
|
throw new RuntimeException("Failed to initialize input devices.", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void initKeyCodes() |
|
|
|
protected void initKeyCodes() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Keys.NONE.setCode(Keyboard.KEY_NONE); |
|
|
|
Keys.NONE.setCode(Keyboard.KEY_NONE); |
|
|
|
|
|
|
|
|
|
|
|
Keys.NUM_1.setCode(Keyboard.KEY_1); |
|
|
|
Keys.NUM_1.setCode(Keyboard.KEY_1); |
|
|
|
Keys.NUM_2.setCode(Keyboard.KEY_2); |
|
|
|
Keys.NUM_2.setCode(Keyboard.KEY_2); |
|
|
|
Keys.NUM_3.setCode(Keyboard.KEY_3); |
|
|
|
Keys.NUM_3.setCode(Keyboard.KEY_3); |
|
|
@ -75,7 +75,7 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
Keys.NUM_8.setCode(Keyboard.KEY_8); |
|
|
|
Keys.NUM_8.setCode(Keyboard.KEY_8); |
|
|
|
Keys.NUM_9.setCode(Keyboard.KEY_9); |
|
|
|
Keys.NUM_9.setCode(Keyboard.KEY_9); |
|
|
|
Keys.NUM_0.setCode(Keyboard.KEY_0); |
|
|
|
Keys.NUM_0.setCode(Keyboard.KEY_0); |
|
|
|
|
|
|
|
|
|
|
|
Keys.Q.setCode(Keyboard.KEY_Q); |
|
|
|
Keys.Q.setCode(Keyboard.KEY_Q); |
|
|
|
Keys.W.setCode(Keyboard.KEY_W); |
|
|
|
Keys.W.setCode(Keyboard.KEY_W); |
|
|
|
Keys.E.setCode(Keyboard.KEY_E); |
|
|
|
Keys.E.setCode(Keyboard.KEY_E); |
|
|
@ -102,7 +102,7 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
Keys.B.setCode(Keyboard.KEY_B); |
|
|
|
Keys.B.setCode(Keyboard.KEY_B); |
|
|
|
Keys.N.setCode(Keyboard.KEY_N); |
|
|
|
Keys.N.setCode(Keyboard.KEY_N); |
|
|
|
Keys.M.setCode(Keyboard.KEY_M); |
|
|
|
Keys.M.setCode(Keyboard.KEY_M); |
|
|
|
|
|
|
|
|
|
|
|
Keys.MINUS.setCode(Keyboard.KEY_MINUS); |
|
|
|
Keys.MINUS.setCode(Keyboard.KEY_MINUS); |
|
|
|
Keys.EQUALS.setCode(Keyboard.KEY_EQUALS); |
|
|
|
Keys.EQUALS.setCode(Keyboard.KEY_EQUALS); |
|
|
|
Keys.SLASH.setCode(Keyboard.KEY_SLASH); |
|
|
|
Keys.SLASH.setCode(Keyboard.KEY_SLASH); |
|
|
@ -114,17 +114,17 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
Keys.GRAVE.setCode(Keyboard.KEY_GRAVE); |
|
|
|
Keys.GRAVE.setCode(Keyboard.KEY_GRAVE); |
|
|
|
Keys.COMMA.setCode(Keyboard.KEY_COMMA); |
|
|
|
Keys.COMMA.setCode(Keyboard.KEY_COMMA); |
|
|
|
Keys.PERIOD.setCode(Keyboard.KEY_PERIOD); |
|
|
|
Keys.PERIOD.setCode(Keyboard.KEY_PERIOD); |
|
|
|
|
|
|
|
|
|
|
|
Keys.SPACE.setCode(Keyboard.KEY_SPACE); |
|
|
|
Keys.SPACE.setCode(Keyboard.KEY_SPACE); |
|
|
|
Keys.BACKSPACE.setCode(Keyboard.KEY_BACK); |
|
|
|
Keys.BACKSPACE.setCode(Keyboard.KEY_BACK); |
|
|
|
Keys.TAB.setCode(Keyboard.KEY_TAB); |
|
|
|
Keys.TAB.setCode(Keyboard.KEY_TAB); |
|
|
|
Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE); |
|
|
|
Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE); |
|
|
|
|
|
|
|
|
|
|
|
Keys.APPS.setCode(Keyboard.KEY_APPS); |
|
|
|
Keys.APPS.setCode(Keyboard.KEY_APPS); |
|
|
|
Keys.POWER.setCode(Keyboard.KEY_POWER); |
|
|
|
Keys.POWER.setCode(Keyboard.KEY_POWER); |
|
|
|
Keys.SLEEP.setCode(Keyboard.KEY_SLEEP); |
|
|
|
Keys.SLEEP.setCode(Keyboard.KEY_SLEEP); |
|
|
|
//Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined
|
|
|
|
//Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined
|
|
|
|
|
|
|
|
|
|
|
|
Keys.F1.setCode(Keyboard.KEY_F1); |
|
|
|
Keys.F1.setCode(Keyboard.KEY_F1); |
|
|
|
Keys.F2.setCode(Keyboard.KEY_F2); |
|
|
|
Keys.F2.setCode(Keyboard.KEY_F2); |
|
|
|
Keys.F3.setCode(Keyboard.KEY_F3); |
|
|
|
Keys.F3.setCode(Keyboard.KEY_F3); |
|
|
@ -140,11 +140,11 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
Keys.F13.setCode(Keyboard.KEY_F13); |
|
|
|
Keys.F13.setCode(Keyboard.KEY_F13); |
|
|
|
Keys.F14.setCode(Keyboard.KEY_F14); |
|
|
|
Keys.F14.setCode(Keyboard.KEY_F14); |
|
|
|
Keys.F15.setCode(Keyboard.KEY_F15); |
|
|
|
Keys.F15.setCode(Keyboard.KEY_F15); |
|
|
|
|
|
|
|
|
|
|
|
Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL); |
|
|
|
Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL); |
|
|
|
Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL); |
|
|
|
Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL); |
|
|
|
Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK); |
|
|
|
Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK); |
|
|
|
|
|
|
|
|
|
|
|
Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT); |
|
|
|
Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT); |
|
|
|
Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD); |
|
|
|
Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD); |
|
|
|
Keys.NUMPAD_0.setCode(Keyboard.KEY_NUMPAD0); |
|
|
|
Keys.NUMPAD_0.setCode(Keyboard.KEY_NUMPAD0); |
|
|
@ -161,7 +161,7 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
Keys.NUMPAD_ENTER.setCode(Keyboard.KEY_NUMPADENTER); |
|
|
|
Keys.NUMPAD_ENTER.setCode(Keyboard.KEY_NUMPADENTER); |
|
|
|
Keys.NUMPAD_DIVIDE.setCode(Keyboard.KEY_DIVIDE); |
|
|
|
Keys.NUMPAD_DIVIDE.setCode(Keyboard.KEY_DIVIDE); |
|
|
|
Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY); |
|
|
|
Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY); |
|
|
|
|
|
|
|
|
|
|
|
Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL); |
|
|
|
Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL); |
|
|
|
Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL); |
|
|
|
Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL); |
|
|
|
Keys.ALT_LEFT.setCode(Keyboard.KEY_LMENU); |
|
|
|
Keys.ALT_LEFT.setCode(Keyboard.KEY_LMENU); |
|
|
@ -170,37 +170,37 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
Keys.SHIFT_RIGHT.setCode(Keyboard.KEY_RSHIFT); |
|
|
|
Keys.SHIFT_RIGHT.setCode(Keyboard.KEY_RSHIFT); |
|
|
|
Keys.META_LEFT.setCode(Keyboard.KEY_LMETA); |
|
|
|
Keys.META_LEFT.setCode(Keyboard.KEY_LMETA); |
|
|
|
Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA); |
|
|
|
Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA); |
|
|
|
|
|
|
|
|
|
|
|
Keys.UP.setCode(Keyboard.KEY_UP); |
|
|
|
Keys.UP.setCode(Keyboard.KEY_UP); |
|
|
|
Keys.DOWN.setCode(Keyboard.KEY_DOWN); |
|
|
|
Keys.DOWN.setCode(Keyboard.KEY_DOWN); |
|
|
|
Keys.LEFT.setCode(Keyboard.KEY_LEFT); |
|
|
|
Keys.LEFT.setCode(Keyboard.KEY_LEFT); |
|
|
|
Keys.RIGHT.setCode(Keyboard.KEY_RIGHT); |
|
|
|
Keys.RIGHT.setCode(Keyboard.KEY_RIGHT); |
|
|
|
|
|
|
|
|
|
|
|
Keys.HOME.setCode(Keyboard.KEY_HOME); |
|
|
|
Keys.HOME.setCode(Keyboard.KEY_HOME); |
|
|
|
Keys.END.setCode(Keyboard.KEY_END); |
|
|
|
Keys.END.setCode(Keyboard.KEY_END); |
|
|
|
|
|
|
|
|
|
|
|
Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR); |
|
|
|
Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR); |
|
|
|
Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT); |
|
|
|
Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT); |
|
|
|
|
|
|
|
|
|
|
|
Keys.RETURN.setCode(Keyboard.KEY_RETURN); |
|
|
|
Keys.RETURN.setCode(Keyboard.KEY_RETURN); |
|
|
|
Keys.PAUSE.setCode(Keyboard.KEY_PAUSE); |
|
|
|
Keys.PAUSE.setCode(Keyboard.KEY_PAUSE); |
|
|
|
Keys.INSERT.setCode(Keyboard.KEY_INSERT); |
|
|
|
Keys.INSERT.setCode(Keyboard.KEY_INSERT); |
|
|
|
Keys.DELETE.setCode(Keyboard.KEY_DELETE); |
|
|
|
Keys.DELETE.setCode(Keyboard.KEY_DELETE); |
|
|
|
Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ); |
|
|
|
Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void destroy() |
|
|
|
public void destroy() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Mouse.destroy(); |
|
|
|
Mouse.destroy(); |
|
|
|
Keyboard.destroy(); |
|
|
|
Keyboard.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final VectVar mouseMove = Vect.makeVar(); |
|
|
|
private final VectVar mouseMove = Vect.makeVar(); |
|
|
|
private final VectVar mouseLastPos = Vect.makeVar(); |
|
|
|
private final VectVar mouseLastPos = Vect.makeVar(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public synchronized void update(double delta) |
|
|
|
public synchronized void update(double delta) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -208,9 +208,9 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
if (!Display.isCreated()) return; |
|
|
|
if (!Display.isCreated()) return; |
|
|
|
if (!Mouse.isCreated()) return; |
|
|
|
if (!Mouse.isCreated()) return; |
|
|
|
if (!Keyboard.isCreated()) return; |
|
|
|
if (!Keyboard.isCreated()) return; |
|
|
|
|
|
|
|
|
|
|
|
Display.processMessages(); |
|
|
|
Display.processMessages(); |
|
|
|
|
|
|
|
|
|
|
|
// sum the moves
|
|
|
|
// sum the moves
|
|
|
|
mouseMove.reset(); |
|
|
|
mouseMove.reset(); |
|
|
|
mouseLastPos.reset(); |
|
|
|
mouseLastPos.reset(); |
|
|
@ -219,81 +219,81 @@ public class LwjglInputModule extends InputModule implements Updateable { |
|
|
|
onMouseEvent(mouseMove, mouseLastPos); |
|
|
|
onMouseEvent(mouseMove, mouseLastPos); |
|
|
|
wasMouse = true; |
|
|
|
wasMouse = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (wasMouse && !mouseMove.isZero()) { |
|
|
|
if (wasMouse && !mouseMove.isZero()) { |
|
|
|
App.bus().send(new MouseMotionEvent(mouseLastPos, mouseMove)); |
|
|
|
App.bus().send(new MouseMotionEvent(mouseLastPos, mouseMove)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (Keyboard.next()) { |
|
|
|
while (Keyboard.next()) { |
|
|
|
onKeyEvent(); |
|
|
|
onKeyEvent(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Display.isCloseRequested()) { |
|
|
|
if (Display.isCloseRequested()) { |
|
|
|
App.shutdown(); |
|
|
|
App.shutdown(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onMouseEvent(VectVar moveSum, VectVar lastPos) |
|
|
|
private void onMouseEvent(VectVar moveSum, VectVar lastPos) |
|
|
|
{ |
|
|
|
{ |
|
|
|
final int button = Mouse.getEventButton(); |
|
|
|
final int button = Mouse.getEventButton(); |
|
|
|
final boolean down = Mouse.getEventButtonState(); |
|
|
|
final boolean down = Mouse.getEventButtonState(); |
|
|
|
|
|
|
|
|
|
|
|
final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY()); |
|
|
|
final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY()); |
|
|
|
final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY()); |
|
|
|
final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY()); |
|
|
|
|
|
|
|
|
|
|
|
final int wheeld = Mouse.getEventDWheel(); |
|
|
|
final int wheeld = Mouse.getEventDWheel(); |
|
|
|
|
|
|
|
|
|
|
|
// flip Y axis
|
|
|
|
// flip Y axis
|
|
|
|
pos.setY(Display.getHeight() - pos.y()); |
|
|
|
pos.setY(Display.getHeight() - pos.y()); |
|
|
|
|
|
|
|
|
|
|
|
if (button != -1 || wheeld != 0) { |
|
|
|
if (button != -1 || wheeld != 0) { |
|
|
|
App.bus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld)); |
|
|
|
App.bus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
moveSum.setTo(moveSum.add(move)); |
|
|
|
moveSum.setTo(moveSum.add(move)); |
|
|
|
lastPos.setTo(pos); |
|
|
|
lastPos.setTo(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onKeyEvent() |
|
|
|
private void onKeyEvent() |
|
|
|
{ |
|
|
|
{ |
|
|
|
final int key = Keyboard.getEventKey(); |
|
|
|
final int key = Keyboard.getEventKey(); |
|
|
|
final boolean down = Keyboard.getEventKeyState(); |
|
|
|
final boolean down = Keyboard.getEventKeyState(); |
|
|
|
final char c = Keyboard.getEventCharacter(); |
|
|
|
final char c = Keyboard.getEventCharacter(); |
|
|
|
|
|
|
|
|
|
|
|
App.bus().send(new KeyEvent(key, c, down)); |
|
|
|
App.bus().send(new KeyEvent(key, c, down)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Vect getMousePos() |
|
|
|
public Vect getMousePos() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return mousePos; |
|
|
|
return mousePos; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean isMouseInside() |
|
|
|
public boolean isMouseInside() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Mouse.isInsideWindow(); |
|
|
|
return Mouse.isInsideWindow(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void grabMouse(boolean grab) |
|
|
|
public void grabMouse(boolean grab) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Mouse.setGrabbed(grab); |
|
|
|
Mouse.setGrabbed(grab); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean isKeyDown(Key key) |
|
|
|
public boolean isKeyDown(Key key) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return key.isDefined() && Keyboard.isKeyDown(key.getCode()); |
|
|
|
return key.isDefined() && Keyboard.isKeyDown(key.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean isMouseButtonDown(int button) |
|
|
|
public boolean isMouseButtonDown(int button) |
|
|
|
{ |
|
|
|
{ |
|
|
|