Raftel Engine
 
Loading...
Searching...
No Matches
input.hpp
1#ifndef __INPUT_H__
2#define __INPUT_H__ 1
3
4#pragma once
5
6#include <unordered_map>
7#include <raftel/global_macros.hpp>
8#include <glm/vec2.hpp>
9
10struct GLFWwindow;
11
12namespace Raftel {
13
17 class Input {
18 public:
29
33 enum class Keys {
34 Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P,
35 Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L,
36 Key_Z, Key_X, Key_C, Key_V, Key_B, Key_N, Key_M,
37
38 Key_Space, Key_Escape, Key_Enter, Key_Tab, Key_Backspace, Key_Delete,
39 Key_Left, Key_Right, Key_Up, Key_Down, Key_Control, Key_Alt, Key_Shift,
40 Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0,
41
43 };
44
48 struct KeyInfo {
50 bool up = true;
51 bool down = false;
52 bool this_frame = false;
54 };
55
59 struct ButtonInfo {
61 bool up = true;
62 bool down = false;
63 bool this_frame = false;
65 };
66
71 Input(GLFWwindow* window);
72
77
78 friend void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
79 friend void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
80 friend void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
81
87 bool isKeyPressed(Keys key);
88
94 bool isKeyRelease(Keys key);
95
101 bool isKeyDown(Keys key) const;
102
108 bool isKeyUp(Keys key) const;
109
116
123
129 bool isMouseButtonDown(Buttons button) const;
130
136 bool isMouseButtonUp(Buttons button) const;
137
142 glm::vec2 getScrollDelta();
143
148
153
158 glm::vec2 getMouseDelta();
159
164 glm::vec2 getMousePosition();
165
170
171 private:
172 glm::vec2 scrollDelta;
173 glm::vec2 lastScrollOffset;
174
175 GLFWwindow* window_;
176
177 glm::vec2 lastMousePosition;
178 bool firstMouseMove = true;
179
183 void assignKeys();
184
188 void assignButtons();
189
190 std::unordered_map<int, KeyInfo> input_map;
191 std::unordered_map<int, ButtonInfo> button_map;
192
193 MOVABLE_BUT_NOT_COPYABLE(Input);
194 };
195
196} // namespace Raftel
197
198#endif
void resetMouseTracking()
Resets mouse movement tracking data.
bool isMouseButtonPressed(Buttons button)
Checks if a mouse button is currently pressed.
glm::vec2 getMouseDelta()
Retrieves the mouse movement delta.
void resetScrollTracking()
Resets scroll tracking data.
glm::vec2 getScrollDelta()
Retrieves the scroll delta from the last input frame.
glm::vec2 getMousePosition()
Retrieves the current mouse position.
Keys
Enumeration of keyboard keys.
Definition input.hpp:33
Input(GLFWwindow *window)
Constructs an Input object.
bool isKeyDown(Keys key) const
Checks if a key is currently held down.
bool isMouseButtonRelease(Buttons button)
Checks if a mouse button was just released.
bool isKeyRelease(Keys key)
Checks if a key was just released.
bool isKeyPressed(Keys key)
Checks if a key is currently pressed.
void updateKeys()
Updates the key states for the current frame.
bool isMouseButtonDown(Buttons button) const
Checks if a mouse button is currently held down.
Buttons
Enumeration of mouse buttons.
Definition input.hpp:22
~Input()
Destructor for Input.
bool isKeyUp(Keys key) const
Checks if a key is currently up.
bool isMouseButtonUp(Buttons button) const
Checks if a mouse button is currently up.
Stores information about a mouse button's state.
Definition input.hpp:59
Stores information about a key's state.
Definition input.hpp:48