From 4c3014e49e6c6fa471abc7c6c6d40b29ff11a319 Mon Sep 17 00:00:00 2001 From: drdev Date: Sat, 3 May 2014 17:32:47 +0000 Subject: [PATCH] Add basic key modifier shortcuts to FTextField --- forge-gui-mobile/src/forge/Forge.java | 11 +++++ .../src/forge/toolbox/FTextField.java | 44 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/forge-gui-mobile/src/forge/Forge.java b/forge-gui-mobile/src/forge/Forge.java index 476361cdc50..cceff8311ac 100644 --- a/forge-gui-mobile/src/forge/Forge.java +++ b/forge-gui-mobile/src/forge/Forge.java @@ -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 { diff --git a/forge-gui-mobile/src/forge/toolbox/FTextField.java b/forge-gui-mobile/src/forge/toolbox/FTextField.java index 7c100862a32..d576f7f68cc 100644 --- a/forge-gui-mobile/src/forge/toolbox/FTextField.java +++ b/forge-gui-mobile/src/forge/toolbox/FTextField.java @@ -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; }