charcoal/OpenGLEngine/GLFWInputManager.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

#include "GLFWInputManager.h"
#include "Exception.h"
2018-09-12 21:03:46 +00:00
namespace charcoal
{
2018-09-12 21:03:46 +00:00
std::map<GLFWwindow*, GLFWInputManager*> GLFWInputManager::s_glfw_windows;
2018-09-12 21:03:46 +00:00
GLFWInputManager::~GLFWInputManager()
{
s_glfw_windows.erase(m_p_window);
}
2018-09-12 21:03:46 +00:00
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<GLFWwindow*, GLFWInputManager*>::value_type(m_p_window, this));
}
void GLFWInputManager::key_callback(GLFWwindow* p_window, int key, int scancode, int action, int mods)
{
std::map<GLFWwindow*, GLFWInputManager*>::iterator iter = s_glfw_windows.find(p_window);
if (iter == s_glfw_windows.end())
return; // Ignore Unknown Windows
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) + ")");
}
}