96 lines
1.9 KiB
C++
96 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
// Define the Windows 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
|
|
|
|
namespace charcoal
|
|
{
|
|
using namespace glm;
|
|
|
|
class InputManager
|
|
{
|
|
public:
|
|
typedef int KeyCode;
|
|
|
|
InputManager();
|
|
virtual ~InputManager();
|
|
|
|
//Should be called after each frame to reset the keysPressed
|
|
void mark();
|
|
|
|
bool is_key_down(KeyCode key_code) const;
|
|
bool is_key_pressed(KeyCode key_code) const;
|
|
bool is_key_released(KeyCode key_code) const;
|
|
const ivec2& get_mouse_position() const;
|
|
const ivec2& get_mouse_delta() const;
|
|
const int& get_scroll_distance() const;
|
|
|
|
protected:
|
|
void key_down(KeyCode key_code);
|
|
void key_up(KeyCode key_code);
|
|
void mouse_move(const ivec2& position);
|
|
void mouse_scroll(int 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<KeyCode, bool> m_keys_pressed;
|
|
|
|
//Keys that are down
|
|
std::map<KeyCode, 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) since the last mark() call
|
|
int m_scroll_distance;
|
|
|
|
//TODO: Controller Movement
|
|
};
|
|
} |