Organize stuffs
This commit is contained in:
parent
a9240cac6e
commit
c120871293
13 changed files with 625 additions and 56 deletions
48
src/events/EventManager.h
Normal file
48
src/events/EventManager.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include "../core/Common.h"
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
enum class EventType {
|
||||
Quit,
|
||||
KeyDown,
|
||||
KeyUp,
|
||||
MouseMove,
|
||||
MouseButtonDown,
|
||||
MouseButtonUp,
|
||||
WindowEvent
|
||||
};
|
||||
|
||||
struct EventData {
|
||||
EventType type;
|
||||
SDL_Event sdlEvent;
|
||||
};
|
||||
|
||||
class EventManager {
|
||||
public:
|
||||
EventManager();
|
||||
~EventManager() = default;
|
||||
|
||||
// Event handling
|
||||
bool pollEvents();
|
||||
bool isRunning() const { return running_; }
|
||||
void stop() { running_ = false; }
|
||||
|
||||
// Event callbacks
|
||||
using EventCallback = std::function<void(const EventData&)>;
|
||||
void registerCallback(EventType type, EventCallback callback);
|
||||
void unregisterCallback(EventType type);
|
||||
|
||||
// Event processing
|
||||
void processEvent(const SDL_Event& event);
|
||||
|
||||
private:
|
||||
bool running_;
|
||||
std::unordered_map<EventType, EventCallback> callbacks_;
|
||||
|
||||
void handleQuitEvent();
|
||||
void handleKeyEvent(const SDL_Event& event);
|
||||
void handleMouseEvent(const SDL_Event& event);
|
||||
void handleWindowEvent(const SDL_Event& event);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue