Page 1 of 1

[SOLVED]How to close a Menubar if capture is lost?

Posted: Tue Jan 29, 2013 19:05
by osbios
I like my Menubar to close if you click on anythink outside the menu. Like it is the default with many other GUIs.
I have the event function running when this happens, now I only need to find a function to close the CEGUI::Menubar.
Is there a function/way to do this?

Code: Select all

27/01/2013 20:04:21 (Std)    ---- Version 0.7.5 (Build: Apr 28 2012 GNU/Linux g++ 4.6.3 64 bit) ----
27/01/2013 20:04:21 (Std)    ---- Renderer module is: CEGUI::OpenGLRenderer - Official OpenGL based 2nd generation renderer module.  TextureTarget support enabled via FBO extension. ----
27/01/2013 20:04:21 (Std)    ---- XML Parser module is: CEGUI::ExpatParser - Official expat based parser module for CEGUI ----
27/01/2013 20:04:21 (Std)    ---- Image Codec module is: DevILImageCodec - Official DevIL based image codec ----
27/01/2013 20:04:21 (Std)    ---- Scripting module is: None ----

Re: How to close a Menubar if capture is lost?

Posted: Tue Jan 29, 2013 19:09
by Kulik
Are you absolutely sure you mean Menubar?

You probably want PopupMenu and this:
http://www.cegui.org.uk/docs/current/cl ... 9f4561ec3a

Re: How to close a Menubar if capture is lost?

Posted: Tue Jan 29, 2013 20:34
by osbios
Yes, I mean the Menubar. Like this:

Image

I would like any open Menu to close if I click in the grey array.

What would be the most elegant way to call closePopupMenu() on every PopupMenu except manually do it for each single one?

Re: How to close a Menubar if capture is lost?

Posted: Tue Jan 29, 2013 22:25
by osbios
Solved it:

Code: Select all

menubar->subscribeEvent(CEGUI::Window::EventDeactivated,
        CEGUI::Event::Subscriber(&CeguiIcaf::inputCaptureLost, this));


Code: Select all

bool CeguiIcaf::inputCaptureLost(const CEGUI::EventArgs& e)
{
    const ActivationEventArgs &f = dynamic_cast<const ActivationEventArgs&>(e);

    CEGUI::Menubar *m = dynamic_cast<CEGUI::Menubar*>(f.window);

    for (int i=0; i < m->getChildCount(); ++i)
    {
       CEGUI::MenuItem* child = dynamic_cast<MenuItem*>( m->getChildAtIdx( i ) );
       child->closePopupMenu();
    }

    return true;
}