root / trunk / tbeta / Windows / libs / openFrameworks / events / ofEventUtils.h @ 139
View | Annotate | Download (2.2 KB)
| 1 | 139 | ss | #include "ofConstants.h" |
|---|---|---|---|
| 2 | 139 | ss | |
| 3 | 139 | ss | #ifdef OF_USING_POCO
|
| 4 | 139 | ss | |
| 5 | 139 | ss | #include "Poco/FIFOEvent.h" |
| 6 | 139 | ss | #include "Poco/Delegate.h" |
| 7 | 139 | ss | |
| 8 | 139 | ss | using Poco::delegate; |
| 9 | 139 | ss | |
| 10 | 139 | ss | |
| 11 | 139 | ss | //-----------------------------------------
|
| 12 | 139 | ss | // define ofEvent as a poco FIFOEvent
|
| 13 | 139 | ss | // to create your own events use:
|
| 14 | 139 | ss | // ofEvent<argType> myEvent
|
| 15 | 139 | ss | |
| 16 | 139 | ss | template <typename ArgumentsType> |
| 17 | 139 | ss | class ofEvent: public Poco::FIFOEvent<ArgumentsType> {};
|
| 18 | 139 | ss | |
| 19 | 139 | ss | |
| 20 | 139 | ss | |
| 21 | 139 | ss | //----------------------------------------------------
|
| 22 | 139 | ss | // register any method of any class to an event.
|
| 23 | 139 | ss | // the method must provide one of the following
|
| 24 | 139 | ss | // signatures:
|
| 25 | 139 | ss | // void method(ArgumentsType & args)
|
| 26 | 139 | ss | // void method(const void * sender, ArgumentsType &args)
|
| 27 | 139 | ss | // ie:
|
| 28 | 139 | ss | // ofAddListener(addon.newIntEvent, this, &Class::method)
|
| 29 | 139 | ss | |
| 30 | 139 | ss | template <class EventType,typename ArgumentsType, class ListenerClass> |
| 31 | 139 | ss | static void ofAddListener(EventType & event, ListenerClass * listener, void (ListenerClass::*listenerMethod)(ArgumentsType&)){ |
| 32 | 139 | ss | event += delegate(listener, listenerMethod); |
| 33 | 139 | ss | } |
| 34 | 139 | ss | |
| 35 | 139 | ss | |
| 36 | 139 | ss | //----------------------------------------------------
|
| 37 | 139 | ss | // unregister any method of any class to an event.
|
| 38 | 139 | ss | // the method must provide one the following
|
| 39 | 139 | ss | // signatures:
|
| 40 | 139 | ss | // void method(ArgumentsType & args)
|
| 41 | 139 | ss | // void method(const void * sender, ArgumentsType &args)
|
| 42 | 139 | ss | // ie:
|
| 43 | 139 | ss | // ofAddListener(addon.newIntEvent, this, &Class::method)
|
| 44 | 139 | ss | |
| 45 | 139 | ss | template <class EventType,typename ArgumentsType, class ListenerClass> |
| 46 | 139 | ss | static void ofRemoveListener(EventType & event, ListenerClass * listener, void (ListenerClass::*listenerMethod)(ArgumentsType&)){ |
| 47 | 139 | ss | event -= delegate(listener, listenerMethod); |
| 48 | 139 | ss | } |
| 49 | 139 | ss | |
| 50 | 139 | ss | //----------------------------------------------------
|
| 51 | 139 | ss | // notifies an event so all the registered listeners
|
| 52 | 139 | ss | // get called
|
| 53 | 139 | ss | // ie:
|
| 54 | 139 | ss | // ofNotifyEvent(addon.newIntEvent, intArgument, this)
|
| 55 | 139 | ss | //
|
| 56 | 139 | ss | // or in case there's no sender:
|
| 57 | 139 | ss | // ofNotifyEvent(addon.newIntEvent, intArgument)
|
| 58 | 139 | ss | |
| 59 | 139 | ss | template <class EventType,typename ArgumentsType, typename SenderType> |
| 60 | 139 | ss | static void ofNotifyEvent(EventType & event, ArgumentsType & args, SenderType * sender){ |
| 61 | 139 | ss | event.notify(sender,args); |
| 62 | 139 | ss | } |
| 63 | 139 | ss | |
| 64 | 139 | ss | template <class EventType,typename ArgumentsType> |
| 65 | 139 | ss | static void ofNotifyEvent(EventType & event, ArgumentsType & args){ |
| 66 | 139 | ss | event.notify(NULL,args);
|
| 67 | 139 | ss | } |
| 68 | 139 | ss | |
| 69 | 139 | ss | |
| 70 | 139 | ss | #endif |
