vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::InputHandle Class Reference

One frame of raw device state: keys and buttons down, cursor position and wheel turn. More...

#include <input_handle.h>

Public Member Functions

bool isKeyPressed (int key) const
 Check whether the specified key is currently held down.
bool wasKeyStruck (int key) const
 Whether the key went down since the last clearStrikes().
bool wasKeyTyped (int key) const
 Whether the key went down or auto-repeated since the last clearStrikes().
void onKeyEvent (int key, bool pressed)
 Record a key's held state.
void onText (char32_t codepoint)
 Record a character the keyboard produced.
const std::u32string & text () const
 The characters typed since the last clearStrikes(), in order, as UTF-32.
void moveTo (double x, double y)
 Move the cursor to x, y, recording the step it took.
void setButton (int button, bool pressed)
 Record a mouse button's held state.
bool isButtonPressed (int button) const
 Check if the specified mouse button is pressed.
bool wasButtonStruck (int button) const
 Whether the button went down since the last clearStrikes(), even if it is up again.
void clearStrikes ()
 Forget every key and button press, repeat and character recorded so far.
void resetScrollDelta ()
 Zero the scroll delta before the window polls for this frame's.
void addScroll (double yOffset)
 Add to this frame's scroll, which resetScrollDelta() clears.
double getX () const
 The absolute cursor X position.
double getY () const
 The absolute cursor Y position.
double getDeltaX () const
 The X movement the last moveTo recorded.
double getDeltaY () const
 The Y movement the last moveTo recorded.
double getScrollY () const
 The scroll accumulated since resetScrollDelta().

Detailed Description

One frame of raw device state: keys and buttons down, cursor position and wheel turn.

Source-agnostic, which keeps the windowing library out of the input path. Main thread only, so unsynchronised. A key or button also records a strike since the last clearStrikes(): one poll can deliver a press and its release together, which the level alone would miss.

Member Function Documentation

◆ isKeyPressed()

bool Vkm::Engine::InputHandle::isKeyPressed ( int key) const

Check whether the specified key is currently held down.

Parameters
keyThe GLFW key code to query.
Returns
True if the key is currently pressed; false for out-of-range keys.

◆ wasKeyStruck()

bool Vkm::Engine::InputHandle::wasKeyStruck ( int key) const

Whether the key went down since the last clearStrikes().

True even when it is up again: a tap shorter than one poll.

Parameters
keyThe GLFW key code to query.
Returns
True if a press arrived; false for out-of-range keys.

◆ wasKeyTyped()

bool Vkm::Engine::InputHandle::wasKeyTyped ( int key) const

Whether the key went down or auto-repeated since the last clearStrikes().

Parameters
keyThe GLFW key code to query.
Returns
True if a press or a repeat arrived; false for out-of-range keys.

◆ onKeyEvent()

void Vkm::Engine::InputHandle::onKeyEvent ( int key,
bool pressed )

Record a key's held state.

A key going down is also recorded as struck. Out-of-range codes are ignored.

Parameters
keyThe GLFW key code that changed.
pressedTrue when now held. A press of a key already held is a repeat: typed, not struck.

◆ onText()

void Vkm::Engine::InputHandle::onText ( char32_t codepoint)

Record a character the keyboard produced.

Parameters
codepointA Unicode codepoint.

◆ text()

const std::u32string & Vkm::Engine::InputHandle::text ( ) const
inline

The characters typed since the last clearStrikes(), in order, as UTF-32.

Layout, Shift and dead keys already applied.

Returns
The characters, oldest first.

◆ moveTo()

void Vkm::Engine::InputHandle::moveTo ( double x,
double y )

Move the cursor to x, y, recording the step it took.

The delta is derived, so position and movement cannot disagree.

Parameters
xCursor X in window pixels, from the left.
yCursor Y in window pixels, from the top.

◆ setButton()

void Vkm::Engine::InputHandle::setButton ( int button,
bool pressed )

Record a mouse button's held state.

A button going down is also recorded as struck, as for a key.

Parameters
buttonButton code; out of range is ignored.
pressedTrue while it is down.

◆ isButtonPressed()

bool Vkm::Engine::InputHandle::isButtonPressed ( int button) const

Check if the specified mouse button is pressed.

Parameters
buttonThe GLFW mouse button code.
Returns
True if button is pressed.

◆ wasButtonStruck()

bool Vkm::Engine::InputHandle::wasButtonStruck ( int button) const

Whether the button went down since the last clearStrikes(), even if it is up again.

Parameters
buttonThe GLFW mouse button code.
Returns
True if a press arrived; false for out-of-range buttons.

◆ resetScrollDelta()

void Vkm::Engine::InputHandle::resetScrollDelta ( )

Zero the scroll delta before the window polls for this frame's.

The scroll callback adds to it; without this one notch would turn every frame after.

◆ addScroll()

void Vkm::Engine::InputHandle::addScroll ( double yOffset)

Add to this frame's scroll, which resetScrollDelta() clears.

Accumulated: a frame can carry several scroll events.

Parameters
yOffsetNotches turned, positive away from the viewer.

◆ getX()

double Vkm::Engine::InputHandle::getX ( ) const
inline

The absolute cursor X position.

Returns
Cursor X in window pixels, from the left.

◆ getY()

double Vkm::Engine::InputHandle::getY ( ) const
inline

The absolute cursor Y position.

Returns
Cursor Y in window pixels, from the top.

◆ getDeltaX()

double Vkm::Engine::InputHandle::getDeltaX ( ) const
inline

The X movement the last moveTo recorded.

Returns
Pixels moved along X.

◆ getDeltaY()

double Vkm::Engine::InputHandle::getDeltaY ( ) const
inline

The Y movement the last moveTo recorded.

Returns
Pixels moved along Y.

◆ getScrollY()

double Vkm::Engine::InputHandle::getScrollY ( ) const
inline

The scroll accumulated since resetScrollDelta().

Returns
Notches turned, positive away from the viewer.

The documentation for this class was generated from the following file: