-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.cpp
50 lines (42 loc) · 858 Bytes
/
input.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "headers/input.h"
bool Input::mKeys[1024];
bool Input::mKeysOnce[1024];
//Input* Input::mInstance;
Input::Input()
{
}
Input::~Input()
{
//delete mInstance;
}
void Input::CreateInstance()
{
//mInstance = new Input();
glfwSetKeyCallback(Window::GetWindow()->GetGLFWWindow(), Key_Callback);
}
bool Input::IsKeyPressedOnce(int _key)
{
if(mKeysOnce[_key])
{
bool retVal = mKeysOnce[_key];
mKeysOnce[_key] = false;
return retVal;
}
else return false;
}
bool Input::IsKeyPressed(int _key)
{
return mKeys[_key];
}
void Input::Key_Callback(GLFWwindow* _window, int _key, int _scancode, int _action, int _mods)
{
if(_action == GLFW_PRESS)
{
mKeys[_key] = true;
mKeysOnce[_key] = true;
}
else if(_action == GLFW_RELEASE)
{
mKeys[_key] = false;
}
}