Page 1 of 1

stuff with subscribeEvent()

Posted: Tue Mar 17, 2009 08:15
by Charli3
Hi,

Nice to see you 8)

Actually, I need to create an onClickButton() method.
Basically, this method do just that :

Code: Select all

void GUIHandler::OnClickButton(const std::string &button, "callback")
{
     CEGUI::WindowManager *wmgr = CEGUI::WindowManager::getSingletonPtr();
     CEGUI::Window *Event = wmgr->getWindow(button);
     Event->subscribeEvent(CEGUI::PushButton::EventClicked, "callback");
}


But I don't know how to pass the callback. I want it to be cegui independant.
So I think that I must pass a pointer to a function. However, I don't know how to cast the pointer for subscribeevent().

Hope I've been clear :D

Bye
Charlie

Posted: Tue Mar 17, 2009 12:03
by CrazyEddie
Hi, and welcome :)

Your function signature must match this:

Code: Select all

bool myFunction(const CEGUI::EventArgs&)


If it's a free function, just pass it in:

Code: Select all

Event->subscribeEvent(CEGUI::PushButton::EventClicked, myFunction);


i.e. Free functions do not need to be cast to Event::Subscriber or anything like that.

HTH

CE

Posted: Tue Mar 17, 2009 12:24
by Charli3
ok thanks for the answer :D

Is there any way to remove or change the argument of the function ?
I know you said "must match" but may be... I don't know :roll:

Posted: Tue Mar 17, 2009 14:51
by LennyH
Derive your own class from EventArgs. Have your derived class take in your callback. When firing the event, use your derived class.

Then, when handling event, cast the EventArgs to your derived class and grab your callback and do whatever it is you are going to do.

Posted: Sun Mar 22, 2009 12:34
by Pompei2
and use dynamic_cast to do so and cast std::bad_cast exceptions. Just to have robust code.