xmario/xSDL/xController.h

33 lines
605 B
C++

#ifndef DEF_XCONTROLLER_H
#define DEF_XCONTROLLER_H
#include "SDL.h"
#include <mutex>
#include <map>
using namespace std;
#define EventHandlerArg void(* handler)(SDL_Event*)
#define EventHandler void(*)(SDL_Event*)
class xController{
public:
xController();
~xController();
// called in scheduling
void handleEvent(SDL_Event* event);
// manage handlers
void attachEvent(SDL_EventType t, EventHandlerArg);
void detachEvent(SDL_EventType t);
private:
// event handlers
map<SDL_EventType, EventHandler> _handlers;
// thread safety
mutex _mutex;
};
#endif