BARE2D
BARE2D::InputManager Class Reference

This is the input manager. It does what you expect! Nearly completely copied from GLEngine, the ol' gal. More...

#include <InputManager.hpp>

+ Collaboration diagram for BARE2D::InputManager:

Public Member Functions

 InputManager ()
 
 ~InputManager ()
 
void update ()
 Updates the inputmanager. Should be called every frame. More...
 
void pressKey (unsigned int keyID)
 Sets a key as 'pressed'. More...
 
void releaseKey (unsigned int keyID)
 Sets a key as 'released'. More...
 
void setMousePosition (float x, float y)
 Sets the mouse position to (x,y) More...
 
void setMousePosition (glm::vec2 position)
 Sets the mouse position to 'position'. More...
 
void setMouseScrollwheelPosition (int position)
 Sets the "position" of the scrollwheel - essentially, how much it has moved since the last frame. More...
 
bool isKeyDown (unsigned int keyID) const
 Checks if the key is down at all. More...
 
bool isKeyPressed (unsigned int keyID) const
 Checks if the key has just been pressed. More...
 
char getPressedCharacter (bool alpha=true, bool nums=true, bool all=true) const
 Gets entered character (This just follows the first character that has been pressed this update) More...
 
glm::vec2 getMousePosition () const
 Gets the position of the mouse in the window. More...
 
int getMouseScrollwheelPosition () const
 Gets the position of the mousewheel. More...
 

Private Member Functions

bool wasKeyDown (unsigned int keyID) const
 Checks if the key was down last frame. More...
 

Private Attributes

std::unordered_map< unsigned int, bool > m_keyMap
 
std::unordered_map< unsigned int, bool > m_previousKeyMap
 
glm::vec2 m_mousePosition
 
int m_mouseScrollwheelPosition = 0
 

Detailed Description

This is the input manager. It does what you expect! Nearly completely copied from GLEngine, the ol' gal.

Definition at line 12 of file InputManager.hpp.

Constructor & Destructor Documentation

◆ InputManager()

BARE2D::InputManager::InputManager ( )

Definition at line 7 of file InputManager.cpp.

◆ ~InputManager()

BARE2D::InputManager::~InputManager ( )

Definition at line 10 of file InputManager.cpp.

Member Function Documentation

◆ getMousePosition()

glm::vec2 BARE2D::InputManager::getMousePosition ( ) const

Gets the position of the mouse in the window.

Returns
The position of the mouse in a glm::vec2

Definition at line 115 of file InputManager.cpp.

References m_mousePosition.

◆ getMouseScrollwheelPosition()

int BARE2D::InputManager::getMouseScrollwheelPosition ( ) const

Gets the position of the mousewheel.

Returns
How much the mousewheel has moved since last update.

Definition at line 120 of file InputManager.cpp.

References m_mouseScrollwheelPosition.

◆ getPressedCharacter()

char BARE2D::InputManager::getPressedCharacter ( bool  alpha = true,
bool  nums = true,
bool  all = true 
) const

Gets entered character (This just follows the first character that has been pressed this update)

Parameters
alphaIf true, checks alphabetical characters
numsIf true, checks numbers
symbolsIf true, checks all other (readable) symbols
Returns
The character pressed.

Definition at line 76 of file InputManager.cpp.

References isKeyDown(), and isKeyPressed().

+ Here is the call graph for this function:

◆ isKeyDown()

bool BARE2D::InputManager::isKeyDown ( unsigned int  keyID) const

Checks if the key is down at all.

Parameters
keyIDThe SDL-given ID to check against
Returns
true if the key is down

Definition at line 53 of file InputManager.cpp.

References m_keyMap.

Referenced by getPressedCharacter(), and isKeyPressed().

+ Here is the caller graph for this function:

◆ isKeyPressed()

bool BARE2D::InputManager::isKeyPressed ( unsigned int  keyID) const

Checks if the key has just been pressed.

Parameters
keyIDThe SDL-given ID to check against
Returns
true if the key wasn't down last frame and is this frame. false otherwise

Definition at line 70 of file InputManager.cpp.

References isKeyDown(), and wasKeyDown().

Referenced by getPressedCharacter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pressKey()

void BARE2D::InputManager::pressKey ( unsigned int  keyID)

Sets a key as 'pressed'.

Parameters
keyIDThe id given for a key by SDL

Definition at line 25 of file InputManager.cpp.

References m_keyMap.

Referenced by BARE2D::App::pollSDLInput().

+ Here is the caller graph for this function:

◆ releaseKey()

void BARE2D::InputManager::releaseKey ( unsigned int  keyID)

Sets a key as 'released'.

Parameters
keyIDThe id given for a key by SDL

Definition at line 31 of file InputManager.cpp.

References m_keyMap.

Referenced by BARE2D::App::pollSDLInput().

+ Here is the caller graph for this function:

◆ setMousePosition() [1/2]

void BARE2D::InputManager::setMousePosition ( float  x,
float  y 
)

Sets the mouse position to (x,y)

Parameters
xA float to represent x position
yA float to represent y position

Definition at line 37 of file InputManager.cpp.

References m_mousePosition.

Referenced by BARE2D::App::pollSDLInput().

+ Here is the caller graph for this function:

◆ setMousePosition() [2/2]

void BARE2D::InputManager::setMousePosition ( glm::vec2  position)

Sets the mouse position to 'position'.

Parameters
positionThe position to set it to.

Definition at line 43 of file InputManager.cpp.

References m_mousePosition.

◆ setMouseScrollwheelPosition()

void BARE2D::InputManager::setMouseScrollwheelPosition ( int  position)

Sets the "position" of the scrollwheel - essentially, how much it has moved since the last frame.

Parameters
positionThe distance it has moved since last update.

Definition at line 48 of file InputManager.cpp.

References m_mouseScrollwheelPosition.

Referenced by BARE2D::App::pollSDLInput().

+ Here is the caller graph for this function:

◆ update()

void BARE2D::InputManager::update ( )

Updates the inputmanager. Should be called every frame.

Definition at line 13 of file InputManager.cpp.

References m_keyMap, m_mouseScrollwheelPosition, and m_previousKeyMap.

Referenced by BARE2D::App::updateInput().

+ Here is the caller graph for this function:

◆ wasKeyDown()

bool BARE2D::InputManager::wasKeyDown ( unsigned int  keyID) const
private

Checks if the key was down last frame.

Parameters
keyIDThe SDL-given ID to check against
Returns
true if the key was down last frame, false otherwise.

Definition at line 125 of file InputManager.cpp.

References m_previousKeyMap.

Referenced by isKeyPressed().

+ Here is the caller graph for this function:

Field Documentation

◆ m_keyMap

std::unordered_map<unsigned int, bool> BARE2D::InputManager::m_keyMap
private

Definition at line 97 of file InputManager.hpp.

Referenced by isKeyDown(), pressKey(), releaseKey(), and update().

◆ m_mousePosition

glm::vec2 BARE2D::InputManager::m_mousePosition
private

Definition at line 99 of file InputManager.hpp.

Referenced by getMousePosition(), and setMousePosition().

◆ m_mouseScrollwheelPosition

int BARE2D::InputManager::m_mouseScrollwheelPosition = 0
private

◆ m_previousKeyMap

std::unordered_map<unsigned int, bool> BARE2D::InputManager::m_previousKeyMap
private

Definition at line 98 of file InputManager.hpp.

Referenced by update(), and wasKeyDown().


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