Determine event name in event handler

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

timmeh
Just popping in
Just popping in
Posts: 3
Joined: Mon Aug 28, 2006 03:31

Determine event name in event handler

Postby timmeh » 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:

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?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Mon Aug 28, 2006 23:08

Your approach looks good I think. We are not planning of adding this information into the base.


Return to “Help”

Who is online

Users browsing this forum: Google [Bot] and 20 guests