Class Input
java.lang.Object
dev.prozilla.pine.core.state.input.Input
- All Implemented Interfaces:
Destructible,Initializable
Handles the GLFW input system.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final booleanstatic final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTextListener(Input.TextListener listener) voidblockCursor(Entity entity) Prevents the cursor from sending input to remaining entities in the current frame.voidblockCursor(Entity entity, boolean override) Prevents the cursor from sending input to remaining entities in the current frame.voiddestroy()Destroys this input system.voidSets the cursor mode toCursorMode.DISABLED.booleangetAnyKey(int... keys) Checks whether any key in an array is pressed.booleanChecks whether any key in an array is pressed.getCursor(boolean ignoreBlock) Returns the position of the cursor on the screen.Returns the entity that is blocking the cursor in the current frame.Returns the first gamepad if it is connected, otherwise returns a fallback gamepad which returns0ffor all axes andfalsefor all buttons.getGamepad(int id) Returns the gamepad that matches the given ID.booleangetKey(int key) Checks whether a key is pressed.booleangetKey(int key, boolean stopPropagation) Checks whether a key is pressed.booleanChecks whether a key is pressed.booleanChecks whether a key is pressed.booleangetKeyDown(int key) Checks whether a key is down.booleangetKeyDown(int key, boolean stopPropagation) Checks whether a key is down.booleangetKeyDown(Key key) Checks whether a key is down.booleangetKeyDown(Key key, boolean stopPropagation) Checks whether a key is down.booleangetKeys(int... keys) Checks whether a combination of keys is pressed.booleanChecks whether a combination of keys is pressed.booleangetMouseButton(int button) Checks whether a mouse button is pressed.booleangetMouseButton(int button, boolean stopPropagation) Checks whether a mouse button is pressed.booleangetMouseButton(MouseButton button) Checks whether a mouse button is pressed.booleangetMouseButton(MouseButton button, boolean stopPropagation) Checks whether a mouse button is pressed.booleangetMouseButtonDown(int button) Checks whether a mouse button is down.booleangetMouseButtonDown(int button, boolean stopPropagation) Checks whether a mouse button is down.booleangetMouseButtonDown(MouseButton button) Checks whether a mouse button is down.booleangetMouseButtonDown(MouseButton button, boolean stopPropagation) Checks whether a mouse button is down.floatfloatReturns the position of the cursor inside the world.getWorldCursor(boolean ignoreBlock) Returns the position of the cursor inside the world.voidSets the cursor mode toCursorMode.HIDDEN.voidinit()Initializes the input system.voidinput()Prepare handling of input before input systems.booleanChecks whether the cursor is being blocked.booleanisGamepadConnected(int id) Checks if the gamepad that matches the given ID is connected.onGamepadConnect(int id, Callback callback) onGamepadDisconnect(int id, Callback callback) voidvoidremoveTextListener(Input.TextListener listener) voidsetCursorImage(Image image) voidsetCursorImage(Image image, int offsetX, int offsetY) voidsetCursorImage(Image image, Vector2i offset) voidsetCursorMode(CursorMode cursorMode) Changes the cursor mode.voidsetCursorType(int cursorType) Setter for the cursor type.voidsetCursorType(CursorType cursorType) Setter for the cursor type.voidSets the cursor mode toCursorMode.NORMAL.voidupdate()Finalize input handling after input systems.
-
Field Details
-
gamepadEvents
-
CURSOR_TYPE_DEFAULT
public static final int CURSOR_TYPE_DEFAULT -
CURSOR_MODE_DEFAULT
public static final int CURSOR_MODE_DEFAULT -
IGNORE_CURSOR_BLOCK_DEFAULT
public static final boolean IGNORE_CURSOR_BLOCK_DEFAULT- See Also:
-
STOP_PROPAGATION_DEFAULT
public static final boolean STOP_PROPAGATION_DEFAULT- See Also:
-
DEFAULT_GAMEPAD_ID
public static final int DEFAULT_GAMEPAD_ID- See Also:
-
-
Constructor Details
-
Input
Creates an input system.
-
-
Method Details
-
init
public void init()Initializes the input system.- Specified by:
initin interfaceInitializable
-
input
public void input()Prepare handling of input before input systems. -
update
public void update()Finalize input handling after input systems. -
destroy
public void destroy()Destroys this input system.- Specified by:
destroyin interfaceDestructible
-
getAnyKey
Checks whether any key in an array is pressed.- Parameters:
keys- Keys- Returns:
- True if any key is pressed
-
getAnyKey
public boolean getAnyKey(int... keys) Checks whether any key in an array is pressed.- Parameters:
keys- Keys- Returns:
- True if any key is pressed
-
getKeys
Checks whether a combination of keys is pressed.- Parameters:
keys- Keys- Returns:
- True if all keys are pressed
-
getKeys
public boolean getKeys(int... keys) Checks whether a combination of keys is pressed. Returns true in every frame that the key is pressed.- Parameters:
keys- Keys- Returns:
- True if all keys are pressed
-
getKey
Checks whether a key is pressed. Returns true in every frame that the key is pressed.- Returns:
- True if the key is pressed
-
getKey
Checks whether a key is pressed. Returns true in every frame that the key is pressed.- Parameters:
stopPropagation- Whether to stop this key from affecting other listeners- Returns:
- True if the key is pressed
-
getKey
public boolean getKey(int key) Checks whether a key is pressed. Returns true in every frame that the key is pressed.- Parameters:
key- GLFW integer value for a key- Returns:
- True if the key is pressed.
-
getKey
public boolean getKey(int key, boolean stopPropagation) Checks whether a key is pressed. Returns true in every frame that the key is pressed.- Parameters:
key- GLFW integer value for a keystopPropagation- Whether to stop this key from affecting other listeners- Returns:
- True if the key is pressed.
-
getKeyDown
Checks whether a key is down. Returnstruein the first frame that the key is pressed and in every frame the key is being repeated.- Returns:
trueif the key is down.
-
getKeyDown
Checks whether a key is down. Returnstruein the first frame that the key is pressed and in every frame the key is being repeated.- Parameters:
stopPropagation- Whether to stop this key from affecting other listeners- Returns:
trueif the key is down.
-
getKeyDown
public boolean getKeyDown(int key) Checks whether a key is down. Returnstruein the first frame that the key is pressed and in every frame the key is being repeated.- Parameters:
key- GLFW integer value for a key- Returns:
trueif the key is down.
-
getKeyDown
public boolean getKeyDown(int key, boolean stopPropagation) Checks whether a key is down. Returnstruein the first frame that the key is pressed and in every frame the key is being repeated.- Parameters:
key- GLFW integer value for a keystopPropagation- Whether to stop this key from affecting other listeners- Returns:
trueif the key is down.
-
addTextListener
-
removeTextListener
-
getGamepad
Returns the first gamepad if it is connected, otherwise returns a fallback gamepad which returns0ffor all axes andfalsefor all buttons.- Returns:
- The first gamepad or a fallback gamepad
-
getGamepad
Returns the gamepad that matches the given ID.- Returns:
- The gamepad with the given ID.
-
isGamepadConnected
public boolean isGamepadConnected(int id) Checks if the gamepad that matches the given ID is connected.- Returns:
trueif the gamepad with the given ID is connected.
-
onGamepadConnect
-
onGamepadDisconnect
public EventListener<Event<GamepadEventType,Integer>> onGamepadDisconnect(int id, Callback callback) -
getMouseButton
Checks whether a mouse button is pressed.- Returns:
- True if the key is pressed.
-
getMouseButton
Checks whether a mouse button is pressed.- Parameters:
stopPropagation- Whether to stop this mouse button from affecting other listeners- Returns:
- True if the key is pressed.
-
getMouseButton
public boolean getMouseButton(int button) Checks whether a mouse button is pressed.- Parameters:
button- GLFW integer value for a mouse button- Returns:
- True if the key is pressed.
-
getMouseButton
public boolean getMouseButton(int button, boolean stopPropagation) Checks whether a mouse button is pressed.- Parameters:
button- GLFW integer value for a mouse buttonstopPropagation- Whether to stop this mouse button from affecting other listeners- Returns:
- True if the key is pressed.
-
getMouseButtonDown
Checks whether a mouse button is down.- Returns:
- True if the mouse button is down in the current frame
-
getMouseButtonDown
Checks whether a mouse button is down.- Parameters:
stopPropagation- Whether to stop this mouse button from affecting other listeners- Returns:
- True if the mouse button is down in the current frame
-
getMouseButtonDown
public boolean getMouseButtonDown(int button) Checks whether a mouse button is down.- Parameters:
button- GLFW integer value for a mouse button- Returns:
- True if the mouse button is down in the current frame
-
getMouseButtonDown
public boolean getMouseButtonDown(int button, boolean stopPropagation) Checks whether a mouse button is down.- Parameters:
button- GLFW integer value for a mouse buttonstopPropagation- Whether to stop this mouse button from affecting other listeners- Returns:
- True if the mouse button is down in the current frame
-
getScrollX
public float getScrollX()- Returns:
- Horizontal scroll factor.
-
getScrollY
public float getScrollY()- Returns:
- Vertical scroll factor.
-
getCursor
- Returns:
- Position of the cursor on the screen, or
nullif the cursor is being blocked.
-
getCursor
Returns the position of the cursor on the screen. Returnsnullif the cursor is being blocked, unless blocks are being ignored.- Parameters:
ignoreBlock- Whether to ignore blocks.- Returns:
- Position of the cursor
-
getWorldCursor
Returns the position of the cursor inside the world. Returnsnullif the cursor is being blocked.- Returns:
- Position of the cursor
-
getWorldCursor
Returns the position of the cursor inside the world. Returnsnullif the cursor is being blocked, unless blocks are being ignored.- Parameters:
ignoreBlock- Whether to ignore blocks.- Returns:
- Position of the cursor
-
setCursorType
Setter for the cursor type. This value resets after every frame.- Parameters:
cursorType- Cursor type
-
setCursorType
public void setCursorType(int cursorType) Setter for the cursor type. This value resets after every frame.- Parameters:
cursorType- GLFW cursor type integer
-
setCursorImage
-
setCursorImage
-
setCursorImage
-
showCursor
public void showCursor()Sets the cursor mode toCursorMode.NORMAL. -
hideCursor
public void hideCursor()Sets the cursor mode toCursorMode.HIDDEN. -
disableCursor
public void disableCursor()Sets the cursor mode toCursorMode.DISABLED. -
setCursorMode
Changes the cursor mode.When
nullis passed, the cursor mode is set to normal.- Parameters:
cursorMode- The cursor mode to use
-
blockCursor
Prevents the cursor from sending input to remaining entities in the current frame.- Parameters:
entity- Entity that is blocking the cursor
-
blockCursor
Prevents the cursor from sending input to remaining entities in the current frame.- Parameters:
entity- Entity that is blocking the cursoroverride- Whether to override any existing blocking entity.
-
isCursorBlocked
public boolean isCursorBlocked()Checks whether the cursor is being blocked. -
getCursorBlocker
Returns the entity that is blocking the cursor in the current frame. -
printCursorBlocker
public void printCursorBlocker()
-