Window::isCapturedByChild 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

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Window::isCapturedByChild not working?

Postby Van » Sun Feb 26, 2006 21:07

I have a window (Static Image) where it has subscribed to the "Mouse Enters" and "Mouse Leaves" events. Works great accept when the mouse is hovering over a child (Push Button) of this parent window.

I have in the MouseLeaves event this:

Code: Select all


// Simple hide the menu routine
bool clsGUIStation::eventMenuMouseLeaves(const CEGUI::EventArgs& e)
{
   if ( mGUIMenu->isCapturedByChild() ) return true;
   mGUIMenu->setPosition( CEGUI::Point( 0.98f, mMenuOpenPos.d_y) );
   return true;
} // eventMenuMouseLeaves



Except, isCapturedByChild() is not returning true even though the mouse is hovering over a child button of this window. Is this a bug or am I not using the correct function?

Oh, running CEGUI 0.4.1 on Ogre Dagon.

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

Postby CrazyEddie » Mon Feb 27, 2006 10:02

The mouse is said to be 'captured' when some window decides that it needs to track all mouse inputs for some reason; a typical example would be the 'thumb' button in sliders and scrollbars, when you are dragging the thumb around, it has the mouse captured so all inputs go to the thumb instead of other windows that the mouse might be over (which would result in undesired behaviour).

To find out if the mouse cursor is just hovering (that is, without the left mouse button pushed, which would cause capture to occur) within a child of a given window, you need to obtain the window where the mouse is positioned:

Code: Select all

Window* wnd = CEGUI::System::getSingleton().getWindowContainingMouse();


and then discover whether the window returned is a child of your window:

Code: Select all

bool result = isChild(wnd);


HTH

CE.

User avatar
martignasse
Just can't stay away
Just can't stay away
Posts: 227
Joined: Thu Apr 14, 2005 08:10
Location: Lyon, FRANCE

Postby martignasse » Mon Feb 27, 2006 11:03

hi van,

Except, isCapturedByChild() is not returning true even though the mouse is hovering over a child button of this window. Is this a bug or am I not using the correct function?
from the API Reference, it should return true if a child "has captured the inputs", and not when mouse is hovering a child.

hope it help.

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Mon Feb 27, 2006 13:50

Thank you both for your replys,

CE,

I did what you said but I still get the same problem:

Here is the init code

Code: Select all


   mGUIMenu = static_cast<CEGUI::Window*>( mWinMgr.getWindow( (CEGUI::utf8*) "Station/Menu") );
   mGUIMenu->subscribeEvent( CEGUI::Window::EventMouseEnters, CEGUI::Event::Subscriber( &clsGUIStation::eventMenuMouseEnters, this ) );
   mGUIMenu->subscribeEvent( CEGUI::Window::EventMouseLeaves, CEGUI::Event::Subscriber( &clsGUIStation::eventMenuMouseLeaves, this ) );
   mMenuOpenPos = mGUIMenu->getPosition();

   // create buttons

   // ****************************************
   // Main Menu Items

   mPBMainHangar = (CEGUI::PushButton*) mWinMgr.createWindow( (CEGUI::utf8*) CEGUILOOK"/Button", "Station/Button/Hangar" );
   mGUIMenu->addChildWindow( mPBMainHangar );
   mPBMainHangar->setText( (CEGUI::utf8*) "Hangar" );
   mPBMainHangar->setTooltipText("Display hangar menu.");
   mPBMainHangar->setInheritsAlpha( false );
   mPBMainHangar->setVisible( false );
   mPBMainHangar->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &clsGUIStation::eventMainHangar, this ) );



Here is the mouse leave code

Code: Select all


bool clsGUIStation::eventMenuMouseEnters(const CEGUI::EventArgs& e)
{
   mGUIMenu->setPosition( mMenuOpenPos );
   return true;
} // eventMenuMouseEnters


// Simple hide the menu routine
bool clsGUIStation::eventMenuMouseLeaves(const CEGUI::EventArgs& e)
{
   CEGUI::Window* mWnd = CEGUI::System::getSingleton().getWindowContainingMouse();
   if ( mWnd && mGUIMenu->isChild( mWnd ) ) return true;
   mGUIMenu->setPosition( CEGUI::Point( 0.98f, mMenuOpenPos.d_y ) );
   return true;
} // eventMenuMouseLeaves



isChild is still returning false. But, as you can see from the init code, the button is a Child of mGUIMenu

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Mon Feb 27, 2006 15:08

OK. We've looked into this issue and it has turned out that you have found a bug :) :(

The method 'getWindowContainingMouse' will only return the right window after the MouseLeave handler has been called.
The fix should be in anonymous cvs by wednesday.

If you cannot wait you can work around it by doing the handling in a MouseEnter handler that you subscribe to each button.
MouseEnter handlers get correct results for 'getWindowContainingMouse'.
Another approach to determine if the window is a child of your main menu window is to simply test the return value of 'getParent'. This is a little bit faster as well.

So... while the fix is being committed you can use a MouseEnter handler like this for your buttons:

Code: Select all

// Simple hide the menu routine
bool clsGUIStation::eventMenuButtonMouseEnters(const CEGUI::EventArgs& e)
{
   CEGUI::Window* mWnd = static_cast<const CEGUI::WindowEventArgs&>(e).window;
   if ( mWnd->getParent() == mGUIMenu ) return true;
   mGUIMenu->setPosition( CEGUI::Point( 0.98f, mMenuOpenPos.d_y ) );
   return true;
} // eventMenuButtonMouseEnters


HTH and thank you for finding this bug

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Wed Mar 01, 2006 14:06

Appears to be working correctly now! Thank you!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 18 guests