el h / SimpleGUI

Fork of SimpleGUI by Duncan McIntyre

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EventHandler.h Source File

EventHandler.h

00001 #ifndef SIMPLEGUI_EVENT_HANDLER_H
00002 #define SIMPLEGUI_EVENT_HANDLER_H
00003 
00004 #include "Event.h"
00005 #include "EventHandlerFunction.h"
00006 
00007 class EventHandler {
00008     
00009     public:
00010 
00011     EventHandler(EventType eventType, EventHandlerFunction fn) : type(eventType)
00012     {
00013         _fp.attach(fn);
00014     }
00015     
00016     
00017     template<typename T>
00018     EventHandler(EventType eventType, T* tptr, void (T::*mptr)(Event)) : type(eventType)
00019     {
00020         _fp.attach(tptr, mptr);
00021     }
00022     
00023     void handle(Event e) {
00024         _fp.call(e);
00025     }
00026     
00027     EventType type;
00028     FunctionPointerArg1<void,Event> _fp;
00029 };
00030 
00031 class EventHandlerList {
00032     
00033     public:
00034     
00035     EventHandlerList(EventHandler* eventHandler) : handler(eventHandler), next(NULL), prev(NULL)
00036     {
00037     }
00038     
00039     EventHandler *handler;
00040     EventHandlerList *next;
00041     EventHandlerList *prev;
00042 
00043 };
00044 
00045 #endif