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