Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Input Class Reference

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

Inputoperator= (const Input &)=delete
 
 Input (const Input &)=delete
 
Inputoperator= (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
 
Controllercontroller () 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 Inputmanager ()
 

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,...).
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Input() [1/2]

Input::Input ( const Input )
delete

Copy constructor (disabled).

◆ Input() [2/2]

Input::Input ( Input &&  )
delete

Move constructor (disabled).

Member Function Documentation

◆ controller()

Controller * Input::controller ( ) const
inline

Query the current controller (joystick).

Returns
a reference to the current controller
Warning
Make sure a controller is available before calling this method.

◆ controllerAvailable()

bool Input::controllerAvailable ( ) const
inline

Query if a controller (joystick) is available.

Returns
true if a controller is available

◆ controllerConnected()

bool Input::controllerConnected ( ) const
inline

Query if a controller (joystick) was connected at this frame.

Returns
true if a controller has just been connected

◆ controllerDisconnected()

bool Input::controllerDisconnected ( ) const
inline

Query if a controller (joystick) was disconnected at this frame.

Returns
true if a controller has just been disconnected

◆ density()

float Input::density ( ) const

Query the current screen density.

Returns
The screen density.

◆ densityEvent()

void Input::densityEvent ( float  density)

Register a screen density change event.

Parameters
densitythe new density of the screen

◆ interacted()

bool Input::interacted ( ) const

Check if the user interacted with the keyboard, window, or mouse (except mouse moves).

Returns
true if any interaction happened.

◆ joystickEvent()

void Input::joystickEvent ( int  joy,
int  event 
)

Register a joystick event.

Parameters
joythe ID of the joystick
eventthe joystick event

◆ keyPressedEvent()

void Input::keyPressedEvent ( int  key,
int  action 
)

Register a keyboard event.

Parameters
keythe key code
actionthe action code (pressed/released)

◆ manager()

Input & Input::manager ( )
static

Accessor to the Input manager singleton.

Returns
the Input manager

◆ minimized()

bool Input::minimized ( ) const
inline

Query if the window has been minimized.

Returns
true if the window is minimized

◆ minimizedEvent()

void Input::minimizedEvent ( bool  minimized)

Register a window minification event.

Parameters
minimizedthe current state of the window

◆ mouse()

glm::vec2 Input::mouse ( ) const

Query the current mouse position.

Returns
the current mouse position in unit coordinates, from the bottom left corner.

◆ mouseMovedEvent()

void Input::mouseMovedEvent ( double  x,
double  y 
)

Register a mouse move event.

Parameters
xthe horizontal position of the cursor, in pixels
ythe vertical position of the cursor, in pixels

◆ mousePressedEvent()

void Input::mousePressedEvent ( int  button,
int  action 
)

Register a mouse button event.

Parameters
buttonthe button code
actionthe action code (pressed/released)

◆ mouseScrolledEvent()

void Input::mouseScrolledEvent ( double  xoffset,
double  yoffset 
)

Register a mouse scroll event.

Parameters
xoffsetthe horizontal amount of scrolling
yoffsetthe vertical amount of scrolling

◆ moved()

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.

Parameters
mouseButtonthe mouse button to track
Returns
the amount of displacement on both axis in unit coordinates.
Note
The displacement will be expressed in the [0,1] range.

◆ operator=() [1/2]

Input & Input::operator= ( const Input )
delete

Copy operator (disabled).

Returns
a reference to the object assigned to

◆ operator=() [2/2]

Input & Input::operator= ( Input &&  )
delete

Move operator (disabled).

Returns
a reference to the object assigned to

◆ preferRawControllers()

void Input::preferRawControllers ( bool  prefer)

Disable the GLFW/SDL available controller mappings.

Parameters
prefershould the input only use raw controllers

◆ pressed() [1/2]

bool Input::pressed ( const Key keyboardKey) const

Query if a given key is held at this frame.

Parameters
keyboardKeythe key code
Returns
true if the key is currently pressed.

◆ pressed() [2/2]

bool Input::pressed ( const Mouse mouseButton) const

Query if a given mouse button is held at this frame.

Parameters
mouseButtonthe mouse button code
Returns
true if the button is currently pressed.

◆ released() [1/2]

bool Input::released ( const Key keyboardKey,
bool  absorb = false 
)

Query if a given key was released at this frame precisely.

Parameters
keyboardKeythe key code
absorbshould the press event be hidden from future queries during the current frame
Returns
true if the key was released at this frame.

◆ released() [2/2]

bool Input::released ( const Mouse mouseButton,
bool  absorb = false 
)

Query if a given mouse button was released at this frame precisely.

Parameters
mouseButtonthe mouse button code
absorbshould the press event be hidden from future queries during the current frame
Returns
true if the mouse button was released at this frame.

◆ resized()

bool Input::resized ( ) const
inline

Query if the window has been resized at this frame.

Returns
true if the window was resized

◆ resizeEvent()

void Input::resizeEvent ( int  width,
int  height 
)

Register a window size change event.

Parameters
widththe new width of the window
heightthe new height of the window

◆ scroll()

glm::vec2 Input::scroll ( ) const

Query the current scroll amount.

Returns
the current scrolling amount on both axis
Note
The scroll amount is in arbitrary units.

◆ size()

glm::ivec2 Input::size ( ) const
inline

Query the current window size.

Returns
the size of the window, in pixels

◆ triggered() [1/2]

bool Input::triggered ( const Key keyboardKey,
bool  absorb = false 
)

Query if a given key was pressed at this frame precisely.

Parameters
keyboardKeythe key code
absorbshould the press event be hidden from future queries during the current frame
Returns
true if the key was triggered at this frame.

◆ triggered() [2/2]

bool Input::triggered ( const Mouse mouseButton,
bool  absorb = false 
)

Query if a given mouse button was pressed at this frame precisely.

Parameters
mouseButtonthe mouse button code
absorbshould the press event be hidden from future queries during the current frame
Returns
true if the mouse button was triggered at this frame.

◆ update()

void Input::update ( )

Trigger an update of the internal state


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