-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow_Inputs.hpp
97 lines (78 loc) · 2.21 KB
/
Window_Inputs.hpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef WINDOW_INPUTS_H
#define WINDOW_INPUTS_H
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <map>
#include <functional>
#include <string>
#include "Util.hpp"
typedef std::function<void()> void_func;
static const void_func NOPfunc = ([](){});
static bool window_gained_focus_;
static bool window_lost_focus_;
struct Key_Input {
const int key;
const int action;
Key_Input(const int& key, const int& action) :
key(key), action(action) {
}
};
class Input {
private:
static const int NOP = -1;
int action;
public:
void_func pressed_func;
void_func released_func;
void_func repeated_func;
Input();
void setAction(const int action_in);
void doAction();
};
class Window_Inputs {
private:
v2 cursor_pos;
GLFWwindow* window;
std::map<int, Input> keymap;
public:
Window_Inputs();
GLFWwindow* init_window(std::string window_name="Sick window name here", int x=1920, int y=1080);
GLFWwindow* getWindow();
v2 windowSize();
// reading from this resets the static bool
bool window_gained_focus();
bool window_lost_focus();
void toggle_cursor();
void disable_cursor();
void enable_cursor();
bool cursor_disabled;
void swapBuffers();
void processInput();
v2 cursorDelta();
template <typename F>
void setFunc(int key, int action, F f) {
switch (action) {
case GLFW_PRESS:
keymap[key].pressed_func = f;
break;
case GLFW_REPEAT:
keymap[key].repeated_func = f;
break;
case GLFW_RELEASE:
keymap[key].released_func = f;
break;
}
}
template <typename F>
void setFunc1(int key, F f) {
setFunc(key,GLFW_PRESS,f);
}
// sets to REPEAT for as long as you hold key
template <typename F>
void setFunc2(int key, F f) {
setFunc(key,GLFW_PRESS,f);
setFunc(key,GLFW_REPEAT,f);
}
void close();
};
#endif