charcoal/OpenGLEngine/InputManager.h

90 lines
1.9 KiB
C
Raw Normal View History

2018-09-04 19:25:54 +00:00
#pragma once
#include <map>
#include "vec2.h"
//Define the Virtual Keys for the numbers & letters
#define K_0 0x30
#define K_1 0x31
#define K_2 0x32
#define K_3 0x33
#define K_4 0x34
#define K_5 0x35
#define K_6 0x36
#define K_7 0x37
#define K_8 0x38
#define K_9 0x39
#define K_A 0x41
#define K_B 0x42
#define K_C 0x43
#define K_D 0x44
#define K_E 0x45
#define K_F 0x46
#define K_G 0x47
#define K_H 0x48
#define K_I 0x49
#define K_J 0x4a
#define K_K 0x4b
#define K_L 0x4c
#define K_M 0x4d
#define K_N 0x4e
#define K_O 0x4f
#define K_P 0x50
#define K_Q 0x51
#define K_R 0x52
#define K_S 0x53
#define K_T 0x54
#define K_U 0x55
#define K_V 0x56
#define K_W 0x57
#define K_X 0x58
#define K_Y 0x59
#define K_Z 0x5A
using namespace egm;
class InputManager
{
public:
InputManager();
~InputManager();
//Should be called after each frame to reset the keysPressed
void mark();
void key_down(const unsigned long& keyCode);
void key_up(const unsigned long& keyCode);
void mouse_move(const ivec2& position);
void mouse_scroll(const unsigned int& distance);
bool is_key_down(const unsigned long& keyCode);
bool is_key_pressed(const unsigned long& keyCode);
bool is_key_released(const unsigned long& keyCode);
const ivec2& get_mouse_position();
const ivec2& get_mouse_delta();
const int& get_scroll_distance();
private:
//Keys pressed since the last frame
//The existance of a value in this array means that the key has changed to that state
//since the last mark() call.
//A value of true means the key was pressed, false means the value was released
std::map<unsigned long, bool> m_keys_pressed;
//Keys that are down
std::map<unsigned long, bool> m_keys_down;
//Current Mouse Position
ivec2 m_mouse_position;
//Change in mouse position since last mark() call
ivec2 m_mouse_delta;
//The change in scroll (mouse wheel) sinc ethe last mark() call
int m_scroll_distance;
//TODO: Controller Movement
};