CEGUI::PushButton button hold event

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

CEGUI::PushButton button hold event

Postby sabotage3d » Sat Oct 04, 2014 11:22

Hello ,

Is there an event with CEGUI::PushButton that can execute the callback while the button is being pressed but not released, just holding the button down. For example if you want to control a camera moving forward you would want to press the button and keep holding it to move properly. At the moment I am getting callback only after the button is being pressed but not while I am holding the button down.

Update: I found that I can use EventCursorPressHold. This is how I am doing it at the moment but it seems messy and the one thing that doesn't work is when I have pressed the button but I move my cursor outside of the button I cannot stop the event I tried using EventInputCaptureLost, EventCursorLeavesArea, EventCursorLeavesSurface but all of them work only when the EventCursorPressHold has finished. Is there a way to execute two events at the same time maybe ?
It seems that when I have two buttons with events if you try and press them at the same time it doesn't work the Event::Subscriber is waiting for the first event to finish before it executes the second button event.

Code: Select all

//CEGUI events subscribers

 button->subscribeEvent(CEGUI::PushButton::EventCursorPressHold, CEGUI::Event::Subscriber(&OgreFramework::mMoveForward, this));
 button->subscribeEvent(CEGUI::PushButton::EventInputCaptureLost ,CEGUI::Event::Subscriber(&OgreFramework::mStopMovement, this));


//Movement

void OgreFramework::moveCamera()
{
    m_pCamera2->moveRelative(m_TranslateVector / 10);
   
}


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

{
    bMoveForward = true;
    return true;
}

bool OgreFramework::mStopMovement(const CEGUI::EventArgs &e)
{
    bMoveForward = false;
    return true;
}


void OgreFramework::TranslateCamera()
{
   
    if(bMoveForward) m_TranslateVector.z = -m_MoveScale ;
}

//Update

void OgreFramework::updateOgre(double timeSinceLastFrame)
{
   m_MoveScale = m_MoveSpeed   * (float)timeSinceLastFrame;
   m_RotScale  = m_RotateSpeed * (float)timeSinceLastFrame;
    m_TranslateVector = Vector3::ZERO;
   
    TranslateCamera();
   moveCamera();
   
   m_FrameEvent.timeSinceLastFrame = timeSinceLastFrame;
    CEGUI::System::getSingleton().injectTimePulse(timeSinceLastFrame);
}

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

Re: CEGUI::PushButton button hold event

Postby Ident » Tue Oct 07, 2014 06:58

Can you show us your layout? Is the button the root window?
CrazyEddie: "I don't like GUIs"

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

Re: CEGUI::PushButton button hold event

Postby sabotage3d » Wed Oct 08, 2014 19:21

I have updated my code a bit. The main issue is I cannot get any release button event from CEGUI so I am doing some trickery which is a bit buggy at the moment as if I press a button it displays as it is still pressed. Also it seems events are waiting for other events to finish before they call the callback.


Code: Select all

CEGUI::OgreRenderer* renderer = &CEGUI::OgreRenderer::bootstrapSystem(*m_pRenderWnd);

CEGUI::SchemeManager::getSingleton().createFromFile("OgreTray.scheme");
guiRoot = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "_MasterRoot");
CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(guiRoot);

buttonForward = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","PushButton"));
buttonForward->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0.8,0)));
buttonForward->setSize(CEGUI::USize(CEGUI::UDim(0,150),CEGUI::UDim(0,70)));
buttonForward->setText("Forward");
buttonForward->subscribeEvent(CEGUI::PushButton::EventCursorPressHold, CEGUI::Event::Subscriber(&OgreFramework::mMoveForward, this));
buttonForward->subscribeEvent(CEGUI::PushButton::EventInputCaptureLost ,CEGUI::Event::Subscriber(&OgreFramework::mStopMovement, this));

buttonShoot = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","ShootPushButton"));
buttonShoot->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5,0),CEGUI::UDim(0.8,0)));
buttonShoot->setSize(CEGUI::USize(CEGUI::UDim(0,150),CEGUI::UDim(0,70)));
buttonShoot->setText("Shoot");
buttonShoot->subscribeEvent(CEGUI::PushButton::EventCursorPressHold, CEGUI::Event::Subscriber(&OgreFramework::mShoot, this));
buttonShoot->subscribeEvent(CEGUI::PushButton::EventInputCaptureLost ,CEGUI::Event::Subscriber(&OgreFramework::mStopShoot, this));

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



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;

    //bMoveForward = false;
    d_systemInputAggregator->injectMouseButtonUp( CEGUI::LeftButton);
}




void OgreFramework::moveCamera()
{
    m_pCamera2->moveRelative(m_TranslateVector / 10);
}



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

{
    bMoveForward = true;
    return true;
}

bool OgreFramework::mStopMovement(const CEGUI::EventArgs &e)
{
    bMoveForward = false;

}


void OgreFramework::TranslateCamera()
{
   
    if(bMoveForward) m_TranslateVector.z = -m_MoveScale ;
}



void OgreFramework::updateOgre(double timeSinceLastFrame)
{
    m_MoveScale = m_MoveSpeed   * (float)timeSinceLastFrame;
    m_RotScale  = m_RotateSpeed * (float)timeSinceLastFrame;


    m_TranslateVector = Vector3::ZERO;
   

    TranslateCamera();
    moveCamera();
   
    m_FrameEvent.timeSinceLastFrame = timeSinceLastFrame;
    CEGUI::System::getSingleton().injectTimePulse(timeSinceLastFrame);
}

bool OgreFramework::mShoot(const CEGUI::EventArgs &e)
{
    bShoot = true;
}

bool OgreFramework::mStopShoot(const CEGUI::EventArgs &e)
{
    bShoot = false;
}

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

Re: CEGUI::PushButton button hold event

Postby Ident » Thu Oct 09, 2014 16:12

You are not returning false in your event handlers. In fact you are returning nothing although the return type is bool. Does that even compile?
CrazyEddie: "I don't like GUIs"

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

Re: CEGUI::PushButton button hold event

Postby sabotage3d » Fri Oct 10, 2014 22:52

Sorry about that I was editing the code and I removed them accidentally. There should be just return true on all the bool functions.
For some reason the buttons animation stays pressed even if the mouse is released and no longer on the button. Until I click somewhere outside the button than its is back into normal state.

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

Re: CEGUI::PushButton button hold event

Postby Ident » Sat Oct 11, 2014 08:05

There should be return false.
CrazyEddie: "I don't like GUIs"

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

Re: CEGUI::PushButton button hold event

Postby sabotage3d » Sat Oct 11, 2014 11:55

I am confused why do we want them to return false. Does it actually matter or I am missing something.
In these functions are setting seperate bool flags anyway, CEGUI is only calling these functions or it is doing something else ?

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

Re: CEGUI::PushButton button hold event

Postby Ident » Sat Oct 11, 2014 12:06

Read the docu on what the return values do.


Have you tried out returning false and did you see any change?
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 13 guests