xmario/xSDL/xController.cpp

40 lines
741 B
C++
Raw Normal View History

#include "xController.h"
xController::xController():
_handlers()
{}
xController::~xController(){
_handlers.clear();
}
// called in scheduling
void xController::handleEvent(SDL_Event* event){
_mutex.lock();
2019-11-06 21:48:47 +00:00
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
2019-11-06 21:48:47 +00:00
void xController::attachEvent(SDL_EventType t, EventHandlerArg){
_mutex.lock();
_handlers[ t ] = handler;
_mutex.unlock();
}
// removes an existing handler
2019-11-06 21:48:47 +00:00
void xController::detachEvent(SDL_EventType t){
_mutex.lock();
_handlers.erase(t);
_mutex.unlock();
}