PushButton::EventClicked not working

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

sabotage3d
Just popping in
Just popping in
Posts: 17
Joined: Tue Sep 23, 2014 19:32

PushButton::EventClicked not working

Postby sabotage3d » Wed Oct 01, 2014 00:04

Hello ,

I am using Ogre 1.9.0 with CEGUI 0.8.4.
I am doing a really simple test where I am creating a button with CEGUI and I have a method called Move which should be triggered by EventClicked.
But I can't get the PushButton::EventClicked to work.
The animation of the button works when I click it but I can't get the event to set my method to true.
For reference I was using this link as a guide: http://cegui.org.uk/wiki/CEGUI_In_Practice_-_A_push_button

This is my code:

Code: Select all

//Init
CEGUI::OgreRenderer* renderer = &CEGUI::OgreRenderer::bootstrapSystem();
CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
CEGUI::PushButton *button = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button","PushButton"));

button->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5,0),CEGUI::UDim(0.50,0)));
button->setSize(CEGUI::USize(CEGUI::UDim(0,150),CEGUI::UDim(0,100)));
button->setText("PushButton");
button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&OgreFramework::Move, this));

CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(button);


//Input init
d_systemInputAggregator = new CEGUI::InputAggregator(
                                                  &CEGUI::System::getSingletonPtr()->getDefaultGUIContext());
d_systemInputAggregator->initialise();

//

void OgreFramework::mouseMoved(const MouseMotionEvent &arg)
{
     d_systemInputAggregator->injectMousePosition(arg.x, arg.y);   
}

void OgreFramework::mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id )
{
    pressed = true;
    d_systemInputAggregator->injectMouseButtonDown( CEGUI::LeftButton);
}


void OgreFramework::mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id )
{
    pressed = false;
    d_systemInputAggregator->injectMouseButtonUp( CEGUI::LeftButton);
}

bool OgreFramework::Move(const CEGUI::EventArgs &e)

{
    move = true;
    return true;
}


then in my loop I am checking the value of move but it always returns 0.

Thanks,

Alex

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: PushButton::EventClicked not working

Postby Ident » Wed Oct 01, 2014 06:54

What do you mean by: "The value of Move".
You subscribe a function, look at HelloWorld demo which subscribes to EventClicked.
CrazyEddie: "I don't like GUIs"

sabotage3d
Just popping in
Just popping in
Posts: 17
Joined: Tue Sep 23, 2014 19:32

Re: PushButton::EventClicked not working

Postby sabotage3d » Wed Oct 01, 2014 10:48

HI I looked into the HelloWorld already. Maybe it is something else causing it not work in my Ogre Project, but my callback method is called Move which is a bool and I have a class variable called move which is also a bool when the button is clicked it should set the move = true I am constantly checking the value in my main loop. But all I am getting is false.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: PushButton::EventClicked not working

Postby Ident » Wed Oct 01, 2014 12:04

Why dont u put a debugging breakpoint inside the move function and tell us what happens?
CrazyEddie: "I don't like GUIs"

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

Re: PushButton::EventClicked not working

Postby Kulik » Wed Oct 01, 2014 12:06

Hi, I don't see any obvious mistakes in the code.

The following:

Code: Select all

button->subscribeEvent(CEGUI::PushButton::EventClicked, &OgreFramework::Move, this);


will cause OgreFramework::Move be called when the button is clicked.

Please try to set a breakpoint inside the method. See if it gets triggered.

lucebac
Just can't stay away
Just can't stay away
Posts: 193
Joined: Sat May 24, 2014 21:55

Re: PushButton::EventClicked not working

Postby lucebac » Wed Oct 01, 2014 17:07

Another idea how to solve your problem:
as mentioned in the "CEGUI in practice" tutorial you have to create your root window as follows:

Code: Select all

CEGUI::Window* myRoot = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "_MasterRoot");
CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(myRoot);


and afterwards you can attach your own widgets like this:

Code: Select all

CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->addChild(newWidget);

sabotage3d
Just popping in
Just popping in
Posts: 17
Joined: Tue Sep 23, 2014 19:32

Re: PushButton::EventClicked not working

Postby sabotage3d » Wed Oct 01, 2014 19:31

Thanks a lot lucebac it worked :)

That is the working code:

Code: Select all

    CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
    guiRoot = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "_MasterRoot");
    CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(guiRoot);
    button = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button","PushButton"));
    button->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5,0),CEGUI::UDim(0.50,0)));
    button->setSize(CEGUI::USize(CEGUI::UDim(0,150),CEGUI::UDim(0,100)));
    button->setText("PushButton");
    button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&OgreFramework::Move, this));
    CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->addChild(button);

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: PushButton::EventClicked not working

Postby Ident » Thu Oct 02, 2014 09:34

This needs to be added to the docu. Thanks.

http://cegui.org.uk/mantis/view.php?id=1054
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests