BARE2D
InputManager.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <glm/glm.hpp>
4
#include <unordered_map>
5
6
namespace
BARE2D
{
7
8
/**
9
* @class InputManager
10
* @brief This is the input manager. It does what you expect! Nearly completely copied from GLEngine, the ol' gal.
11
*/
12
class
InputManager
13
{
14
public
:
15
InputManager
();
16
~InputManager
();
17
18
/**
19
* @brief Updates the inputmanager. Should be called every frame.
20
*/
21
void
update
();
22
23
/**
24
* @brief Sets a key as 'pressed'
25
* @param keyID The id given for a key by SDL
26
*/
27
void
pressKey
(
unsigned
int
keyID);
28
29
/**
30
* @brief Sets a key as 'released'
31
* @param keyID The id given for a key by SDL
32
*/
33
void
releaseKey
(
unsigned
int
keyID);
34
35
/**
36
* @brief Sets the mouse position to (x,y)
37
* @param x A float to represent x position
38
* @param y A float to represent y position
39
*/
40
void
setMousePosition
(
float
x,
float
y);
41
42
/**
43
* @brief Sets the mouse position to 'position'
44
* @param position The position to set it to.
45
*/
46
void
setMousePosition
(glm::vec2 position);
47
48
/**
49
* @brief Sets the "position" of the scrollwheel - essentially, how much it has moved since the last frame
50
* @param position The distance it has moved since last update.
51
*/
52
void
setMouseScrollwheelPosition
(
int
position);
53
54
/**
55
* @brief Checks if the key is down at all
56
* @param keyID The SDL-given ID to check against
57
* @return true if the key is down
58
*/
59
bool
isKeyDown
(
unsigned
int
keyID)
const
;
60
61
/**
62
* @brief Checks if the key has just been pressed
63
* @param keyID The SDL-given ID to check against
64
* @return true if the key wasn't down last frame and is this frame. false otherwise
65
*/
66
bool
isKeyPressed
(
unsigned
int
keyID)
const
;
67
68
/**
69
* @brief Gets entered character (This just follows the first character that has been pressed this update)
70
* @param alpha If true, checks alphabetical characters
71
* @param nums If true, checks numbers
72
* @param symbols If true, checks all other (readable) symbols
73
* @return The character pressed.
74
*/
75
char
getPressedCharacter
(
bool
alpha =
true
,
bool
nums =
true
,
bool
all =
true
)
const
;
76
77
/**
78
* @brief Gets the position of the mouse in the window
79
* @return The position of the mouse in a glm::vec2
80
*/
81
glm::vec2
getMousePosition
()
const
;
82
83
/**
84
* @brief Gets the position of the mousewheel
85
* @return How much the mousewheel has moved since last update.
86
*/
87
int
getMouseScrollwheelPosition
()
const
;
88
89
private
:
90
/**
91
* @brief Checks if the key was down last frame
92
* @param keyID The SDL-given ID to check against
93
* @return true if the key was down last frame, false otherwise.
94
*/
95
bool
wasKeyDown
(
unsigned
int
keyID)
const
;
96
97
std::unordered_map<unsigned int, bool>
m_keyMap
;
98
std::unordered_map<unsigned int, bool>
m_previousKeyMap
;
99
glm::vec2
m_mousePosition
;
100
int
m_mouseScrollwheelPosition
= 0;
101
};
102
103
}
// namespace BARE2D
BARE2D
Definition:
App.cpp:13
BARE2D::InputManager::update
void update()
Updates the inputmanager. Should be called every frame.
Definition:
InputManager.cpp:13
BARE2D::InputManager::~InputManager
~InputManager()
Definition:
InputManager.cpp:10
BARE2D::InputManager::wasKeyDown
bool wasKeyDown(unsigned int keyID) const
Checks if the key was down last frame.
Definition:
InputManager.cpp:125
BARE2D::InputManager::InputManager
InputManager()
Definition:
InputManager.cpp:7
BARE2D::InputManager::getPressedCharacter
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)
Definition:
InputManager.cpp:76
BARE2D::InputManager::m_previousKeyMap
std::unordered_map< unsigned int, bool > m_previousKeyMap
Definition:
InputManager.hpp:98
BARE2D::InputManager::pressKey
void pressKey(unsigned int keyID)
Sets a key as 'pressed'.
Definition:
InputManager.cpp:25
BARE2D::InputManager::getMouseScrollwheelPosition
int getMouseScrollwheelPosition() const
Gets the position of the mousewheel.
Definition:
InputManager.cpp:120
BARE2D::InputManager::getMousePosition
glm::vec2 getMousePosition() const
Gets the position of the mouse in the window.
Definition:
InputManager.cpp:115
BARE2D::InputManager::m_keyMap
std::unordered_map< unsigned int, bool > m_keyMap
Definition:
InputManager.hpp:97
BARE2D::InputManager::isKeyDown
bool isKeyDown(unsigned int keyID) const
Checks if the key is down at all.
Definition:
InputManager.cpp:53
BARE2D::InputManager::m_mousePosition
glm::vec2 m_mousePosition
Definition:
InputManager.hpp:99
BARE2D::InputManager::m_mouseScrollwheelPosition
int m_mouseScrollwheelPosition
Definition:
InputManager.hpp:100
BARE2D::InputManager
This is the input manager. It does what you expect! Nearly completely copied from GLEngine,...
Definition:
InputManager.hpp:12
BARE2D::InputManager::releaseKey
void releaseKey(unsigned int keyID)
Sets a key as 'released'.
Definition:
InputManager.cpp:31
BARE2D::InputManager::isKeyPressed
bool isKeyPressed(unsigned int keyID) const
Checks if the key has just been pressed.
Definition:
InputManager.cpp:70
BARE2D::InputManager::setMousePosition
void setMousePosition(float x, float y)
Sets the mouse position to (x,y)
Definition:
InputManager.cpp:37
BARE2D::InputManager::setMouseScrollwheelPosition
void setMouseScrollwheelPosition(int position)
Sets the "position" of the scrollwheel - essentially, how much it has moved since the last frame.
Definition:
InputManager.cpp:48
Source
InputManager.hpp
Generated by
1.8.17