MCPcopy
hub / github.com/libgdx/libgdx / AbstractInput

Class AbstractInput

gdx/src/com/badlogic/gdx/AbstractInput.java:6–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import com.badlogic.gdx.utils.IntSet;
5
6public abstract class AbstractInput implements Input {
7 protected final boolean[] pressedKeys;
8 protected final boolean[] justPressedKeys;
9 private final IntSet keysToCatch = new IntSet();
10 protected int pressedKeyCount;
11 protected boolean keyJustPressed;
12
13 public AbstractInput () {
14 pressedKeys = new boolean[Keys.MAX_KEYCODE + 1];
15 justPressedKeys = new boolean[Keys.MAX_KEYCODE + 1];
16 }
17
18 @Override
19 public boolean isKeyPressed (int key) {
20 if (key == Input.Keys.ANY_KEY) {
21 return pressedKeyCount > 0;
22 }
23 if (key < 0 || key > Keys.MAX_KEYCODE) {
24 return false;
25 }
26 return pressedKeys[key];
27 }
28
29 @Override
30 public boolean isKeyJustPressed (int key) {
31 if (key == Input.Keys.ANY_KEY) {
32 return keyJustPressed;
33 }
34 if (key < 0 || key > Keys.MAX_KEYCODE) {
35 return false;
36 }
37 return justPressedKeys[key];
38 }
39
40 @Override
41 public void setCatchKey (int keycode, boolean catchKey) {
42 if (!catchKey) {
43 keysToCatch.remove(keycode);
44 } else {
45 keysToCatch.add(keycode);
46 }
47 }
48
49 @Override
50 public boolean isCatchKey (int keycode) {
51 return keysToCatch.contains(keycode);
52 }
53
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected