jubilant-funicular
InputManager.h
1 #ifndef NTA_INPUTMANAGER_H_INCLUDED
2 #define NTA_INPUTMANAGER_H_INCLUDED
3 
4 #include <glm/glm.hpp>
5 #include <SDL2/SDL.h>
6 #include <unordered_map>
7 
8 namespace nta {
9  class ScreenManager;
12  friend class ScreenManager;
16  };
18  enum MouseWheelMotion{STATIONARY = 0, SCROLL_UP = 1, SCROLL_DOWN = -1};
20  class InputManager {
21  public:
22  using key_type = unsigned int;
23  private:
25  std::unordered_map<key_type, bool> m_keyMap;
27  std::unordered_map<key_type, bool> m_prevKeyMap;
29  glm::vec2 m_mouseCoords;
32  public:
35  glm::vec2 getMouseCoords() const;
37  glm::vec2 getMouseCoordsStandard(int height) const;
41  bool isPressed(key_type key) const;
43  bool justPressed(key_type key) const;
45  bool justReleased(key_type key) const;
47  void pressKey(key_type key);
49  void releaseKey(key_type key);
51  void setMouseCoords(float x, float y);
53  void setMouseWheelMotion(const MouseWheelMotion& motion);
55  void update(SDL_Event& event);
57  void update_keys(SDL_Event& event);
59  void update_mouse(SDL_Event& event);
61  void updatePrev();
62  };
63 }
64 
65 #endif // NTA_INPUTMANAGER_H_INCLUDED
nta::InputManager::m_mouseWheelMotion
MouseWheelMotion m_mouseWheelMotion
stores the motion of the mouse wheel
Definition: InputManager.h:31
nta::InputManager::getMouseCoordsStandard
glm::vec2 getMouseCoordsStandard(int height) const
returns the mouse's coordinates with the y axis flipped (0 represents the bottom of the screen instea...
Definition: InputManager.cpp:7
nta::InputManager::getMouseWheelMotion
MouseWheelMotion getMouseWheelMotion() const
returns the mouse wheel's motion
Definition: InputManager.cpp:10
nta::InputManager::update
void update(SDL_Event &event)
updates internal state
Definition: InputManager.cpp:38
nta::InputManager::update_mouse
void update_mouse(SDL_Event &event)
update mouse information
Definition: InputManager.cpp:48
nta::InputManager::updatePrev
void updatePrev()
updates the state of m_prevKeyMap
Definition: InputManager.cpp:56
nta::InputManager::m_keyMap
std::unordered_map< key_type, bool > m_keyMap
stores whether each key is pressed or not
Definition: InputManager.h:25
nta::InputManager::pressKey
void pressKey(key_type key)
tells InputManager that specified key was pressed
Definition: InputManager.cpp:25
nta::InputManager::getMouseCoords
glm::vec2 getMouseCoords() const
returns the mouse's coordinates
Definition: InputManager.cpp:4
nta
Definition: Animation2D.h:6
nta::InputManager::update_keys
void update_keys(SDL_Event &event)
updates key information
Definition: InputManager.cpp:42
nta::ScreenManager
Definition: ScreenManager.h:16
nta::InputManager::m_mouseCoords
glm::vec2 m_mouseCoords
stores the location of the mouse in mouse coordinates
Definition: InputManager.h:29
nta::MouseWheelMotion
MouseWheelMotion
represents the way a mouse wheel was rolled
Definition: InputManager.h:18
nta::InputManager::setMouseWheelMotion
void setMouseWheelMotion(const MouseWheelMotion &motion)
tells InputManager how the wheel is rolling
Definition: InputManager.cpp:35
nta::CreateInputManagerKey
Key unlocking the InputManager constructor.
Definition: InputManager.h:11
nta::InputManager::justPressed
bool justPressed(key_type key) const
returns whether or not the key was just pressed this frame
Definition: InputManager.cpp:17
nta::InputManager
keeps track of all input
Definition: InputManager.h:20
nta::InputManager::isPressed
bool isPressed(key_type key) const
returns whether or not specified key is pressed
Definition: InputManager.cpp:13
nta::InputManager::justReleased
bool justReleased(key_type key) const
returns whether or not the key was just released this frame
Definition: InputManager.cpp:21
nta::InputManager::releaseKey
void releaseKey(key_type key)
tells InputManager that specified key was released
Definition: InputManager.cpp:28
nta::InputManager::setMouseCoords
void setMouseCoords(float x, float y)
tells InputManager where the mouse is
Definition: InputManager.cpp:31
nta::InputManager::m_prevKeyMap
std::unordered_map< key_type, bool > m_prevKeyMap
stores whether the key was pressed last frame or not
Definition: InputManager.h:27