|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include "glm/vec2.hpp"
|
|
|
|
|
|
|
|
class Listener;
|
|
|
|
|
|
|
|
class MouseListener;
|
|
|
|
|
|
|
|
class Input {
|
|
|
|
friend Listener;
|
|
|
|
friend MouseListener;
|
|
|
|
public:
|
|
|
|
explicit Input(GLFWwindow *window);
|
|
|
|
static Input *instance;
|
|
|
|
static std::map<int, bool> KeyIsDown;
|
|
|
|
static std::map<int, bool> MouseButtonIsDown;
|
|
|
|
glm::vec2 currentCursorPosition {};
|
|
|
|
private:
|
|
|
|
GLFWwindow *window;
|
|
|
|
std::set<Listener *> listeners;
|
|
|
|
|
|
|
|
void keyPressed(int key);
|
|
|
|
void keyReleased(int key);
|
|
|
|
|
|
|
|
void mouseButtonPressed(int button);
|
|
|
|
void mouseButtonReleased(int button);
|
|
|
|
void mouseMoved(const glm::vec2 &newCursorPosition);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Listener {
|
|
|
|
public:
|
|
|
|
Listener();
|
|
|
|
virtual ~Listener();
|
|
|
|
};
|
|
|
|
|
|
|
|
class KeyListener : Listener {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class MouseListener : public Listener {
|
|
|
|
public:
|
|
|
|
virtual void mouseMoved(const glm::vec2 &delta) {};
|
|
|
|
|
|
|
|
virtual void mouseButtonPressed(int button) {};
|
|
|
|
|
|
|
|
virtual void mouseButtonReleased(int button) {};
|
|
|
|
};
|