#include "GLFWInputManager.h" #include "Exception.h" std::map GLFWInputManager::s_glfw_windows; GLFWInputManager::~GLFWInputManager() { s_glfw_windows.erase(m_p_window); } void GLFWInputManager::init(GLFWwindow* p_window) { if (m_p_window != nullptr) { throw EXCEPTION("GLFWInputManager Already Initialized."); } m_p_window = p_window; s_glfw_windows.insert(std::map::value_type(m_p_window, this)); } void GLFWInputManager::key_callback(GLFWwindow* p_window, int key, int scancode, int action, int mods) { std::map::iterator iter = s_glfw_windows.find(p_window); if (iter == s_glfw_windows.end()) { // Ignore Unknown Windows return; } GLFWInputManager& input_manager = *iter->second; if (action == GLFW_PRESS) { input_manager.key_down(key); } else if (action == GLFW_RELEASE) { input_manager.key_up(key); } else if (action == GLFW_REPEAT) { // Ignored } else { throw Exception("Invalid GLFW Key Action: " + std::to_string(action) + " (" + std::to_string(scancode) + ")", "class GLFWInputManager"); } }