Skip to content

Commit ed0ff43

Browse files
author
闫茂源
committed
[M]Add key trigger to test case
1 parent c572502 commit ed0ff43

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/test/java/com/atr/jme/font/example/TestAtlasResize.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import com.atr.jme.font.util.StringContainer;
1111
import com.atr.jme.font.util.Style;
1212
import com.jme3.app.SimpleApplication;
13+
import com.jme3.input.KeyInput;
14+
import com.jme3.input.controls.ActionListener;
15+
import com.jme3.input.controls.KeyTrigger;
1316
import com.jme3.material.Material;
1417
import com.jme3.math.ColorRGBA;
1518
import com.jme3.scene.Geometry;
@@ -43,7 +46,7 @@ public void simpleInitApp() {
4346

4447
TrueTypeKey key = new TrueTypeKeyBMP(font, Style.Plain, fontSize, 0, 72, false, "", 256, true);
4548

46-
TrueTypeFont font = (TrueTypeFont)assetManager.loadAsset(key);
49+
final TrueTypeFont font = (TrueTypeFont)assetManager.loadAsset(key);
4750

4851
// Use a short String first.
4952
StringContainer sc = new StringContainer(font, "ABC", 2);
@@ -53,12 +56,23 @@ public void simpleInitApp() {
5356

5457
displayAtlas(font, -20, 0);
5558

56-
// Use a longer String, force atlas resize.
57-
TrueTypeNode text = font.getText("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2, ColorRGBA.White);
58-
text.move(0, font.getActualLineHeight() * 2, 0);
59-
rootNode.attachChild(text);
59+
inputManager.addMapping("ADD", new KeyTrigger(KeyInput.KEY_SPACE));
60+
inputManager.addListener(new ActionListener() {
61+
@Override
62+
public void onAction(String name, boolean isPressed, float tpf) {
63+
// Use a longer String, force atlas resize.
64+
TrueTypeNode text = font.getText("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2, ColorRGBA.White);
65+
text.move(0, font.getActualLineHeight() * 2, 0);
66+
rootNode.attachChild(text);
67+
displayAtlas(font, -20, 21);
68+
69+
// Use this listener only once
70+
inputManager.deleteMapping("ADD");
71+
inputManager.removeListener(this);
72+
}
73+
}, "ADD");
74+
6075

61-
displayAtlas(font, -20, 21);
6276
}
6377

6478
@SuppressWarnings("rawtypes")

0 commit comments

Comments
 (0)