-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeyboard.hpp
More file actions
50 lines (42 loc) · 1.19 KB
/
Keyboard.hpp
File metadata and controls
50 lines (42 loc) · 1.19 KB
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
#pragma once
#include "GLAD/glad.h"
#include "GLGlobals.hpp"
#include <vector>
#include <functional>
#include <utility>
// TODO: rework this garbage.
namespace Keyboard
{
inline std::vector<std::pair<int, std::function<void()>>> Callbacks;
inline void AddKeyboardEvent(int Key, std::function<void()> Callback)
{
Callbacks.emplace_back(std::pair<int, std::function<void()>> { Key, Callback });
}
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
if (key == GLFW_KEY_F1 && action == GLFW_PRESS)
{
static bool IsOn = false;
if (!IsOn)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
else
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
IsOn = !IsOn;
}
for (auto&& Callback : Callbacks)
{
if (glfwGetKey(window, Callback.first) == GLFW_PRESS)
{
Callback.second();
}
}
}
}