charcoal/OpenGLEngine/InputManager.cpp
2018-09-04 15:25:54 -04:00

81 lines
1.4 KiB
C++

#include "InputManager.h"
InputManager::InputManager()
{
}
InputManager::~InputManager()
{
}
void InputManager::mark()
{
m_keys_pressed.clear();
m_mouse_delta = { 0, 0 };
m_scroll_distance = 0;
}
void InputManager::key_down(const unsigned long& keyCode)
{
if (!m_keys_down[keyCode])
{
m_keys_down[keyCode] = true;
m_keys_pressed[keyCode] = true;
}
}
void InputManager::key_up(const unsigned long& keyCode)
{
m_keys_down[keyCode] = false;
m_keys_pressed[keyCode] = false;
}
void InputManager::mouse_move(const ivec2& position)
{
m_mouse_delta += position - m_mouse_position;
m_mouse_position = position;
}
void InputManager::mouse_scroll(const unsigned int& distance)
{
m_scroll_distance += distance;
}
bool InputManager::is_key_down(const unsigned long& keyCode)
{
return m_keys_down[keyCode];
}
bool InputManager::is_key_pressed(const unsigned long& keyCode)
{
auto iter = m_keys_pressed.find(keyCode);
if (iter == m_keys_pressed.end())
return false;
else
return iter->second;
}
bool InputManager::is_key_released(const unsigned long& keyCode)
{
auto iter = m_keys_pressed.find(keyCode);
if (iter == m_keys_pressed.end())
return false;
else
return !iter->second;
}
const ivec2& InputManager::get_mouse_position()
{
return m_mouse_position;
}
const ivec2& InputManager::get_mouse_delta()
{
return m_mouse_delta;
}
const int& InputManager::get_scroll_distance()
{
return m_scroll_distance;
}