remove delegating stuff from Input
This commit is contained in:
@@ -35,6 +35,8 @@ import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import static org.lwjgl.input.Keyboard.*;
|
||||
|
||||
/**
|
||||
* A wrapped for all keyboard, mouse and controller input
|
||||
* Edited for opsu!
|
||||
@@ -44,131 +46,6 @@ import org.lwjgl.opengl.Display;
|
||||
@SuppressWarnings({"rawtypes", "unchecked", "unused"})
|
||||
public class Input {
|
||||
|
||||
public static final int KEY_ESCAPE = 0x01;
|
||||
public static final int KEY_1 = 0x02;
|
||||
public static final int KEY_2 = 0x03;
|
||||
public static final int KEY_3 = 0x04;
|
||||
public static final int KEY_4 = 0x05;
|
||||
public static final int KEY_5 = 0x06;
|
||||
public static final int KEY_6 = 0x07;
|
||||
public static final int KEY_7 = 0x08;
|
||||
public static final int KEY_8 = 0x09;
|
||||
public static final int KEY_9 = 0x0A;
|
||||
public static final int KEY_0 = 0x0B;
|
||||
public static final int KEY_MINUS = 0x0C; /* - on main keyboard */
|
||||
public static final int KEY_EQUALS = 0x0D;
|
||||
public static final int KEY_BACK = 0x0E; /* backspace */
|
||||
public static final int KEY_TAB = 0x0F;
|
||||
public static final int KEY_Q = 0x10;
|
||||
public static final int KEY_W = 0x11;
|
||||
public static final int KEY_E = 0x12;
|
||||
public static final int KEY_R = 0x13;
|
||||
public static final int KEY_T = 0x14;
|
||||
public static final int KEY_Y = 0x15;
|
||||
public static final int KEY_U = 0x16;
|
||||
public static final int KEY_I = 0x17;
|
||||
public static final int KEY_O = 0x18;
|
||||
public static final int KEY_P = 0x19;
|
||||
public static final int KEY_LBRACKET = 0x1A;
|
||||
public static final int KEY_RBRACKET = 0x1B;
|
||||
public static final int KEY_RETURN = 0x1C; /* Enter on main keyboard */
|
||||
public static final int KEY_ENTER = 0x1C; /* Enter on main keyboard */
|
||||
public static final int KEY_LCONTROL = 0x1D;
|
||||
public static final int KEY_A = 0x1E;
|
||||
public static final int KEY_S = 0x1F;
|
||||
public static final int KEY_D = 0x20;
|
||||
public static final int KEY_F = 0x21;
|
||||
public static final int KEY_G = 0x22;
|
||||
public static final int KEY_H = 0x23;
|
||||
public static final int KEY_J = 0x24;
|
||||
public static final int KEY_K = 0x25;
|
||||
public static final int KEY_L = 0x26;
|
||||
public static final int KEY_SEMICOLON = 0x27;
|
||||
public static final int KEY_APOSTROPHE = 0x28;
|
||||
public static final int KEY_GRAVE = 0x29; /* accent grave */
|
||||
public static final int KEY_LSHIFT = 0x2A;
|
||||
public static final int KEY_BACKSLASH = 0x2B;
|
||||
public static final int KEY_Z = 0x2C;
|
||||
public static final int KEY_X = 0x2D;
|
||||
public static final int KEY_C = 0x2E;
|
||||
public static final int KEY_V = 0x2F;
|
||||
public static final int KEY_B = 0x30;
|
||||
public static final int KEY_N = 0x31;
|
||||
public static final int KEY_M = 0x32;
|
||||
public static final int KEY_COMMA = 0x33;
|
||||
public static final int KEY_PERIOD = 0x34; /* . on main keyboard */
|
||||
public static final int KEY_SLASH = 0x35; /* / on main keyboard */
|
||||
public static final int KEY_RSHIFT = 0x36;
|
||||
public static final int KEY_MULTIPLY = 0x37; /* * on numeric keypad */
|
||||
public static final int KEY_LMENU = 0x38; /* left Alt */
|
||||
public static final int KEY_SPACE = 0x39;
|
||||
public static final int KEY_CAPITAL = 0x3A;
|
||||
public static final int KEY_F1 = 0x3B;
|
||||
public static final int KEY_F2 = 0x3C;
|
||||
public static final int KEY_F3 = 0x3D;
|
||||
public static final int KEY_F4 = 0x3E;
|
||||
public static final int KEY_F5 = 0x3F;
|
||||
public static final int KEY_F6 = 0x40;
|
||||
public static final int KEY_F7 = 0x41;
|
||||
public static final int KEY_F8 = 0x42;
|
||||
public static final int KEY_F9 = 0x43;
|
||||
public static final int KEY_F10 = 0x44;
|
||||
public static final int KEY_NUMLOCK = 0x45;
|
||||
public static final int KEY_SCROLL = 0x46; /* Scroll Lock */
|
||||
public static final int KEY_NUMPAD7 = 0x47;
|
||||
public static final int KEY_NUMPAD8 = 0x48;
|
||||
public static final int KEY_NUMPAD9 = 0x49;
|
||||
public static final int KEY_SUBTRACT = 0x4A; /* - on numeric keypad */
|
||||
public static final int KEY_NUMPAD4 = 0x4B;
|
||||
public static final int KEY_NUMPAD5 = 0x4C;
|
||||
public static final int KEY_NUMPAD6 = 0x4D;
|
||||
public static final int KEY_ADD = 0x4E; /* + on numeric keypad */
|
||||
public static final int KEY_NUMPAD1 = 0x4F;
|
||||
public static final int KEY_NUMPAD2 = 0x50;
|
||||
public static final int KEY_NUMPAD3 = 0x51;
|
||||
public static final int KEY_NUMPAD0 = 0x52;
|
||||
public static final int KEY_DECIMAL = 0x53; /* . on numeric keypad */
|
||||
public static final int KEY_F11 = 0x57;
|
||||
public static final int KEY_F12 = 0x58;
|
||||
public static final int KEY_F13 = 0x64; /* (NEC PC98) */
|
||||
public static final int KEY_F14 = 0x65; /* (NEC PC98) */
|
||||
public static final int KEY_F15 = 0x66; /* (NEC PC98) */
|
||||
public static final int KEY_KANA = 0x70; /* (Japanese keyboard) */
|
||||
public static final int KEY_CONVERT = 0x79; /* (Japanese keyboard) */
|
||||
public static final int KEY_NOCONVERT = 0x7B; /* (Japanese keyboard) */
|
||||
public static final int KEY_YEN = 0x7D; /* (Japanese keyboard) */
|
||||
public static final int KEY_NUMPADEQUALS = 0x8D; /* = on numeric keypad (NEC PC98) */
|
||||
public static final int KEY_CIRCUMFLEX = 0x90; /* (Japanese keyboard) */
|
||||
public static final int KEY_AT = 0x91; /* (NEC PC98) */
|
||||
public static final int KEY_COLON = 0x92; /* (NEC PC98) */
|
||||
public static final int KEY_UNDERLINE = 0x93; /* (NEC PC98) */
|
||||
public static final int KEY_KANJI = 0x94; /* (Japanese keyboard) */
|
||||
public static final int KEY_STOP = 0x95; /* (NEC PC98) */
|
||||
public static final int KEY_AX = 0x96; /* (Japan AX) */
|
||||
public static final int KEY_UNLABELED = 0x97; /* (J3100) */
|
||||
public static final int KEY_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
|
||||
public static final int KEY_RCONTROL = 0x9D;
|
||||
public static final int KEY_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */
|
||||
public static final int KEY_DIVIDE = 0xB5; /* / on numeric keypad */
|
||||
public static final int KEY_SYSRQ = 0xB7;
|
||||
public static final int KEY_RMENU = 0xB8; /* right Alt */
|
||||
public static final int KEY_PAUSE = 0xC5; /* Pause */
|
||||
public static final int KEY_HOME = 0xC7; /* Home on arrow keypad */
|
||||
public static final int KEY_UP = 0xC8; /* UpArrow on arrow keypad */
|
||||
public static final int KEY_PRIOR = 0xC9; /* PgUp on arrow keypad */
|
||||
public static final int KEY_LEFT = 0xCB; /* LeftArrow on arrow keypad */
|
||||
public static final int KEY_RIGHT = 0xCD; /* RightArrow on arrow keypad */
|
||||
public static final int KEY_END = 0xCF; /* End on arrow keypad */
|
||||
public static final int KEY_DOWN = 0xD0; /* DownArrow on arrow keypad */
|
||||
public static final int KEY_NEXT = 0xD1; /* PgDn on arrow keypad */
|
||||
public static final int KEY_INSERT = 0xD2; /* Insert on arrow keypad */
|
||||
public static final int KEY_DELETE = 0xD3; /* Delete on arrow keypad */
|
||||
public static final int KEY_LWIN = 0xDB; /* Left Windows key */
|
||||
public static final int KEY_RWIN = 0xDC; /* Right Windows key */
|
||||
public static final int KEY_APPS = 0xDD; /* AppMenu key */
|
||||
public static final int KEY_POWER = 0xDE;
|
||||
public static final int KEY_SLEEP = 0xDF;
|
||||
|
||||
/** A helper for left ALT */
|
||||
public static final int KEY_LALT = KEY_LMENU;
|
||||
/** A helper for right ALT */
|
||||
@@ -356,17 +233,7 @@ public class Input {
|
||||
lastMouseX = getMouseX();
|
||||
lastMouseY = getMouseY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character representation of the key identified by the specified code
|
||||
*
|
||||
* @param code The key code of the key to retrieve the name of
|
||||
* @return The name or character representation of the key requested
|
||||
*/
|
||||
public static String getKeyName(int code) {
|
||||
return Keyboard.getKeyName(code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a particular key has been pressed since this method
|
||||
* was last called for the specified key
|
||||
@@ -415,16 +282,6 @@ public class Input {
|
||||
public void clearMousePressedRecord() {
|
||||
Arrays.fill(mousePressed, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a particular key is down
|
||||
*
|
||||
* @param code The key code of the key to check
|
||||
* @return True if the key is down
|
||||
*/
|
||||
public boolean isKeyDown(int code) {
|
||||
return Keyboard.isKeyDown(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x position of the mouse cursor
|
||||
@@ -443,23 +300,13 @@ public class Input {
|
||||
public int getMouseY() {
|
||||
return height - Mouse.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given mouse button is down
|
||||
*
|
||||
* @param button The index of the button to check (starting at 0)
|
||||
* @return True if the mouse button is down
|
||||
*/
|
||||
public boolean isMouseButtonDown(int button) {
|
||||
return Mouse.isButtonDown(button);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if any mouse button is down
|
||||
*
|
||||
* @return True if any mouse button is down
|
||||
*/
|
||||
private boolean anyMouseDown() {
|
||||
public boolean anyMouseDown() {
|
||||
for (int i=0;i<3;i++) {
|
||||
if (Mouse.isButtonDown(i)) {
|
||||
return true;
|
||||
@@ -469,6 +316,10 @@ public class Input {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isControlDown() {
|
||||
return Keyboard.isKeyDown(KEY_RCONTROL) || Keyboard.isKeyDown(KEY_LCONTROL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll the state of the input
|
||||
*
|
||||
|
||||
@@ -32,11 +32,11 @@ import org.lwjgl.Sys;
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Font;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.geom.Rectangle;
|
||||
import yugecin.opsudance.core.components.ActionListener;
|
||||
import yugecin.opsudance.core.components.Component;
|
||||
|
||||
import static org.lwjgl.input.Keyboard.*;
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ public class TextField extends Component {
|
||||
|
||||
public void render(Graphics g) {
|
||||
if (lastKey != -1) {
|
||||
if (input.isKeyDown(lastKey)) {
|
||||
if (isKeyDown(lastKey)) {
|
||||
if (repeatTimer < System.currentTimeMillis()) {
|
||||
repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
|
||||
keyPressed(lastKey, lastChar);
|
||||
@@ -168,10 +168,8 @@ public class TextField extends Component {
|
||||
}
|
||||
|
||||
public void keyPressed(int key, char c) {
|
||||
if (key != -1)
|
||||
{
|
||||
if ((key == Input.KEY_V) &&
|
||||
((input.isKeyDown(Input.KEY_LCONTROL)) || (input.isKeyDown(Input.KEY_RCONTROL)))) {
|
||||
if (key != -1) {
|
||||
if (key == KEY_V && input.isControlDown()) {
|
||||
String text = Sys.getClipboard();
|
||||
if (text != null) {
|
||||
doPaste(text);
|
||||
@@ -188,7 +186,7 @@ public class TextField extends Component {
|
||||
}
|
||||
lastChar = c;
|
||||
|
||||
if (key == Input.KEY_LEFT) { /*
|
||||
if (key == KEY_LEFT) { /*
|
||||
if (cursorPos > 0) {
|
||||
cursorPos--;
|
||||
}
|
||||
@@ -196,7 +194,7 @@ public class TextField extends Component {
|
||||
if (consume) {
|
||||
container.getInput().consumeEvent();
|
||||
}
|
||||
*/ } else if (key == Input.KEY_RIGHT) { /*
|
||||
*/ } else if (key == KEY_RIGHT) { /*
|
||||
if (cursorPos < value.length()) {
|
||||
cursorPos++;
|
||||
}
|
||||
@@ -204,9 +202,9 @@ public class TextField extends Component {
|
||||
if (consume) {
|
||||
container.getInput().consumeEvent();
|
||||
}
|
||||
*/ } else if (key == Input.KEY_BACK) {
|
||||
*/ } else if (key == KEY_BACK) {
|
||||
if ((cursorPos > 0) && (value.length() > 0)) {
|
||||
if (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL)) {
|
||||
if (input.isControlDown()) {
|
||||
int sp = 0;
|
||||
boolean startSpace = Character.isWhitespace(value.charAt(cursorPos - 1));
|
||||
boolean charSeen = false;
|
||||
@@ -238,7 +236,7 @@ public class TextField extends Component {
|
||||
cursorPos--;
|
||||
}
|
||||
}
|
||||
} else if (key == Input.KEY_DELETE) {
|
||||
} else if (key == KEY_DELETE) {
|
||||
if (value.length() > cursorPos) {
|
||||
value = value.substring(0,cursorPos) + value.substring(cursorPos+1);
|
||||
}
|
||||
@@ -250,7 +248,7 @@ public class TextField extends Component {
|
||||
value = value.substring(0, cursorPos) + c;
|
||||
}
|
||||
cursorPos++;
|
||||
} else if (key == Input.KEY_RETURN) {
|
||||
} else if (key == KEY_RETURN) {
|
||||
if (listener != null) {
|
||||
listener.onAction();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user