2018-09-04 19:25:54 +00:00
|
|
|
#include "InputManager.h"
|
|
|
|
|
2018-09-07 03:22:40 +00:00
|
|
|
InputManager::InputManager() {}
|
2018-09-04 19:25:54 +00:00
|
|
|
|
|
|
|
|
2018-09-07 03:22:40 +00:00
|
|
|
InputManager::~InputManager() {}
|
2018-09-04 19:25:54 +00:00
|
|
|
|
|
|
|
void InputManager::mark()
|
|
|
|
{
|
|
|
|
m_keys_pressed.clear();
|
|
|
|
m_mouse_delta = { 0, 0 };
|
|
|
|
m_scroll_distance = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
void InputManager::key_down(KeyCode key_code)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
if (!m_keys_down[key_code])
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
m_keys_down[key_code] = true;
|
|
|
|
m_keys_pressed[key_code] = true;
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
void InputManager::key_up(KeyCode key_code)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
m_keys_down[key_code] = false;
|
|
|
|
m_keys_pressed[key_code] = false;
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputManager::mouse_move(const ivec2& position)
|
|
|
|
{
|
|
|
|
m_mouse_delta += position - m_mouse_position;
|
|
|
|
m_mouse_position = position;
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
void InputManager::mouse_scroll(int distance)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
|
|
|
m_scroll_distance += distance;
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
bool InputManager::is_key_down(KeyCode key_code)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
return m_keys_down[key_code];
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
bool InputManager::is_key_pressed(KeyCode key_code)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
auto iter = m_keys_pressed.find(key_code);
|
2018-09-04 19:25:54 +00:00
|
|
|
if (iter == m_keys_pressed.end())
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
bool InputManager::is_key_released(KeyCode key_code)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
auto iter = m_keys_pressed.find(key_code);
|
2018-09-04 19:25:54 +00:00
|
|
|
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;
|
|
|
|
}
|