Page 1 of 1

getting buttons to do something

Posted: Mon Apr 02, 2007 17:27
by jchmack
im new to cegui. I have been going over the beginners tutorials and i can get my button on screen and am injecting inputs properly. I can click the button and it changes to its "pushed in" state. But where do i define what this does in my program? Where can i say when i push button x (in CEGU) perform action y? Looking at the tutorials (from what i can find) the beginners guide ends at injecting inputs then goes into scripting and artists content. Can someone inform me or point to a link on how to get actions back from CEGUI? Thanks a lot in advance guys =)

Posted: Mon Apr 02, 2007 19:08
by Rackle
I'm sort of basing this code on the code posted within the Wiki code snippits; look there for more complete code:

Code: Select all

class MyClass  : public DialogSystem
{
public:
    bool initialiseSample()
{

...

CEGUI::Window* widgetHandle = CEGUI::WindowManager::getSingleton().getWindow(widget);
widgetHandle->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&MyClass::onOk, this));

...

return true;
}

bool onOk(const CEGUI::EventArgs& e)
{
  // THE BUTTON WAS CLICKED!!!
  return true;
}

}


Basically you subscribe to an event, such as a pushbutton being clicked and specify which class function should be called. In that function you execute your code and return true.