mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Add basic key modifier shortcuts to FTextField
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Stack;
|
|||||||
|
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input.Keys;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
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
|
//also allow handling of keyUp but don't require it
|
||||||
public boolean keyUp(int keyCode) { return false; }
|
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 {
|
private static class MainInputProcessor extends FGestureAdapter {
|
||||||
|
|||||||
@@ -73,6 +73,13 @@ public class FTextField extends FDisplayObject {
|
|||||||
selLength = 0;
|
selLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSelectedText() {
|
||||||
|
if (selLength > 0) {
|
||||||
|
return text.substring(selStart, selLength);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public String getGhostText() {
|
public String getGhostText() {
|
||||||
return ghostText;
|
return ghostText;
|
||||||
}
|
}
|
||||||
@@ -220,6 +227,43 @@ public class FTextField extends FDisplayObject {
|
|||||||
selLength = 0;
|
selLength = 0;
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user