stuff with subscribeEvent()

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

Just popping in
Just popping in
Posts: 2
Joined: Tue Mar 17, 2009 08:04

stuff with subscribeEvent()

Postby Charli3 » Tue Mar 17, 2009 08:15


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


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

Postby CrazyEddie » Tue Mar 17, 2009 12:03

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.



Just popping in
Just popping in
Posts: 2
Joined: Tue Mar 17, 2009 08:04

Postby Charli3 » Tue Mar 17, 2009 12:24

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:

Quite a regular
Quite a regular
Posts: 92
Joined: Thu Nov 30, 2006 20:50

Postby LennyH » Tue Mar 17, 2009 14:51

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.

Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Sun Mar 22, 2009 12:34

and use dynamic_cast to do so and cast std::bad_cast exceptions. Just to have robust code.

Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 1 guest