Class Input

java.lang.Object
dev.prozilla.pine.core.state.input.Input
All Implemented Interfaces:
Destructible, Initializable

public class Input extends Object implements Initializable, Destructible
Handles the GLFW input system.
  • Field Details

  • Constructor Details

    • Input

      public Input(Application application)
      Creates an input system.
  • Method Details

    • init

      public void init()
      Initializes the input system.
      Specified by:
      init in interface Initializable
    • 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:
      destroy in interface Destructible
    • getAnyKey

      public boolean getAnyKey(Key... keys)
      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

      public boolean getKeys(Key... keys)
      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

      public boolean getKey(Key key)
      Checks whether a key is pressed. Returns true in every frame that the key is pressed.
      Returns:
      True if the key is pressed
    • getKey

      public boolean getKey(Key key, boolean stopPropagation)
      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 key
      stopPropagation - Whether to stop this key from affecting other listeners
      Returns:
      True if the key is pressed.
    • getKeyDown

      public boolean getKeyDown(Key key)
      Checks whether a key is down. Returns true in the first frame that the key is pressed and in every frame the key is being repeated.
      Returns:
      true if the key is down.
    • getKeyDown

      public boolean getKeyDown(Key key, boolean stopPropagation)
      Checks whether a key is down. Returns true in 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:
      true if the key is down.
    • getKeyDown

      public boolean getKeyDown(int key)
      Checks whether a key is down. Returns true in 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:
      true if the key is down.
    • getKeyDown

      public boolean getKeyDown(int key, boolean stopPropagation)
      Checks whether a key is down. Returns true in 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
      stopPropagation - Whether to stop this key from affecting other listeners
      Returns:
      true if the key is down.
    • addTextListener

      public void addTextListener(Input.TextListener listener)
    • removeTextListener

      public void removeTextListener(Input.TextListener listener)
    • getGamepad

      public GamepadInput getGamepad()
      Returns the first gamepad if it is connected, otherwise returns a fallback gamepad which returns 0f for all axes and false for all buttons.
      Returns:
      The first gamepad or a fallback gamepad
    • getGamepad

      public GamepadInput getGamepad(int id)
      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:
      true if the gamepad with the given ID is connected.
    • onGamepadConnect

      public EventListener<Event<GamepadEventType,Integer>> onGamepadConnect(int id, Callback callback)
    • onGamepadDisconnect

      public EventListener<Event<GamepadEventType,Integer>> onGamepadDisconnect(int id, Callback callback)
    • getMouseButton

      public boolean getMouseButton(MouseButton button)
      Checks whether a mouse button is pressed.
      Returns:
      True if the key is pressed.
    • getMouseButton

      public boolean getMouseButton(MouseButton button, boolean stopPropagation)
      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 button
      stopPropagation - Whether to stop this mouse button from affecting other listeners
      Returns:
      True if the key is pressed.
    • getMouseButtonDown

      public boolean getMouseButtonDown(MouseButton button)
      Checks whether a mouse button is down.
      Returns:
      True if the mouse button is down in the current frame
    • getMouseButtonDown

      public boolean getMouseButtonDown(MouseButton button, boolean stopPropagation)
      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 button
      stopPropagation - 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

      public Vector2i getCursor()
      Returns:
      Position of the cursor on the screen, or null if the cursor is being blocked.
    • getCursor

      public Vector2i getCursor(boolean ignoreBlock)
      Returns the position of the cursor on the screen. Returns null if the cursor is being blocked, unless blocks are being ignored.
      Parameters:
      ignoreBlock - Whether to ignore blocks.
      Returns:
      Position of the cursor
    • getWorldCursor

      public Vector2f getWorldCursor()
      Returns the position of the cursor inside the world. Returns null if the cursor is being blocked.
      Returns:
      Position of the cursor
    • getWorldCursor

      public Vector2f getWorldCursor(boolean ignoreBlock)
      Returns the position of the cursor inside the world. Returns null if the cursor is being blocked, unless blocks are being ignored.
      Parameters:
      ignoreBlock - Whether to ignore blocks.
      Returns:
      Position of the cursor
    • setCursorType

      public void setCursorType(CursorType cursorType)
      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

      public void setCursorImage(Image image)
    • setCursorImage

      public void setCursorImage(Image image, Vector2i offset)
    • setCursorImage

      public void setCursorImage(Image image, int offsetX, int offsetY)
    • blockCursor

      public void blockCursor(Entity entity)
      Prevents the cursor from sending input to remaining entities in the current frame.
      Parameters:
      entity - Entity that is blocking the cursor
    • blockCursor

      public void blockCursor(Entity entity, boolean override)
      Prevents the cursor from sending input to remaining entities in the current frame.
      Parameters:
      entity - Entity that is blocking the cursor
      override - Whether to override any existing blocking entity.
    • isCursorBlocked

      public boolean isCursorBlocked()
      Checks whether the cursor is being blocked.
    • getCursorBlocker

      public Entity getCursorBlocker()
      Returns the entity that is blocking the cursor in the current frame.
    • printCursorBlocker

      public void printCursorBlocker()