This is pretty much a continuation of the “better event model” thread. The key ideas were already worked out pretty well. At this point it is just a matter of rounding things up. There was a bit of ambiguity on where/how to register the listeners. Arturo introduced the idea of a event manager class and in the patch-6 I am using this class for both registering and triggering the event. Here is a bit of a summary to get everybody going again:
Howto use this patch: It is made for the “v005 + poco” zip that was circulating earlier on the forum. Copy all the files from the zip and overwrite the ones in OF. In main.cpp of any example replace “ofRunApp(new testApp());” with " testApp app; ofRunApp();".
Generally each event consists of the following classes:
- Usage: carry data about the event,
------- the object passed to the event listener
- Examples: ofKeyEventArgs, ofMouseEventArgs
- Useage: subclassed by any object that handles the event
-------- (eg: ofSimpleApp)
- Examples: ofKeyListener, ofMouseListner
- Usage: registers/unregisters event listeners,
------- and triggers event
- Examples: ofKeyEventManager, ofMouseEventManager
Event manager classes can either be instanced as globals, member variables or they can be subclassed. For the core they should probably be global. For gui elements (eg. buttons or or any object that occurs multiple times) they should be members or superclasses. For these three cases the the api looks like this, respectively.
registering a listener to a global manager:
registering a listener to a subclassed manager (eg. button “is a” manager):
registering a listener to a member manager (eg. button “has a” manager):
Some questions to consider:
Q: Where should the event manager objects reside?
For core events: ofAppRunner.cpp or event .cpp (eg. ofKeyEvents.cpp)
For gui objects: member of the gui class or superclass
Q: should we group setup, update, draw, exit ? Under what name ?
Q: Should all the event-related source files be moved from the “app” folder to the their own “events” folder?