Page 1 of 1

Events Handlers

Posted: Tue May 05, 2009 13:48
by mrGREEN
Hi

Suppouse that I subscribe my events into a single handler function

Code: Select all

subscribeEvent("Window/MyWin", Window::EventActivated, Event::Subscriber(&WindowDemo::EventHandler, this));
subscribeEvent("Window/MyWin", Window::EventAlphaChanged, Event::Subscriber(&WindowDemo::EventHandler, this));
subscribeEvent("Window/MyWin", Window::EventCharacterKey, Event::Subscriber(&WindowDemo::EventHandler, this));


How can I retrieve the information about which event fired the handler :?:

Code: Select all

bool WindowDemo::EventHandler(const CEGUI::EventArgs& cEventArgs)
{
Event <- cEventArgs ???? SOME HOW ????
...
   if (Event == Window::EventActivated)
      // Code dealing with EventActivated event
   if (Event == Window::EventAlphaChanged)
      // Code dealing with EventAlphaChanged event
   if (Event == Window::EventCharacterKey)
      // Code dealing with EventCharacterKey event   
...      
}


I really need to use only one callback.

So far I realize that is not possible achieve such thing :shock:

Re: Events Handlers

Posted: Wed May 06, 2009 19:24
by Jamarr
The CEGUI::EventArgs object does not have any kind of type-information built into it. I think the only way to do this would be to modify the CEGUI source and re-build it so that the event name is available from the EventArgs object. If there is another way, I am not aware of it; you will likely have to wait till CE gets back from his break for a definitive answer.

I am not sure why you have to do this, but it seems like a very poor design.

Re: Events Handlers

Posted: Tue Jun 23, 2009 22:00
by aerique
Jamarr wrote:If there is another way, I am not aware of it; you will likely have to wait till CE gets back from his break for a definitive answer.

I'm also curious what the easiest way is to get the event type (f.e. "Clicked") from within the event handler. Like others I'm trying to use just one event handler (which is a callback function back into Common Lisp from where I'm using CEGUI) and I basically need the name of the window which I can get from casting EventArgs and I need the type of event.

The best solution I've seen so far is: viewtopic.php?f=10&t=1871&p=9250#p9250 but since it is from 2006 I'm wondering whether an easier way has been added to CEGUI. (Unsurprisingly I like his suggestion of adding the event name to EventArgs.)

Jamarr wrote:I am not sure why you have to do this, but it seems like a very poor design.

For me it would mean a whole lot less needed code in both C++, my C wrappers functions and in Common Lisp since I wouldn't have to make functions for every type of event.

Re: Events Handlers

Posted: Wed Jun 24, 2009 08:42
by CrazyEddie
The situation in this regard is unchanged from 2006; monolithic event handlers are not something I like to look at, so there is still no intention of adding anything that would allow such a thing to be (easily) used (and therefore, subsequently abused).

Sorry to be the bearer of bad news ;)

CE.

Re: Events Handlers

Posted: Wed Jun 24, 2009 09:38
by aerique
CrazyEddie wrote:Sorry to be the bearer of bad news ;)

Well, that's clear at least.

BTW. I've got a fantastic idea for a CEGUI 0.7.0 feature! :wink:

edit: I implemented timmeh's solution that I linked in my previous post and that works good enough for now.

Re: Events Handlers

Posted: Thu Jun 25, 2009 08:54
by CrazyEddie
aerique wrote:BTW. I've got a fantastic idea for a CEGUI 0.7.0 feature! :wink:

:lol:

Obviously, it's an easy enough thing to add (although copying strings on every event fired would get quite expensive fast), and while it seems harmless enough, it eventually leads to enormous monolithic functions, if.. if else.. if else... blah, blah, and people having issues and posting the damned things here on the forum, and I do not want to have to look at it. IMO it's horrible now, it's always been horrible, and it always be horrible (basically it's a throwback to a procedural, C language type approach - no thank you very much ;)).

CE.

Re: Events Handlers

Posted: Thu Jun 25, 2009 18:40
by aerique
Yeah, I understand your reasons. Although it is a pretty static approach.

I wanted the feature to move the logic out of C++ and into the language I'm wrapping CEGU in.