43 lines
1.0 KiB
C++

#pragma once
// Must be the first include
#include <glad/glad.h>
// Other includes
#include <GLFW/glfw3.h>
#include "RenderBackend.h"
#include <map>
namespace Gedeng {
class Input {
public:
static void initialize(GLFWwindow *window) {
glfwSetKeyCallback(window, key_callback);
}
// FIXME: Ignore warnings produced by these unused variables -- they're required for the callback to work:
// https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE);
Input::set_key_down(key, action == GLFW_RELEASE ? false : true);
}
static void poll_input() {
glfwPollEvents();
}
static void set_key_down(int key, bool down) {
keys_down[key] = down;
}
static bool is_key_down(int key) {
return keys_down[key];
}
inline static std::map<int, bool> keys_down;
};
} // namespace Gedeng