ofDocsdocumentation events ofEventUtils (functions)

ofEventUtils (functions)


ofAddListener( ... )

void ofAddListener(EventType &event, void (*)(const void *, ArgumentsType &) listenerFunction, int prio)

ofAddListener( ... )

void ofAddListener(EventType &event, bool (*)(const void *, ArgumentsType &) listenerFunction, int prio)

ofAddListener( ... )

void ofAddListener(EventType &event, ListenerClass *listener, bool (ListenerClass::*)(const void *, ArgumentsType &) listenerMethod, int prio)

Allows you to add a listener method to an event, use it whenever you want a class to be notified about an event.

This is a templated function so the types of the parameters are not predefined types but can be any type as long as the method is one of the listener class' and it has a particular signature.

The signature of the listener method depends on the event type. Every event is defined as:

ofEvent<type

ofAddListener( ... )

void ofAddListener(EventType &event, ListenerClass *listener, void (ListenerClass::*)(const void *, ArgumentsType &) listenerMethod, int prio)

register any method of any class to an event.

the method must provide one of the following signatures: void method(ArgumentsType & args) void method(const void * sender, ArgumentsType &args) ie: ofAddListener(addon.newIntEvent, this, &Class::method)

Allows you to add a listener method to an event, use it whenever you want a class to be notified about an event.

This is a templated function so the types of the parameters are not predefined types but can be any type as long as the method is one of the listener class' and it has a particular signature.

The signature of the listener method depends on the event type. Every event is defined as:

ofEvent<type

ofAddListener( ... )

void ofAddListener(EventType &event, ListenerClass *listener, bool (ListenerClass::*)(ArgumentsType &) listenerMethod, int prio)

Allows you to add a listener method to an event, use it whenever you want a class to be notified about an event.

This is a templated function so the types of the parameters are not predefined types but can be any type as long as the method is one of the listener class' and it has a particular signature.

The signature of the listener method depends on the event type. Every event is defined as:

ofEvent<type

ofAddListener( ... )

void ofAddListener(EventType &event, ListenerClass *listener, void (ListenerClass::*)(ArgumentsType &) listenerMethod, int prio)

Allows you to add a listener method to an event, use it whenever you want a class to be notified about an event.

This is a templated function so the types of the parameters are not predefined types but can be any type as long as the method is one of the listener class' and it has a particular signature.

The signature of the listener method depends on the event type. Every event is defined as:

ofEvent<type

ofAddListener( ... )

void ofAddListener(EventType &event, void (*)(ArgumentsType &) listenerFunction, int prio)

ofAddListener( ... )

void ofAddListener(EventType &event, bool (*)(ArgumentsType &) listenerFunction, int prio)

ofNotifyEvent( ... )

bool ofNotifyEvent(EventType &event, const ArgumentsType &args)

Notifies an event, what makes all it's registered method listeners to be called with the same argument.

This is a templated function so the type of the parameters is not predefined and can be anything as long as the listener methods use the same type for the parameter.

The arguments are passed to the listeners by reference so they can modify them.

The listener methods are called in the same order they were registered using ofAddListener.

With this version the listeners also receive a pointer to the notifying class in case the listener method specifies that parameter.

For instance, borrowing from the examples/events/SimpleEventsExample, if we make a class that will broadcast an event:


class SimpleEventNotifier {
	ofEvent<float

ofNotifyEvent( ... )

bool ofNotifyEvent(EventType &event, ArgumentsType &args)

Notifies an event, what makes all it's registered method listeners to be called with the same argument.

This is a templated function so the type of the parameters is not predefined and can be anything as long as the listener methods use the same type for the parameter.

The arguments are passed to the listeners by reference so they can modify them.

The listener methods are called in the same order they were registered using ofAddListener.

With this version the listeners also receive a pointer to the notifying class in case the listener method specifies that parameter.

For instance, borrowing from the examples/events/SimpleEventsExample, if we make a class that will broadcast an event:


class SimpleEventNotifier {
	ofEvent<float

ofNotifyEvent( ... )

bool ofNotifyEvent(EventType &event, const ArgumentsType &args, SenderType *sender)

Notifies an event, what makes all it's registered method listeners to be called with the same argument.

This is a templated function so the type of the parameters is not predefined and can be anything as long as the listener methods use the same type for the parameter.

The arguments are passed to the listeners by reference so they can modify them.

The listener methods are called in the same order they were registered using ofAddListener.

With this version the listeners also receive an event args object that can be used to send additional data to the listening class.

For instance, borrowing from the examples/events/SimpleEventsExample, if we make a class that will broadcast an event:


class SimpleEventNotifier {
	ofEvent<float

ofNotifyEvent( ... )

bool ofNotifyEvent(EventType &event, ArgumentsType &args, SenderType *sender)

notifies an event so all the registered listeners get called

ie: ofNotifyEvent(addon.newIntEvent, intArgument, this)

or in case there's no sender: ofNotifyEvent(addon.newIntEvent, intArgument)

@returns: true in case any listener attended the event

Notifies an event, what makes all it's registered method listeners to be called with the same argument.

This is a templated function so the type of the parameters is not predefined and can be anything as long as the listener methods use the same type for the parameter.

The arguments are passed to the listeners by reference so they can modify them.

The listener methods are called in the same order they were registered using ofAddListener.

For instance, borrowing from the examples/events/SimpleEventsExample, if we make a class that will broadcast an event:


class SimpleEventNotifier {
	ofEvent notify;	// will send an event with no data

	void sendEvent() {
		ofNotifyEvent(notify); 
	}

};

We can listen for that in our ofApp:

SimpleEventNotifier notifier;
void ofApp::setup() {
	ofAddListener(notifier.notify, this, &ofApp::haveBeenNotified);
}

void ofApp::haveBeenNotified(){
    ofLog() << " event at " << ofGetElapsedTimef() << endl;
}


ofRemoveListener( ... )

void ofRemoveListener(EventType &event, void (*)(const void *, ArgumentsType &) listenerFunction, int prio)

ofRemoveListener( ... )

void ofRemoveListener(EventType &event, bool (*)(const void *, ArgumentsType &) listenerFunction, int prio)

ofRemoveListener( ... )

void ofRemoveListener(EventType &event, ListenerClass *listener, bool (ListenerClass::*)(const void *, ArgumentsType &) listenerMethod, int prio)

Removes a listener method from an event. Use it whenever you want a class to stop being notified about an event after having registered it to the method with ofAddListener.

Don't forget to call this before deleting any instance that is listening to an event, if not the event will try to notify a non existent instance and the application will crash.

The syntax is just the same as that of ofAddListener.


ofRemoveListener( ... )

void ofRemoveListener(EventType &event, ListenerClass *listener, void (ListenerClass::*)(const void *, ArgumentsType &) listenerMethod, int prio)

unregister any method of any class to an event.

the method must provide one the following signatures: void method(ArgumentsType & args) void method(const void * sender, ArgumentsType &args) ie: ofAddListener(addon.newIntEvent, this, &Class::method)

Removes a listener method from an event. Use it whenever you want a class to stop being notified about an event after having registered it to the method with ofAddListener.

Don't forget to call this before deleting any instance that is listening to an event, if not the event will try to notify a non existent instance and the application will crash.

The syntax is just the same as that of ofAddListener.


ofRemoveListener( ... )

void ofRemoveListener(EventType &event, ListenerClass *listener, bool (ListenerClass::*)(ArgumentsType &) listenerMethod, int prio)

Removes a listener method from an event. Use it whenever you want a class to stop being notified about an event after having registered it to the method with ofAddListener.

Don't forget to call this before deleting any instance that is listening to an event, if not the event will try to notify a non existent instance and the application will crash.

The syntax is just the same as that of ofAddListener.


ofRemoveListener( ... )

void ofRemoveListener(EventType &event, ListenerClass *listener, void (ListenerClass::*)(ArgumentsType &) listenerMethod, int prio)

Removes a listener method from an event. Use it whenever you want a class to stop being notified about an event after having registered it to the method with ofAddListener.

Don't forget to call this before deleting any instance that is listening to an event, if not the event will try to notify a non existent instance and the application will crash.

The syntax is just the same as that of ofAddListener.


ofRemoveListener( ... )

void ofRemoveListener(EventType &event, void (*)(ArgumentsType &) listenerFunction, int prio)

ofRemoveListener( ... )

void ofRemoveListener(EventType &event, bool (*)(ArgumentsType &) listenerFunction, int prio)