Class GLFWInputSystem
Annotated input objects are attached to this system as listeners and have their fields altered and methods called when events are sent through via window events and other device polling like joysticks/gamepads.
Since the Main thread is the thread responsible for carrying out callbacks and other listeners via a window, all input objects should handle their event consumption as lightly as possible so that other event processing doesn't get held up. If actions need to be taken on value changes via mouse/keyboard events, it might be worth processing in a parallel thread and kicked off by a listener that listens for event dispatch completion.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA listener interface for when joysticks/gamepads get connected or disconnected from GLFW.static interfaceJoystick input parameters per added device. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInputObject(Object inputObject) Adds an object that is annotated for receiving input events to this input system.voidaddJoystickInputObject(int jid, GLFWInputSystem.JoystickInputParameters parameters, Object inputObject) Adds a joystick-specific object that is annotated for receiving input events to this input system.voidaddJoystickInputObject(int jid, Object inputObject) Adds a joystick-specific object that is annotated for receiving input events to this input system.voidAdds a joystick listener to this input system to listen for joystick connections and disconnections.voidattachToWindow(GLFWWindow window) Attaches this input system to a window.voiddetachFromWindow(GLFWWindow window) Detaches this input system from a window.voidThis method must be called in order to prep joysticks for polling.voidThis method must be called in order to prep joysticks for polling.booleanfireJoystickAxisEvent(int jid, JoystickAxisType type, double amount) Fires a joystick axis event in this system.booleanfireJoystickButtonEvent(int jid, JoystickButtonType type, boolean pressed) Fires a joystick button event in this system.booleanfireJoystickDirectionEvent(int jid, JoystickAxisType type, JoystickDirectionType direction) Fires a joystick direction event in this system.booleanfireJoystickHatEvent(int jid, int index, JoystickHatType type) Fires a joystick hat event in this system.booleanfireKeyEvent(KeyType type, boolean pressed) Fires a key event in this system.booleanfireKeyTypedEvent(char c) Fires a key typed event in this system.booleanfireMouseAxisEvent(MouseAxisType type, double amount) Fires a mouse axis event in this system.booleanfireMouseButtonEvent(MouseButtonType type, boolean pressed) Fires a mouse button event in this system.booleanfireMousePositionEvent(MouseAxisType type, double value) Fires a mouse position event in this system.booleanfireMouseScrollEvent(MouseScrollType type, double amount) Fires a mouse scroll event in this system.voidPolls all connected joysticks.voidremoveInputObject(Object inputObject) Removes an object that is annotated for receiving input events from this input system.voidremoveJoystickInputObject(int jid) Removes a joystick-specific object that is annotated for receiving input events to this input system.voidRemoves a joystick listener from this input system.
-
Constructor Details
-
GLFWInputSystem
public GLFWInputSystem()Creates a new input system.
-
-
Method Details
-
addInputObject
Adds an object that is annotated for receiving input events to this input system. Adding or removing an object from this system in thread-safe.- Parameters:
inputObject- the input object to add.- Throws:
InputSetupException- if an object's annotations are not set up properly.
-
removeInputObject
Removes an object that is annotated for receiving input events from this input system. Adding or removing an object from this system in thread-safe.- Parameters:
inputObject- the input object to remove.
-
addJoystickInputObject
Adds a joystick-specific object that is annotated for receiving input events to this input system. Adding or removing an object from this system is thread-safe. Adding a joystick where a JID is already used will remove the old one.- Parameters:
jid- the joystick id.inputObject- the input object to add.- Throws:
InputSetupException- if an object's annotations are not set up properly.
-
addJoystickInputObject
public void addJoystickInputObject(int jid, GLFWInputSystem.JoystickInputParameters parameters, Object inputObject) Adds a joystick-specific object that is annotated for receiving input events to this input system. Adding or removing an object from this system is thread-safe. Adding a joystick where a JID is already used will remove the old one.- Parameters:
jid- the joystick id.parameters- the joystick parameters.inputObject- the input object to add.- Throws:
InputSetupException- if an object's annotations are not set up properly.
-
removeJoystickInputObject
public void removeJoystickInputObject(int jid) Removes a joystick-specific object that is annotated for receiving input events to this input system. Adding or removing an object from this system in thread-safe.- Parameters:
jid- the joystick id.- Throws:
InputSetupException- if an object's annotations are not set up properly.
-
attachToWindow
Attaches this input system to a window. This listens for key/mouse events.Essentially just attaches the window and input listener of this system to the window.
- Parameters:
window- the window to accept events from.
-
detachFromWindow
Detaches this input system from a window.Essentially just detaches the window and input listener of this system from the window.
- Parameters:
window- the window to remove from.
-
addJoystickListener
Adds a joystick listener to this input system to listen for joystick connections and disconnections. Usually, an annotated input object is added on connection, and removed on disconnect. This method is thread safe.Joystick support does not need to be enabled for this to be called.
- Parameters:
listener- the listener to add.
-
removeJoystickListener
Removes a joystick listener from this input system. This method is thread safe.Joystick support does not need to be enabled for this to be called.
- Parameters:
listener- the listener to remove.
-
enableJoysticks
public void enableJoysticks()This method must be called in order to prep joysticks for polling. If joysticks are already enabled, this does nothing.This will fire connection events to
GLFWInputSystem.JoystickConnectionListeners for each joystick found at enable so that they can be attached as input listeners.This must only be called from the main thread.
-
disableJoysticks
public void disableJoysticks()This method must be called in order to prep joysticks for polling. If joysticks are already enabled, this does nothing. -
pollJoysticks
public void pollJoysticks()Polls all connected joysticks.This must only be called from the main thread.
-
fireKeyEvent
Fires a key event in this system.- Parameters:
type- the key type.pressed- true if pressed, false if released.- Returns:
- true if the event was handled by an object, false if not.
-
fireKeyTypedEvent
public boolean fireKeyTypedEvent(char c) Fires a key typed event in this system.- Parameters:
c- the character typed.- Returns:
- true if the event was handled by an object, false if not.
-
fireMouseButtonEvent
Fires a mouse button event in this system.- Parameters:
type- the mouse button type.pressed- true if pressed, false if released.- Returns:
- true if the event was handled by an object, false if not.
-
fireMouseAxisEvent
Fires a mouse axis event in this system.- Parameters:
type- the mouse axis type.amount- the amount moved.- Returns:
- true if the event was handled by an object, false if not.
-
fireMousePositionEvent
Fires a mouse position event in this system.- Parameters:
type- the mouse axis type.value- the mouse position value.- Returns:
- true if the event was handled by an object, false if not.
-
fireMouseScrollEvent
Fires a mouse scroll event in this system.- Parameters:
type- the mouse axis type.amount- the scroll amount.- Returns:
- true if the event was handled by an object, false if not.
-
fireJoystickButtonEvent
Fires a joystick button event in this system.- Parameters:
jid- the joystick id to fire to.type- the joystick button type.pressed- true if pressed, false if released.- Returns:
- true if the event was handled by an object, false if not.
-
fireJoystickAxisEvent
Fires a joystick axis event in this system.- Parameters:
jid- the joystick id to fire to.type- the joystick axis type.amount- the amount moved.- Returns:
- true if the event was handled by an object, false if not.
-
fireJoystickHatEvent
Fires a joystick hat event in this system.- Parameters:
jid- the joystick id to fire to.index- the hat index on the device.type- the joystick hat type.- Returns:
- true if the event was handled by an object, false if not.
-
fireJoystickDirectionEvent
public boolean fireJoystickDirectionEvent(int jid, JoystickAxisType type, JoystickDirectionType direction) Fires a joystick direction event in this system.- Parameters:
jid- the joystick id to fire to.type- the joystick axis type.direction- the joystick hat direction type.- Returns:
- true if the event was handled by an object, false if not.
-