Organize stuffs

This commit is contained in:
Sebastian Cabrera 2025-08-09 21:22:44 -04:00
parent a9240cac6e
commit c120871293
Signed by: okseby
GPG key ID: 2DDBFDEE356CF3DE
13 changed files with 625 additions and 56 deletions

48
src/events/EventManager.h Normal file
View 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);
};