62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include <GL/glew.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
enum class Input {
|
|
Forward, Backward, Left, Right, Up, Down,
|
|
Mouse, Debug
|
|
};
|
|
enum class Mouse {
|
|
Left = GLFW_MOUSE_BUTTON_LEFT,
|
|
Right = GLFW_MOUSE_BUTTON_RIGHT
|
|
};
|
|
|
|
/// Handle inputs with name to key mapping table
|
|
class InputMap {
|
|
public:
|
|
InputMap(GLFWwindow*);
|
|
InputMap(InputMap &&) = default;
|
|
InputMap(const InputMap &) = default;
|
|
InputMap &operator=(InputMap &&) = default;
|
|
InputMap &operator=(const InputMap &) = default;
|
|
~InputMap();
|
|
|
|
void saveKeys();
|
|
|
|
bool isDown(Input input) const;
|
|
bool wasDown(Input input) const;
|
|
bool isPressing(Input input) const;
|
|
bool isReleasing(Input input) const;
|
|
|
|
void toggle(bool &val, Input input) const;
|
|
|
|
bool isDown(Mouse input) const;
|
|
bool wasDown(Mouse input) const;
|
|
bool isPressing(Mouse input) const;
|
|
bool isReleasing(Mouse input) const;
|
|
|
|
private:
|
|
GLFWwindow *window;
|
|
std::unordered_map<Input, int> Map = {
|
|
{Input::Forward, GLFW_KEY_W},
|
|
{Input::Backward, GLFW_KEY_S},
|
|
{Input::Left, GLFW_KEY_A},
|
|
{Input::Right, GLFW_KEY_D},
|
|
{Input::Up, GLFW_KEY_SPACE},
|
|
{Input::Down, GLFW_KEY_LEFT_SHIFT},
|
|
{Input::Mouse, GLFW_KEY_E},
|
|
{Input::Debug, GLFW_KEY_F3},
|
|
};
|
|
const std::vector<Input> Toggles = {
|
|
Input::Mouse, Input::Debug
|
|
};
|
|
std::unordered_map<Input, bool> Previous;
|
|
|
|
bool PreviousLeft;
|
|
bool PreviousRight;
|
|
};
|