This is my keypressed handler. Pressing escape should toggle the menubar:
Code: Select all
bool BasicTutorial7::keyPressed(const OIS::KeyEvent &arg)
{
   CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();
   context.injectKeyDown((CEGUI::Key::Scan)arg.key);
   context.injectChar((CEGUI::Key::Scan)arg.text);
   if (arg.key == OIS::KC_ESCAPE)
   {
      if (context.getRootWindow()->getChild("Menubar")->isVisible())
         context.getRootWindow()->getChild("Menubar")->hide();
      else
         context.getRootWindow()->getChild("Menubar")->show();
   }
   mCameraMan->injectKeyDown(arg);
   return true;
}
This is my initialisation. I create 3 buttons in code, load the menu from layout:
Code: Select all
   mRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
   CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets");
   CEGUI::Font::setDefaultResourceGroup("Fonts");
   CEGUI::Scheme::setDefaultResourceGroup("Schemes");
   CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
   CEGUI::WindowManager::setDefaultResourceGroup("Layouts");
   CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
   CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
   CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
   CEGUI::Window *sheet = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet");
   // button
   CEGUI::Window *quit = wmgr.createWindow("TaharezLook/Button", "CEGUIDemo/QuitButton");
   quit->setText("Quit");
   quit->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0.05, 0)));
   quit->setSize(CEGUI::USize(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   sheet->addChild(quit);
   // button
   CEGUI::Window *showbtn = wmgr.createWindow("TaharezLook/Button", "CEGUIDemo/ShowButton");
   showbtn->setText("Show");
   showbtn->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0.10, 0)));
   showbtn->setSize(CEGUI::USize(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   sheet->addChild(showbtn);
   // button
   CEGUI::Window *hidebtn = wmgr.createWindow("TaharezLook/Button", "CEGUIDemo/ShowButton");
   hidebtn->setText("Hide");
   hidebtn->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0.15, 0)));
   hidebtn->setSize(CEGUI::USize(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   sheet->addChild(hidebtn);
   CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(sheet);
   quit->subscribeEvent(CEGUI::PushButton::EventClicked,
      CEGUI::Event::Subscriber(&BasicTutorial7::quit, this));
   showbtn->subscribeEvent(CEGUI::PushButton::EventClicked,
      CEGUI::Event::Subscriber(&BasicTutorial7::showWindow, this));
   hidebtn->subscribeEvent(CEGUI::PushButton::EventClicked,
      CEGUI::Event::Subscriber(&BasicTutorial7::hideWindow, this));
   // Load a layout
   // menu code based from http://cegui.org.uk/wiki/Menu_and_Popup
   CEGUI::Window* guiLayout = CEGUI::WindowManager::getSingleton().loadLayoutFromFile("test1.layout");
   guiLayout->setVisible(false);
   sheet->addChild(guiLayout);
   // subscribe events
   CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->getChild("Menubar/MenuItem_opt1/PopupMenu/MenuItem_show")->subscribeEvent(CEGUI::MenuItem::EventClicked,
      CEGUI::Event::Subscriber(&BasicTutorial7::onMenuItemClicked, this));
   CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->getChild("Menubar/MenuItem_opt1/PopupMenu/MenuItem_hide")->subscribeEvent(CEGUI::MenuItem::EventClicked,
      CEGUI::Event::Subscriber(&BasicTutorial7::onMenuItemClicked, this));
   CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->getChild("Menubar/MenuItem_opt1/PopupMenu/MenuItem_quit")->subscribeEvent(CEGUI::MenuItem::EventClicked,
      CEGUI::Event::Subscriber(&BasicTutorial7::onMenuItemClicked, this));
Nothing crazy in test1.layout:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<GUILayout version="4" >
    <Window type="TaharezLook/Menubar" name="Menubar" >
        <Property name="Area" value="{{0,0},{0,0},{1,0},{0,32}}" />
        <Window type="TaharezLook/MenuItem" name="MenuItem_opt1" >
            <Property name="Area" value="{{0,7},{0,0},{0,67},{0,19}}" />
            <Property name="Text" value="Option 1" />
            <Property name="VerticalAlignment" value="Centre" />
            <Window type="TaharezLook/PopupMenu" name="PopupMenu" >
                <Property name="Area" value="{{0,0},{0,0},{0,106},{0,66.6386}}" />
                <Property name="Visible" value="false" />
                <Property name="ItemSpacing" value="2" />
                <Property name="ClippedByParent" value="false" />
                <Property name="AutoResizeEnabled" value="true" />
                <Window type="TaharezLook/MenuItem" name="MenuItem_show" >
                    <Property name="Area" value="{{0,4},{0,4},{0,103},{0,22}}" />
                    <Property name="Text" value="Show Window" />
                </Window>
                <Window type="TaharezLook/MenuItem" name="MenuItem_hide" >
                    <Property name="Area" value="{{0,4},{0,24},{0,103},{0,42}}" />
                    <Property name="Text" value="Hide Window" />
                </Window>
                <Window type="TaharezLook/MenuItem" name="MenuItem_quit" >
                    <Property name="Area" value="{{0,4},{0,44},{0,103},{0,62}}" />
                    <Property name="Text" value="Quit" />
                </Window>
            </Window>
        </Window>
        <Window type="TaharezLook/MenuItem" name="MenuItem_opt2" >
            <Property name="Area" value="{{0,77},{0,0},{0,137},{0,19}}" />
            <Property name="Text" value="Option 2" />
            <Property name="VerticalAlignment" value="Centre" />
            <Window type="TaharezLook/PopupMenu" name="PopupMenu" >
                <Property name="Area" value="{{0,0},{0,0},{0,92},{0,46.1591}}" />
                <Property name="Visible" value="false" />
                <Property name="ItemSpacing" value="2" />
                <Property name="ClippedByParent" value="false" />
                <Property name="AutoResizeEnabled" value="true" />
                <Window type="TaharezLook/MenuItem" name="MenuItem" >
                    <Property name="Area" value="{{0,4},{0,4},{0,89},{0,22}}" />
                    <Property name="Text" value="menu item 1" />
                </Window>
                <Window type="TaharezLook/MenuItem" name="MenuItem2" >
                    <Property name="Area" value="{{0,4},{0,24},{0,89},{0,42}}" />
                    <Property name="Text" value="menu item 2" />
                </Window>
            </Window>
        </Window>
    </Window>
</GUILayout>
Do I need to do something to force the CEGUI screen refresh?
Interestingly, if I call hide() from onMenuItemClicked handler, it works as expected.
Here it is for good measure:
Code: Select all
bool BasicTutorial7::onMenuItemClicked(const CEGUI::EventArgs& e)
{
   const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(e);
   CEGUI::String senderID = we.window->getName();
   if (senderID == "MenuItem_show")
   {
      // do something
   }
   else if (senderID == "MenuItem_hide")
   {
      // do something different
   }
   else if (senderID == "MenuItem_quit")
   {
      mShutDown = true;
   }
   CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->getChild("Menubar")->hide();
   return true;
}
If you can help me
 please let me know if you need I will post more info.
 please let me know if you need I will post more info.Ogre v1.9
CEGUI 0.8.4
Windows 7
Visual Studio 2015

