Class for creating custom events. Also used inside oF for its own events (see ofCoreEvents).
ie: To create a new event:
To notify an event of that type:
To add a listener to that event, if the event is for example in an object called mySoundObject, and you want to register ofApp as a listener for that event:
where ofApp::onVolumeChange is a function with the following signature:
void onVolumeChange(float & volume);
See the advancedEventsExample to see a complete example of how to work with events in oF.
Be careful when using events, it's a powerful structure but can also lead to really confusing code as there's no direct calls to an object.
It's important to unregister events in the destruction of listeners, if not an object that has already been destroyed can get called and the application will crash.
Events have a private copy constructor to avoid that a copy of an object with an event gets all the registered listeners of the original. To be able to create a copy of an object that contains an event, use a pointer to an event instead of a normal var. This also means that you cannot store events directly in a vector or any other collection, the solution is the same, just use a pointer to an event.
vector< ofEvent<int> > events;
vector< ofEvent<int>* > events;
Documentation from code comments
/! \endcond /
void ofEvent::add(TFunction function, int priority)
void ofEvent::add(TObj *listener, TMethod method, int priority)
void ofEvent::notify(const void *sender, T ¶m)
void ofEvent::remove(TFunction function, int priority)
void ofEvent::remove(TObj *listener, TMethod method, int priority)
Last updated 목요일, 08 9월 2016 17:15:57 UTC - 650640b7cb7f4a60c87d09e78bd7784ece3eb249
Hosting for openFrameworks is generously provided by Rackspace