subscribeEvent function parameter taking more than one arg?

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

pighead10
Just popping in
Just popping in
Posts: 8
Joined: Fri Jan 21, 2011 15:43

subscribeEvent function parameter taking more than one arg?

Postby pighead10 » Thu Oct 27, 2011 16:53

Code: Select all

guiRoot->getChild("Root/AddMiner")->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&GameState::addMiner,this));


I want GameState::addMiner to have an additional argument passed to it, as well as the necessary const CEGUI::EventArgs& one. Is there any easy way I can do this with CEGUI instead of making some other hacky fix?

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: subscribeEvent function parameter taking more than one a

Postby Kulik » Thu Oct 27, 2011 17:27

Use boost::bind, CEGUI's subscriber event system is compatible with it.

PS: We would appreciate a wiki article about this, I am pretty sure there is none. :)

pighead10
Just popping in
Just popping in
Posts: 8
Joined: Fri Jan 21, 2011 15:43

Re: subscribeEvent function parameter taking more than one a

Postby pighead10 » Thu Oct 27, 2011 20:36

I've never used the boost library myself. Is there an easy way of explaining what it does? I'm relatively new to C++ and am not familiar with stl bind functions either.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: subscribeEvent function parameter taking more than one a

Postby Kulik » Thu Oct 27, 2011 22:45

Sorry but I will pull the RTFM acronym :-) boost.org has good documentation, use it. It's no rocket science, no reason to be scared of it. I also think there aren't many easier ways to bind parameters to functions.

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

Re: subscribeEvent function parameter taking more than one a

Postby Jamarr » Fri Oct 28, 2011 00:49

You could just define an object that stores the parameters you need as members, and then use instances of those objects as event handlers. When an instance is called to handle an event, have it call your addMiner function passing the relevant members. You can find the basics of this here. My understanding of boost::bind is basically that it generalizes and simplifies this process for you.

p.s. I know I should probably be more familiar with and taking advantage of boost by now lol :oops:
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!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 3 guests