-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.cpp
More file actions
34 lines (27 loc) · 861 Bytes
/
Input.cpp
File metadata and controls
34 lines (27 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "precomp.h"
#include "Input.h"
uint* Input::keystates = nullptr;
bool Input::IsKeyDown(uint keycode) {
return keystates[keycode] == GLFW_PRESS;
}
bool Input::IsKeyDown(KeyCode keycode) {
return keystates[static_cast<uint>(keycode)] == GLFW_PRESS;
}
KeyCode Input::GetKeyDown() {
for (int key = 0; key < GLFW_KEY_LAST; key++) {
if (keystates[key] != GLFW_RELEASE) {
return static_cast<KeyCode>(key);
}
}
return static_cast<KeyCode>(GLFW_KEY_UNKNOWN);
}
bool Input::IsAlpha(KeyCode keycode) {
return keycode >= KeyCode::A && keycode <= KeyCode::Z;
}
bool Input::IsDigid(KeyCode keycode) {
return keycode >= KeyCode::Num0 && keycode <= KeyCode::Num9;
}
char Input::ToChar(KeyCode keycode) {
ASSERT(IsAlpha(keycode) || IsDigid(keycode), "Keycode must be alpha or digid to convert it to char\n");
return static_cast<char>(keycode);
}