Class GLFWRenderModuleKeyboardInput
java.lang.Object
io.codetoil.curved_spacetime.render.glfw.GLFWRenderModuleKeyboardInput
- All Implemented Interfaces:
RenderModuleKeyboardInput, org.lwjgl.glfw.GLFWKeyCallbackI, org.lwjgl.system.CallbackI, org.lwjgl.system.Pointer
public class GLFWRenderModuleKeyboardInput
extends Object
implements RenderModuleKeyboardInput, org.lwjgl.glfw.GLFWKeyCallbackI
Keyboard input backed by GLFW.
Held state and tapped state come from different places: keyPressed(RenderModuleKeyboardInput.KeyCtx) asks GLFW directly,
while keyTapped(RenderModuleKeyboardInput.KeyCtx) reads a map this class maintains from GLFW's key callback, since a tap
is an edge that polling would miss. That map is cleared each frame by clean(), so a tap
is reported for exactly one frame.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA key identified the way GLFW reports it.Nested classes/interfaces inherited from interface org.lwjgl.system.Pointer
org.lwjgl.system.Pointer.DefaultNested classes/interfaces inherited from interface RenderModuleKeyboardInput
RenderModuleKeyboardInput.KeyCallback -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<RenderModuleKeyboardInput.KeyCallback> Listeners notified whenever a key changes state.Which keys went down since the lastclean(), keyed by GLFW key code.protected final GLFWRenderModuleWindowThe window this input reads from.Fields inherited from interface org.lwjgl.glfw.GLFWKeyCallbackI
DESCRIPTORFields inherited from interface org.lwjgl.system.Pointer
BITS32, BITS64, CLONG_SHIFT, CLONG_SIZE, POINTER_SHIFT, POINTER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionAttaches keyboard handling to the given window. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a callback invoked when a key changes state.voidclean()Clears per-frame state, so that tapped keys are not reported twice.voidinvoke(long handle, int keyCode, int scanCode, int action, int mods) Records a key change from GLFW and notifies the registered callbacks.booleanReturns whether a key is currently held down.booleanReturns whether a key went down during the frame just sampled.voidpoll()Samples the keyboard, refreshing what the query methods report.window()Returns the window this input reads from.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.lwjgl.system.CallbackI
addressMethods inherited from interface org.lwjgl.glfw.GLFWKeyCallbackI
callback, getDescriptor
-
Field Details
-
tappedKeyMap
-
window
The window this input reads from. -
callbacks
Listeners notified whenever a key changes state.
-
-
Constructor Details
-
GLFWRenderModuleKeyboardInput
Attaches keyboard handling to the given window.Installs a GLFW key callback, replacing any previously set on that window.
- Parameters:
window- the window to read keyboard input from
-
-
Method Details
-
window
Description copied from interface:RenderModuleKeyboardInputReturns the window this input reads from.- Specified by:
windowin interfaceRenderModuleKeyboardInput- Returns:
- the owning window
-
addKeyCallBack
Description copied from interface:RenderModuleKeyboardInputRegisters a callback invoked when a key changes state.- Specified by:
addKeyCallBackin interfaceRenderModuleKeyboardInput- Parameters:
callback- the callback to invoke
-
poll
public void poll()Description copied from interface:RenderModuleKeyboardInputSamples the keyboard, refreshing what the query methods report.Called once per frame by the owning window.
- Specified by:
pollin interfaceRenderModuleKeyboardInput
-
clean
public void clean()Description copied from interface:RenderModuleKeyboardInputClears per-frame state, so that tapped keys are not reported twice.- Specified by:
cleanin interfaceRenderModuleKeyboardInput
-
keyPressed
Description copied from interface:RenderModuleKeyboardInputReturns whether a key is currently held down.- Specified by:
keyPressedin interfaceRenderModuleKeyboardInput- Parameters:
keyCtx- the key to test- Returns:
truewhile the key is held
-
keyTapped
Description copied from interface:RenderModuleKeyboardInputReturns whether a key went down during the frame just sampled.Unlike
RenderModuleKeyboardInput.keyPressed(RenderModuleKeyboardInput.KeyCtx), this is true for a single frame per press.- Specified by:
keyTappedin interfaceRenderModuleKeyboardInput- Parameters:
keyCtx- the key to test- Returns:
trueif the key was newly pressed this frame
-
invoke
public void invoke(long handle, int keyCode, int scanCode, int action, int mods) Records a key change from GLFW and notifies the registered callbacks.Events for other windows are ignored, since a GLFW callback is shared across the process.
- Specified by:
invokein interfaceorg.lwjgl.glfw.GLFWKeyCallbackI- Parameters:
handle- the GLFW window the event came fromkeyCode- the GLFW key codescanCode- the platform-specific scancodeaction- the GLFW action, such asGLFW_PRESSorGLFW_RELEASEmods- the modifier key bitmask in effect
-