roguelike/src/core/input.h
2025-06-04 21:59:22 +02:00

35 lines
810 B
C++

#ifndef ROGUE_INPUT_H
#define ROGUE_INPUT_H
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_scancode.h>
#include <functional>
#include <set>
namespace rogue {
struct InputHandler {
InputHandler();
virtual ~InputHandler();
virtual void process_event(SDL_Event event) = 0;
};
struct KeyEventHandler : public InputHandler {
typedef std::function<void(bool down)> Listener;
KeyEventHandler(std::set<SDL_Scancode> code, Listener listener);
virtual void process_event(SDL_Event event) override;
std::set<SDL_Scancode> scancode{};
Listener listener{};
};
class Input {
public:
static void add_handler(InputHandler *handler);
static void remove_handler(InputHandler *handler);
static void process_event(SDL_Event event);
private:
static std::set<InputHandler*> handlers;
};
}
#endif // !ROGUE_INPUT_H