Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
InputManager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <GLFW/glfw3.h>
4#include <array>
5#include <glm/glm.hpp>
6
7namespace shkyera {
8
10 public:
12
13 using Key = int;
15
16 static InputManager& getInstance();
17
20 void update();
21
22 // Key queries
23 bool isKeyDown(Key key) const; // held this frame
24 bool isKeyUp(Key key) const; // not held this frame
25 bool isKeyPressed(Key key) const; // went down this frame
26 bool isKeyReleased(Key key) const; // went up this frame
27
28 // Mouse button queries
33
34 // Mouse position
38
39 private:
41
42 static constexpr int MAX_KEYS = GLFW_KEY_LAST + 1;
43 static constexpr int MAX_MOUSE_BUTTONS = GLFW_MOUSE_BUTTON_LAST + 1;
44
45 GLFWwindow* _window = nullptr;
46
47 std::array<bool, MAX_KEYS> _currentKeyStates{};
48 std::array<bool, MAX_KEYS> _previousKeyStates{};
49
50 std::array<bool, MAX_MOUSE_BUTTONS> _currentMouseStates{};
51 std::array<bool, MAX_MOUSE_BUTTONS> _previousMouseStates{};
52
53 glm::vec2 _mousePos{0.0f, 0.0f};
54
55 std::unordered_map<CoordinateSystem, std::pair<glm::vec2, glm::vec2>> _coordinateSystems;
56};
57
58} // namespace shkyera
Definition InputManager.hpp:9
std::array< bool, MAX_MOUSE_BUTTONS > _currentMouseStates
Definition InputManager.hpp:50
bool isKeyUp(Key key) const
Definition InputManager.cpp:55
bool isMouseButtonPressed(MouseButton button) const
Definition InputManager.cpp:75
CoordinateSystem
Definition InputManager.hpp:11
std::array< bool, MAX_MOUSE_BUTTONS > _previousMouseStates
Definition InputManager.hpp:51
bool isKeyDown(Key key) const
Definition InputManager.cpp:51
int Key
Definition InputManager.hpp:13
InputManager()
Definition InputManager.cpp:12
GLFWwindow * _window
Definition InputManager.hpp:45
glm::vec2 _mousePos
Definition InputManager.hpp:53
static constexpr int MAX_KEYS
Definition InputManager.hpp:42
void setWindow(GLFWwindow *window)
Definition InputManager.cpp:19
bool isMouseButtonDown(MouseButton button) const
Definition InputManager.cpp:67
std::unordered_map< CoordinateSystem, std::pair< glm::vec2, glm::vec2 > > _coordinateSystems
Definition InputManager.hpp:55
glm::vec2 getMousePosition(CoordinateSystem coordinateSystem) const
Definition InputManager.cpp:83
bool isKeyPressed(Key key) const
Definition InputManager.cpp:59
std::array< bool, MAX_KEYS > _previousKeyStates
Definition InputManager.hpp:48
std::array< bool, MAX_KEYS > _currentKeyStates
Definition InputManager.hpp:47
void setCoordinateSystem(CoordinateSystem system, glm::vec2 topLeftCorner, glm::vec2 bottomRightCorner)
Definition InputManager.cpp:23
static InputManager & getInstance()
Definition InputManager.cpp:7
void update()
Definition InputManager.cpp:27
glm::vec2 getRelativeMousePosition(CoordinateSystem coordinateSystem) const
Definition InputManager.cpp:91
bool isMouseButtonUp(MouseButton button) const
Definition InputManager.cpp:71
int MouseButton
Definition InputManager.hpp:14
bool isMouseInside(CoordinateSystem coordinteSystem) const
Definition InputManager.cpp:99
bool isMouseButtonReleased(MouseButton button) const
Definition InputManager.cpp:79
static constexpr int MAX_MOUSE_BUTTONS
Definition InputManager.hpp:43
bool isKeyReleased(Key key) const
Definition InputManager.cpp:63
Definition Asset.hpp:6
Definition Clock.hpp:9