Page 1 of 1

Mouse Event handlers?

Posted: Thu Feb 03, 2005 10:06
by NSXEagle
I have a question related to event handlers. Yesterday, I implemented a simple picking function. I subscribed a Window::EventMouseButtonUp event to the root window of my GUI. Now here is my problem: The signature of my picking handler is:

Code: Select all

bool defaultPickingHandler(EventArgs& e)

Since the function is only called when a MouseButtonUp event was fired, I tried to get a pointer or a reference to MouseEventArgs, but as the parameter is a EventArgs&, no type conversion is possible. How can I obtain the correct MouseEventArgs in my handler function?

Re: Mouse Event handlers?

Posted: Fri Feb 04, 2005 09:06
by walaber
you should be able to safely cast to a MouseEventArgs object.

((CEGUI::MouseEventArgs)e)->button


..etc

Re: Mouse Event handlers?

Posted: Fri Feb 04, 2005 12:57
by NSXEagle
OK, I found the solution. All I had to do was to cast the "const EventArgs&" to an "const MouseEventArgs&". I don't know how I could've done this one wrong, but I think this was one of the dumb errors that happen to everyone of us... :?

It was only a matter of the right combination of types! :D

Re: Mouse Event handlers?

Posted: Fri Feb 04, 2005 14:39
by CrazyEddie
Yeah, this is very easily done :)

One of my most common mistakes is missing the reference specifier (&), then the cast goes totally wrong due to me having a sliced copy of the args instead of the reference :oops:

All good fun though ;)

CE.