Events Handlers

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

mrGREEN
Just popping in
Just popping in
Posts: 12
Joined: Wed Apr 01, 2009 12:49

Events Handlers

Postby mrGREEN » Tue May 05, 2009 13:48

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:

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Events Handlers

Postby Jamarr » Wed May 06, 2009 19:24

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.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

aerique
Just popping in
Just popping in
Posts: 3
Joined: Tue Jun 23, 2009 21:10

Re: Events Handlers

Postby aerique » Tue Jun 23, 2009 22:00

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.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Events Handlers

Postby CrazyEddie » Wed Jun 24, 2009 08:42

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.

aerique
Just popping in
Just popping in
Posts: 3
Joined: Tue Jun 23, 2009 21:10

Re: Events Handlers

Postby aerique » Wed Jun 24, 2009 09:38

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.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Events Handlers

Postby CrazyEddie » Thu Jun 25, 2009 08:54

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.

aerique
Just popping in
Just popping in
Posts: 3
Joined: Tue Jun 23, 2009 21:10

Re: Events Handlers

Postby aerique » Thu Jun 25, 2009 18:40

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.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 7 guests