openframeworks/openFrameworks — pull request #2922 by julapy (2014-04-07 07:37:34+00:00)
Title: fixes for mouse registration issues with ofxGui

when creating ofxGui elements like so `new ofxPanel()` and then deleting them,
i noticed that mouse events were not being unregistered properly, so they next time the mouse was pressed after the object was deleted, it would crash the app.

the issues that i found included,
- ofxPanel was registering for mouse events 3 times on setup!
- ofxButton was registering for events in setup and registering again in the destructor.
- ofxSlider never unregistered mouse events when destroyed.

the solutions in this PR include,
- added mouse register and unregister methods to ofxBaseGui, so all classes that extend ofxBaseGui register and unregister for mouse events via these method.
```
void registerMouseEvents();
void unregisterMouseEvents();
```

`registerMouseEvents()` and `unregisterMouseEvents()` have a flag which makes sure that no multiple mouse registration can be made and that no mouse events are unregistered if they have not been registered for in the first place.

`~ofxBaseGui()` destructor now unregisters mouse events for every `ofxBaseGui` object.
```
ofxBaseGui::~ofxBaseGui(){
unregisterMouseEvents();
}
```