summaryrefslogtreecommitdiffstats
path: root/src/control/InputHandler.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/control/InputHandler.hpp')
-rw-r--r--src/control/InputHandler.hpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/control/InputHandler.hpp b/src/control/InputHandler.hpp
index eba94d1..1a34982 100644
--- a/src/control/InputHandler.hpp
+++ b/src/control/InputHandler.hpp
@@ -26,10 +26,10 @@
#pragma once
-#include <SDL.h>
-
#include <cstdint>
+#include <functional>
#include <unordered_set>
+#include <vector>
namespace RPGEdit {
@@ -37,34 +37,35 @@ namespace RPGEdit {
namespace Control {
class InputHandler {
+public:
+ typedef std::function<void (uint16_t, bool, uint64_t)> Listener;
+
private:
+ std::vector<Listener> listeners;
+
std::unordered_set<uint16_t> pressedKeys;
- std::unordered_set<uint16_t> unhandledKeys;
public:
- void keyPressed(SDL_Scancode key) {
- pressedKeys.insert(key);
- unhandledKeys.insert(key);
+ void registerListener(const Listener &listener) {
+ listeners.push_back(listener);
}
- void keyReleased(SDL_Scancode key) {
- pressedKeys.erase(key);
- }
+ void keyPressed(uint16_t key, uint64_t time) {
+ pressedKeys.insert(key);
- void keyHandled(SDL_Scancode key) {
- unhandledKeys.erase(key);
+ for (auto &listener : listeners)
+ listener(key, true, time);
}
- void resetHandled() {
- unhandledKeys.clear();
- }
+ void keyReleased(uint16_t key, uint64_t time) {
+ pressedKeys.erase(key);
- bool isKeyPressed(SDL_Scancode key) {
- return pressedKeys.count(key);
+ for (auto &listener : listeners)
+ listener(key, false, time);
}
- bool isKeyUnhandled(SDL_Scancode key) {
- return unhandledKeys.count(key);
+ bool isKeyPressed(uint16_t key) {
+ return pressedKeys.count(key);
}
};