Determine event name in event handler
Posted: Mon Aug 28, 2006 17:44
In my project I need all gui events to pass through a single handler function. This function should then determine which widget caused what sort of event and react appropriately. Is there any way to determine the event type from within an event handler? It would be very handy if EventArgs held a reference to the event name.
My interim solution is to bind the event to a general purpose handler object, like so:
Does anybody know of a better way to accomplish this?
My interim solution is to bind the event to a general purpose handler object, like so:
Code: Select all
class evtHandler {
public:
explicit evtHandler(Window * wnd, const CEGUI::String & evt) : m_evt(evt) {
wnd->subscribeEvent(evt, Event::Subscriber(&evtHandler::handler, this));
}
protected:
bool handler(const EventArgs & args) {
// do something useful based on args->window and m_evt
return true;
}
private:
const CEGUI::String & m_evt;
};
Does anybody know of a better way to accomplish this?