40 lines
741 B
C++
40 lines
741 B
C++
#include "xController.h"
|
|
|
|
xController::xController():
|
|
_handlers()
|
|
{}
|
|
|
|
xController::~xController(){
|
|
_handlers.clear();
|
|
}
|
|
|
|
// called in scheduling
|
|
void xController::handleEvent(SDL_Event* event){
|
|
_mutex.lock();
|
|
|
|
map<SDL_EventType, EventHandler>::iterator found = _handlers.find( (SDL_EventType) event->type );
|
|
|
|
// ignore no handler found
|
|
if( found == _handlers.end() ){
|
|
_mutex.unlock();
|
|
return;
|
|
}
|
|
|
|
(*found->second)(event);
|
|
|
|
_mutex.unlock();
|
|
}
|
|
|
|
// bind a new handler
|
|
void xController::attachEvent(SDL_EventType t, EventHandlerArg){
|
|
_mutex.lock();
|
|
_handlers[ t ] = handler;
|
|
_mutex.unlock();
|
|
}
|
|
|
|
// removes an existing handler
|
|
void xController::detachEvent(SDL_EventType t){
|
|
_mutex.lock();
|
|
_handlers.erase(t);
|
|
_mutex.unlock();
|
|
} |