Untitled Game engine no.5  1.0
Input.hpp
1 #ifndef INPUT_HPP
2 #define INPUT_HPP
3 
4 #include <SDL2/SDL_keycode.h>
5 #include <glm/vec2.hpp>
6 #include <unordered_map>
7 #include "Scene.hpp"
8 
9 namespace Engine {
10 
11  typedef SDL_Keycode KeyCode;
12  typedef uint8_t MouseCode;
13 
14  struct Mouse {};
15 
16  class Input {
17  public:
21  static bool IsKeyPressed(KeyCode key);
25  static bool IsMousePressed(MouseCode button);
26 
29  static glm::vec2 GetMousePos();
32  static float GetMouseX();
35  static float GetMouseY();
36 
38  static Input& Get() {
39  static Input s_Instance;
40  return s_Instance;
41  }
42 
44  static void UpdateKey(KeyCode key, bool state) {
45  keyStates[key] = state;
46  }
47 
49  static void UpdateMouse(MouseCode button, bool state) {
50  mouseStates[button] = state;
51  }
52 
58  static void UpdateMousePos(float x, float y);
59 
65  static void UpdateRelMousePos(float x, float y);
66 
71  static glm::vec2 GetMouseDelta();
72 
77  static void Update(const Scene &s);
78 
83  static void SetMouseLock(bool lock);
84 
89  static bool IsMouseLocked();
90 
91  private:
92  static std::unordered_map<KeyCode, bool> keyStates;
93  static std::unordered_map<MouseCode, bool> mouseStates;
94  static Input* s_Instance;
95  static glm::vec2 mousePos, mousePosOld;
96  };
97 }
98 
99 #endif
Engine::Input::IsMouseLocked
static bool IsMouseLocked()
Definition: SdlInput.cpp:57
Engine::Input::GetMousePos
static glm::vec2 GetMousePos()
Definition: SdlInput.cpp:25
Engine::Scene
A container for entities currently in the Scene.
Definition: Scene.hpp:9
Engine::Input::UpdateKey
static void UpdateKey(KeyCode key, bool state)
update the key at the given keycode with the new state
Definition: Input.hpp:44
Engine::Input::UpdateRelMousePos
static void UpdateRelMousePos(float x, float y)
Definition: SdlInput.cpp:49
Engine::Input::GetMouseX
static float GetMouseX()
Definition: SdlInput.cpp:29
Engine::Mouse
Definition: Input.hpp:14
Engine::Input
Definition: Input.hpp:16
Engine::Input::SetMouseLock
static void SetMouseLock(bool lock)
Definition: SdlInput.cpp:53
Engine::Input::GetMouseY
static float GetMouseY()
Definition: SdlInput.cpp:34
Engine::Input::IsMousePressed
static bool IsMousePressed(MouseCode button)
Definition: SdlInput.cpp:21
Engine::Input::GetMouseDelta
static glm::vec2 GetMouseDelta()
Definition: SdlInput.cpp:61
Engine::Input::Get
static Input & Get()
get the static input instance
Definition: Input.hpp:38
Engine
Definition: Animation.hpp:14
Engine::Input::Update
static void Update(const Scene &s)
Definition: SdlInput.cpp:38
Engine::Input::UpdateMouse
static void UpdateMouse(MouseCode button, bool state)
update the mouse button at the given index with the new state
Definition: Input.hpp:49
Engine::Input::IsKeyPressed
static bool IsKeyPressed(KeyCode key)
Definition: SdlInput.cpp:17
Engine::Input::UpdateMousePos
static void UpdateMousePos(float x, float y)
Definition: SdlInput.cpp:45