charcoal/OpenGLEngine/GLFWInputManager.cpp
elipzer a8c4b05d2f It Works! A triangle renders on the screen.
This commit gets creates the ObjectOriented scene and gets it
working.

The current test program swaps a triangle from small to large with
the 1 and 2 keys on the keyboard. (1 for small and 2 for large).

The small triangle is rendered by the simple scene and the large
one is rendered by the object oriented one.
2018-09-05 19:10:38 -04:00

49 lines
1.1 KiB
C++

#include "GLFWInputManager.h"
#include "Exception.h"
std::map<GLFWwindow*, GLFWInputManager*> 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<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())
{
// 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");
}
}