Add basic key modifier shortcuts to FTextField

This commit is contained in:
drdev
2014-05-03 17:32:47 +00:00
parent 3bfc8a926e
commit 4c3014e49e
2 changed files with 55 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Stack;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
@@ -237,6 +238,16 @@ public class Forge implements ApplicationListener {
//also allow handling of keyUp but don't require it
public boolean keyUp(int keyCode) { return false; }
public static boolean isCtrlKeyDown() {
return Gdx.input.isKeyPressed(Keys.CONTROL_LEFT) || Gdx.input.isKeyPressed(Keys.CONTROL_RIGHT);
}
public static boolean isShiftKeyDown() {
return Gdx.input.isKeyPressed(Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT);
}
public static boolean isAltKeyDown() {
return Gdx.input.isKeyPressed(Keys.ALT_LEFT) || Gdx.input.isKeyPressed(Keys.ALT_RIGHT);
}
}
private static class MainInputProcessor extends FGestureAdapter {

View File

@@ -73,6 +73,13 @@ public class FTextField extends FDisplayObject {
selLength = 0;
}
public String getSelectedText() {
if (selLength > 0) {
return text.substring(selStart, selLength);
}
return "";
}
public String getGhostText() {
return ghostText;
}
@@ -220,6 +227,43 @@ public class FTextField extends FDisplayObject {
selLength = 0;
}
return true;
case Keys.A: //select all on Ctrl+A
if (KeyInputAdapter.isCtrlKeyDown()) {
selStart = 0;
selLength = text.length();
return true;
}
break;
case Keys.C: //copy on Ctrl+C
if (KeyInputAdapter.isCtrlKeyDown()) {
if (selLength > 0) {
Forge.getClipboard().setContents(getSelectedText());
}
return true;
}
break;
case Keys.V: //paste on Ctrl+V
if (KeyInputAdapter.isCtrlKeyDown()) {
insertText(Forge.getClipboard().getContents());
return true;
}
break;
case Keys.X: //cut on Ctrl+X
if (KeyInputAdapter.isCtrlKeyDown()) {
if (selLength > 0) {
Forge.getClipboard().setContents(getSelectedText());
insertText("");
}
return true;
}
break;
case Keys.Z: //cancel edit on Ctrl+Z
if (KeyInputAdapter.isCtrlKeyDown()) {
setText(textBeforeKeyInput);
Forge.endKeyInput();
return true;
}
break;
}
return false;
}