Rendu
A lightweight rendering engine for experimentations
|
The input manager is responsible for updating the internal input states (keyboard, mouse, window size). It can also be use to query back these states. More...
#include <Input.hpp>
Classes | |
struct | KeyboardKey |
Keyboard state. More... | |
struct | MouseButton |
Mouse state. More... | |
struct | MouseCursor |
Mouse cursor state. More... | |
Public Types | |
enum class | Key : uint { Space = 0 , Apostrophe , Comma , Minus , Period , Slash , N0 , N1 , N2 , N3 , N4 , N5 , N6 , N7 , N8 , N9 , Semicolon , Equal , A , B , C , D , E , F , G , H , I , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z , LeftBracket , Backslash , RightBracket , GraveAccent , World1 , World2 , Escape , Enter , Tab , Backspace , Insert , Delete , Right , Left , Down , Up , PageUp , PageDown , Home , End , CapsLock , ScrollLock , NumLock , PrintScreen , Pause , F1 , F2 , F3 , F4 , F5 , F6 , F7 , F8 , F9 , F10 , F11 , F12 , F13 , F14 , F15 , F16 , F17 , F18 , F19 , F20 , F21 , F22 , F23 , F24 , F25 , Pad0 , Pad1 , Pad2 , Pad3 , Pad4 , Pad5 , Pad6 , Pad7 , Pad8 , Pad9 , PadDecimal , PadDivide , PadMultiply , PadSubtract , PadAdd , PadEnter , PadEqual , LeftShift , LeftControl , LeftAlt , LeftSuper , RightShift , RightControl , RightAlt , RightSuper , Menu , Count } |
Keys codes. | |
enum class | Mouse : uint { Left = 0 , Right = 1 , Middle = 2 , Count = 3 } |
Mouse buttons codes. | |
Public Member Functions | |
Input & | operator= (const Input &)=delete |
Input (const Input &)=delete | |
Input & | operator= (Input &&)=delete |
Input (Input &&)=delete | |
Input settings | |
void | preferRawControllers (bool prefer) |
Input updates | |
void | keyPressedEvent (int key, int action) |
void | joystickEvent (int joy, int event) |
void | mousePressedEvent (int button, int action) |
void | mouseMovedEvent (double x, double y) |
void | mouseScrolledEvent (double xoffset, double yoffset) |
void | resizeEvent (int width, int height) |
void | minimizedEvent (bool minimized) |
void | densityEvent (float density) |
void | update () |
Input queries | |
bool | resized () const |
bool | minimized () const |
glm::ivec2 | size () const |
bool | controllerAvailable () const |
bool | controllerConnected () const |
bool | controllerDisconnected () const |
Controller * | controller () const |
bool | pressed (const Key &keyboardKey) const |
bool | triggered (const Key &keyboardKey, bool absorb=false) |
bool | released (const Key &keyboardKey, bool absorb=false) |
bool | pressed (const Mouse &mouseButton) const |
bool | triggered (const Mouse &mouseButton, bool absorb=false) |
bool | released (const Mouse &mouseButton, bool absorb=false) |
glm::vec2 | mouse () const |
glm::vec2 | moved (const Mouse &mouseButton) const |
glm::vec2 | scroll () const |
float | density () const |
bool | interacted () const |
Static Public Member Functions | |
static Input & | manager () |
Private Member Functions | |
Input () | |
Constructor (disabled). | |
~Input ()=default | |
Destructor (disabled). | |
Private Attributes | |
unsigned int | _width = 1 |
Internal window width in pixels. | |
unsigned int | _height = 1 |
Internal window height in pixels. | |
bool | _resized = false |
Denote if the window was resized at the current frame. | |
bool | _minimized = false |
Is the window minimized and thus hidden. | |
float | _density = 1.0f |
The screen density. | |
int | _activeController = -1 |
The active joystick ID, or -1 if no controller active. | |
std::unique_ptr< Controller > | _controllers [16] |
States of all possible controllers. | |
bool | _preferRawControllers = false |
Should controller use the gamepad mappings or raw values. | |
bool | _joystickConnected = false |
Has a joystick just been connected. | |
bool | _joystickDisconnected = false |
Has a joystick just been disconnected. | |
MouseButton | _mouseButtons [uint(Mouse::Count)] |
States of all possible mouse buttons. | |
MouseCursor | _mouse |
State of the mouse cursor. | |
KeyboardKey | _keys [uint(Key::Count)] |
States of all possible keyboard keys. | |
bool | _mouseInteracted = false |
Did the user interact with the mouse. | |
bool | _keyInteracted = false |
Did the user interact with the keyboard. | |
bool | _windowInteracted = false |
Did the user interact with the window (minimize, resize,...). | |
The input manager is responsible for updating the internal input states (keyboard, mouse, window size). It can also be use to query back these states.
|
delete |
Copy constructor (disabled).
|
delete |
Move constructor (disabled).
|
inline |
Query the current controller (joystick).
|
inline |
Query if a controller (joystick) is available.
|
inline |
Query if a controller (joystick) was connected at this frame.
|
inline |
Query if a controller (joystick) was disconnected at this frame.
float Input::density | ( | ) | const |
Query the current screen density.
void Input::densityEvent | ( | float | density | ) |
Register a screen density change event.
density | the new density of the screen |
bool Input::interacted | ( | ) | const |
Check if the user interacted with the keyboard, window, or mouse (except mouse moves).
void Input::joystickEvent | ( | int | joy, |
int | event | ||
) |
Register a joystick event.
joy | the ID of the joystick |
event | the joystick event |
void Input::keyPressedEvent | ( | int | key, |
int | action | ||
) |
Register a keyboard event.
key | the key code |
action | the action code (pressed/released) |
|
inline |
Query if the window has been minimized.
void Input::minimizedEvent | ( | bool | minimized | ) |
Register a window minification event.
minimized | the current state of the window |
glm::vec2 Input::mouse | ( | ) | const |
Query the current mouse position.
void Input::mouseMovedEvent | ( | double | x, |
double | y | ||
) |
Register a mouse move event.
x | the horizontal position of the cursor, in pixels |
y | the vertical position of the cursor, in pixels |
void Input::mousePressedEvent | ( | int | button, |
int | action | ||
) |
Register a mouse button event.
button | the button code |
action | the action code (pressed/released) |
void Input::mouseScrolledEvent | ( | double | xoffset, |
double | yoffset | ||
) |
Register a mouse scroll event.
xoffset | the horizontal amount of scrolling |
yoffset | the vertical amount of scrolling |
glm::vec2 Input::moved | ( | const Mouse & | mouseButton | ) | const |
Query the amount of cursor displacement since a given mouse button started to be held. If the button is not currently pressed, is returns a null displacement.
mouseButton | the mouse button to track |
Copy operator (disabled).
Move operator (disabled).
void Input::preferRawControllers | ( | bool | prefer | ) |
Disable the GLFW/SDL available controller mappings.
prefer | should the input only use raw controllers |
bool Input::pressed | ( | const Key & | keyboardKey | ) | const |
Query if a given key is held at this frame.
keyboardKey | the key code |
bool Input::pressed | ( | const Mouse & | mouseButton | ) | const |
Query if a given mouse button is held at this frame.
mouseButton | the mouse button code |
bool Input::released | ( | const Key & | keyboardKey, |
bool | absorb = false |
||
) |
Query if a given key was released at this frame precisely.
keyboardKey | the key code |
absorb | should the press event be hidden from future queries during the current frame |
bool Input::released | ( | const Mouse & | mouseButton, |
bool | absorb = false |
||
) |
Query if a given mouse button was released at this frame precisely.
mouseButton | the mouse button code |
absorb | should the press event be hidden from future queries during the current frame |
|
inline |
Query if the window has been resized at this frame.
void Input::resizeEvent | ( | int | width, |
int | height | ||
) |
Register a window size change event.
width | the new width of the window |
height | the new height of the window |
glm::vec2 Input::scroll | ( | ) | const |
Query the current scroll amount.
|
inline |
Query the current window size.
bool Input::triggered | ( | const Key & | keyboardKey, |
bool | absorb = false |
||
) |
Query if a given key was pressed at this frame precisely.
keyboardKey | the key code |
absorb | should the press event be hidden from future queries during the current frame |
bool Input::triggered | ( | const Mouse & | mouseButton, |
bool | absorb = false |
||
) |
Query if a given mouse button was pressed at this frame precisely.
mouseButton | the mouse button code |
absorb | should the press event be hidden from future queries during the current frame |
void Input::update | ( | ) |
Trigger an update of the internal state