SlideShare a Scribd company logo
1 of 26
openFrameworks
     events
Events
• Send notifications on certain events or create
  your own.

• Wraps around Poco Events system
• You register for the events you want to receive.
• testApp receives events automatically (       ,
                                         keyPressed
  keyReleased, mouseMoved)
Events
Delegates
• A target subscribes to an event by registering a
  delegate.

• You can see the delegate as an “Event listener”
• An event has always one argument.
• There is one global ofEvents object which holds
    the OF related, event instances to which you can
    subscribe.

• OF uses a First In First Out (FIFO) event queue.
Events
Listen for OF-events
Create a function which is called when the event
notification is sent. This function must have one
argument of the correct event type.

Use ofAddListener(event object, callback object,
callback function) to tell the event system you want
to listen for events.

You can remove your regiseterd listener by calling
ofRemoveListener(event object, callback object,
callback function)
Register to an event
1. Decide to what event you want to listen
See events/ofEvents.h for the available OF events
in the ofCoreEvent class.
For example:
ofEvent<ofMouseEventArgs> mouseMoved

The name of the event is mouseMoved and passes
am ofMouseEventArgs to the callback.
Register to an event

                                                       Name of event is
class ofCoreEvents {
 public:                                               mouseMoved which

 ofEvent<ofEventArgs> 
 

 ofEvent<ofEventArgs> 
 
                                setup;
                                update;                stores the listeners

 ofEvent<ofEventArgs> 
 
      draw;

 ofEvent<ofEventArgs> 
 
      exit;

 ofEvent<ofResizeEventArgs>    
 indowResized;
                                w


   ofEvent<ofKeyEventArgs> 
   keyPressed;

   ofEvent<ofKeyEventArgs> 
   keyReleased;


   ofEvent<ofMouseEventArgs>   
   mouseMoved;

   ofEvent<ofMouseEventArgs>   
   mouseDragged;

   ofEvent<ofMouseEventArgs>   
   mousePressed;    ofMouseEventArgs is

   ofEvent<ofMouseEventArgs>   
   mouseReleased;

   ...                                              passed as parameter to
}
                                                     the callback
Register to an event
2. Create the callback function
Create a function which receives the event type as
first and only argument.
ofEvent<ofMouseEventArgs> mouseMoved

      class testApp : public ofBaseApp{
      
 public:
      
 
      void myCustomMouseReleased(ofMouseEventArgs& args) {
      
 
      
   cout << "received a mouse released event" << endl;
      
 
      
   cout << "mouse x:" << args.x << endl;
      
 
      
   cout << "mouse y:" << args.y << endl;
      
 
      
   cout << "mouse button:" << args.button << endl;
      
 
      }
      }
Register to an event
3. Tell the event object you want to listen
Use the global function ofAddListener to register
your new function as a callback for the event. Note
that ofEvents is the global instance of ofCoreEvents


 void testApp::setup(){
 
 ofAddListener(
 
 
      ofEvents.mouseReleased 
 
  
   // the event object
          ,this 
 
   
  
   
  
  
  
   // testApp pointer
 
 
      ,&testApp::myCustomMouseReleased
   // the callback function.
 
 );
 }
UnRegister from event
To unregister from an event, you simply call
ofRemoveListener() with the same parameters
when you added the listener.

You can re-enable the listener again by
calling ofAddListener() again.

            void testApp::setup(){
            
 ofRemoveListener(
            
 
      ofEvents.mouseReleased
            
 
      ,this
            
 
      ,&testApp::myCustomMouseReleased
            
 );
            }
Recap event listening
Listen for OF-events
1. Create listener function
2. Find the event you want to listen to.
3. Call ofAddListener() to register


Remove listener
1. Call ofRemoveListener()
Event listening
Register to all mouse events
Create these functions:
void mouseDragged(ofMouseEventArgs& args)
void mouseMoved(ofMouseEventArgs& args)
void mousePressed(ofMouseEventArgs& args)
void mouseReleased(ofMouseEventArgs& args)

Call ofRegisterMouseEvents(this) to
register to all mouse events. Instead of
registering for each one separately. To unregister
call ofUnregisterMouseEvents(this)
Event listening
class MyWorker {
public:

 MyWorker() {

 }


 void setup() {

 
     ofRegisterMouseEvents(this);

 }


 void mouseMoved(ofMouseEventArgs& args) {

 
     cout << "Moved: " << args.x << ", " << args.y << endl;

 }


 void mouseDragged(ofMouseEventArgs& args) {

 }


 void mousePressed(ofMouseEventArgs& args) {

 }


 void mouseReleased(ofMouseEventArgs& args) {

 }

};
Event listening
Register to all keyboard events
Create these functions:
void keyPressed(ofKeyEventArgs& args)
void keyReleased(ofKeyEventArgs& args)

Call ofRegisterKeyEvents(this) to
register to all key events. To unregister
call ofUnregisterKeyEvents(this)
Event listening
Register to all touch events
Create these functions:
void touchDoubleTap(ofTouchEventArgs& args)
void touchDown(ofTouchEventArgs& args)
void touchMoved(ofTouchEventArgs& args)
void touchUp(ofTouchEventArgs& args)
void touchCancelled(ofTouchEventArgs& args)

Call ofRegisterTouchEvents(this) to
register to all touch events. Unregister using
ofUnregisterTouchEvents(this)
Event listening
Register to all drag events
Create these functions:
void dragEvent(ofDragInfo& args)

Call ofRegisterDragEvents(this) to
register to all drag events. Unregister
with ofUnregisterDragEvents(this)
Simple messaging
openFrameworks adds a very simple way to send
messages between objects using the new function
ofSendMessage(string).

When you call ofSendMessage, the function
testApp::gotMessage(ofMessage msg) is called by the
event system.

You can use this as an easy way to notify
your application about certain simple events.

Works everywhere!
Simple messaging


 void testApp::setup(){
 
 ofSendMessage("ready");
 }

 void testApp::gotMessage(ofMessage msg){
 
 cout << "got message: " << msg.message << endl;
 }
Register for messages
When you create your own class and you want to
receive messages, you create a function called void
gotMessage(ofMessage& msg) and register using
ofRegisterGetMessages(this)

              class MyMessageReciever {
              public:
              
 MyMessageReciever() {
              
 }
              
              
 void setup() {
              
 
     ofRegisterGetMessages(this);
              
              
 }
              
 void gotMessage(ofMessage& msg) {
              
 
     cout << "got message: " << msg.message << endl;
              
 }
              }
Common events
Mouse events      Touch events

• mouseMoved      • touchDown
• mouseDragged    • touchUp
• mousePressed    • touchMoved
• mouseReleased   • touchDoubleTap
                  • touchCancelled
Key events        Audio events

• keyPressed      • audioReceived
• keyReleased     • audioRequested
Common events

Application events   Simple messages

• setup              • messageEvent
• update
• draw               File drag events

• exit               • fileDragEvent
• windowResized
Event argument objects
ofKeyEventArgs     ofAudioEventArgs
int key            float* buffer
                   int bufferSize
ofMouseEventArgs   int nChannels
int x
int y              ofResizeEventArgs
int button         int width
                   int height
Event argument objects
 ofTouchEventArgs
 int id             float minoraxis
 int time           float majoraxis
 float x             float pressure
 float y             float xspeed
 int numTouches     float yspeed
 float width         float xaccel
 float height        float yaccel
 float angle
Custom events

In your header file (.h) create an extern event object
which will be used as a storage for listeners and
which notifies them.

“extern” tells your compiler the object is declared
somewhere else. This will be done in your .cpp file.
Also, define your custom event data type.
Custom events
Step 1. create your custom event data type


class MyCustomEventData {
public:

 MyCustomEventData(string someData):data(someData) {

 }

 string data;
};


Step 2. create a extern declared event dispatcher object.

extern ofEvent<MyCustomEventData> myCustomEventDispatcher;

                                                            The event dispatcher
  The data type you will pass to listener
Custom events
Step 3. in your .cpp define the event dispatcher object.
ofEvent<MyCustomEventData> myCustomEventDispatcher;




To listen to this myCustomerEventDispatcher you
create a event listener function and call
ofAddListener like this:
ofAddListener(myCustomEventDispatcher, this, &testApp::myCustomEventListener);




This is how the event listener function looks.

class testApp : public ofBaseApp{

 public:

 
      void myCustomEventListener(MyCustomEventData& args) {

 
      
   cout << "Received a custom event: " << args.data << endl;

 
      }
}
roxlu
www.roxlu.com

More Related Content

Viewers also liked (10)

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - video
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
openFrameworks 007 - GL
openFrameworks 007 - GL openFrameworks 007 - GL
openFrameworks 007 - GL
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
Computer vision techniques for interactive art
Computer vision techniques for interactive artComputer vision techniques for interactive art
Computer vision techniques for interactive art
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
openFrameworks 007 - sound
openFrameworks 007 - soundopenFrameworks 007 - sound
openFrameworks 007 - sound
 
Media Art II 2013 第5回:openFrameworks Addonを使用する
Media Art II 2013 第5回:openFrameworks Addonを使用するMedia Art II 2013 第5回:openFrameworks Addonを使用する
Media Art II 2013 第5回:openFrameworks Addonを使用する
 

Similar to openFrameworks 007 - events

Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 

Similar to openFrameworks 007 - events (20)

Event handling
Event handlingEvent handling
Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
Java gui event
Java gui eventJava gui event
Java gui event
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
 
What is Event
What is EventWhat is Event
What is Event
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Java-Events
Java-EventsJava-Events
Java-Events
 
Events1
Events1Events1
Events1
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
File Handling
File HandlingFile Handling
File Handling
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

openFrameworks 007 - events

  • 1. openFrameworks events
  • 2. Events • Send notifications on certain events or create your own. • Wraps around Poco Events system • You register for the events you want to receive. • testApp receives events automatically ( , keyPressed keyReleased, mouseMoved)
  • 3. Events Delegates • A target subscribes to an event by registering a delegate. • You can see the delegate as an “Event listener” • An event has always one argument. • There is one global ofEvents object which holds the OF related, event instances to which you can subscribe. • OF uses a First In First Out (FIFO) event queue.
  • 4. Events Listen for OF-events Create a function which is called when the event notification is sent. This function must have one argument of the correct event type. Use ofAddListener(event object, callback object, callback function) to tell the event system you want to listen for events. You can remove your regiseterd listener by calling ofRemoveListener(event object, callback object, callback function)
  • 5. Register to an event 1. Decide to what event you want to listen See events/ofEvents.h for the available OF events in the ofCoreEvent class. For example: ofEvent<ofMouseEventArgs> mouseMoved The name of the event is mouseMoved and passes am ofMouseEventArgs to the callback.
  • 6. Register to an event Name of event is class ofCoreEvents { public: mouseMoved which ofEvent<ofEventArgs> ofEvent<ofEventArgs> setup; update; stores the listeners ofEvent<ofEventArgs> draw; ofEvent<ofEventArgs> exit; ofEvent<ofResizeEventArgs> indowResized; w ofEvent<ofKeyEventArgs> keyPressed; ofEvent<ofKeyEventArgs> keyReleased; ofEvent<ofMouseEventArgs> mouseMoved; ofEvent<ofMouseEventArgs> mouseDragged; ofEvent<ofMouseEventArgs> mousePressed; ofMouseEventArgs is ofEvent<ofMouseEventArgs> mouseReleased; ... passed as parameter to } the callback
  • 7. Register to an event 2. Create the callback function Create a function which receives the event type as first and only argument. ofEvent<ofMouseEventArgs> mouseMoved class testApp : public ofBaseApp{ public: void myCustomMouseReleased(ofMouseEventArgs& args) { cout << "received a mouse released event" << endl; cout << "mouse x:" << args.x << endl; cout << "mouse y:" << args.y << endl; cout << "mouse button:" << args.button << endl; } }
  • 8. Register to an event 3. Tell the event object you want to listen Use the global function ofAddListener to register your new function as a callback for the event. Note that ofEvents is the global instance of ofCoreEvents void testApp::setup(){ ofAddListener( ofEvents.mouseReleased // the event object ,this // testApp pointer ,&testApp::myCustomMouseReleased // the callback function. ); }
  • 9. UnRegister from event To unregister from an event, you simply call ofRemoveListener() with the same parameters when you added the listener. You can re-enable the listener again by calling ofAddListener() again. void testApp::setup(){ ofRemoveListener( ofEvents.mouseReleased ,this ,&testApp::myCustomMouseReleased ); }
  • 10. Recap event listening Listen for OF-events 1. Create listener function 2. Find the event you want to listen to. 3. Call ofAddListener() to register Remove listener 1. Call ofRemoveListener()
  • 11. Event listening Register to all mouse events Create these functions: void mouseDragged(ofMouseEventArgs& args) void mouseMoved(ofMouseEventArgs& args) void mousePressed(ofMouseEventArgs& args) void mouseReleased(ofMouseEventArgs& args) Call ofRegisterMouseEvents(this) to register to all mouse events. Instead of registering for each one separately. To unregister call ofUnregisterMouseEvents(this)
  • 12. Event listening class MyWorker { public: MyWorker() { } void setup() { ofRegisterMouseEvents(this); } void mouseMoved(ofMouseEventArgs& args) { cout << "Moved: " << args.x << ", " << args.y << endl; } void mouseDragged(ofMouseEventArgs& args) { } void mousePressed(ofMouseEventArgs& args) { } void mouseReleased(ofMouseEventArgs& args) { } };
  • 13. Event listening Register to all keyboard events Create these functions: void keyPressed(ofKeyEventArgs& args) void keyReleased(ofKeyEventArgs& args) Call ofRegisterKeyEvents(this) to register to all key events. To unregister call ofUnregisterKeyEvents(this)
  • 14. Event listening Register to all touch events Create these functions: void touchDoubleTap(ofTouchEventArgs& args) void touchDown(ofTouchEventArgs& args) void touchMoved(ofTouchEventArgs& args) void touchUp(ofTouchEventArgs& args) void touchCancelled(ofTouchEventArgs& args) Call ofRegisterTouchEvents(this) to register to all touch events. Unregister using ofUnregisterTouchEvents(this)
  • 15. Event listening Register to all drag events Create these functions: void dragEvent(ofDragInfo& args) Call ofRegisterDragEvents(this) to register to all drag events. Unregister with ofUnregisterDragEvents(this)
  • 16. Simple messaging openFrameworks adds a very simple way to send messages between objects using the new function ofSendMessage(string). When you call ofSendMessage, the function testApp::gotMessage(ofMessage msg) is called by the event system. You can use this as an easy way to notify your application about certain simple events. Works everywhere!
  • 17. Simple messaging void testApp::setup(){ ofSendMessage("ready"); } void testApp::gotMessage(ofMessage msg){ cout << "got message: " << msg.message << endl; }
  • 18. Register for messages When you create your own class and you want to receive messages, you create a function called void gotMessage(ofMessage& msg) and register using ofRegisterGetMessages(this) class MyMessageReciever { public: MyMessageReciever() { } void setup() { ofRegisterGetMessages(this); } void gotMessage(ofMessage& msg) { cout << "got message: " << msg.message << endl; } }
  • 19. Common events Mouse events Touch events • mouseMoved • touchDown • mouseDragged • touchUp • mousePressed • touchMoved • mouseReleased • touchDoubleTap • touchCancelled Key events Audio events • keyPressed • audioReceived • keyReleased • audioRequested
  • 20. Common events Application events Simple messages • setup • messageEvent • update • draw File drag events • exit • fileDragEvent • windowResized
  • 21. Event argument objects ofKeyEventArgs ofAudioEventArgs int key float* buffer int bufferSize ofMouseEventArgs int nChannels int x int y ofResizeEventArgs int button int width int height
  • 22. Event argument objects ofTouchEventArgs int id float minoraxis int time float majoraxis float x float pressure float y float xspeed int numTouches float yspeed float width float xaccel float height float yaccel float angle
  • 23. Custom events In your header file (.h) create an extern event object which will be used as a storage for listeners and which notifies them. “extern” tells your compiler the object is declared somewhere else. This will be done in your .cpp file. Also, define your custom event data type.
  • 24. Custom events Step 1. create your custom event data type class MyCustomEventData { public: MyCustomEventData(string someData):data(someData) { } string data; }; Step 2. create a extern declared event dispatcher object. extern ofEvent<MyCustomEventData> myCustomEventDispatcher; The event dispatcher The data type you will pass to listener
  • 25. Custom events Step 3. in your .cpp define the event dispatcher object. ofEvent<MyCustomEventData> myCustomEventDispatcher; To listen to this myCustomerEventDispatcher you create a event listener function and call ofAddListener like this: ofAddListener(myCustomEventDispatcher, this, &testApp::myCustomEventListener); This is how the event listener function looks. class testApp : public ofBaseApp{ public: void myCustomEventListener(MyCustomEventData& args) { cout << "Received a custom event: " << args.data << endl; } }

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n