Page 1 of 1

Popup Menu

Posted: Tue Sep 09, 2008 09:33
by rtr_18
Hi!
I've used the following code to create a Popup Menu when 'F1' Key is pressed.

Code: Select all


 bool KeyPressed(const dtCore::Keyboard* keyboard, int key)
{
  switch( key )
  {
   case osgGA::GUIEventAdapter::KEY_F1:
   {
     try
     {
       menu1 = static_cast<CEGUI::PopupMenu*>(wm->createWindow  ("WindowsLook/PopupMenu", "help"));
       mWindowBackground->addChildWindow(menu1);
       menu1->setFadeInTime(0.1f);
       menu1->setFadeOutTime(3.0f);
      }
      catch(CEGUI::Exception &e)
      {
        Log::GetInstance().LogMessage(Log::LOG_WARNING, __FUNCTION__,
            "CEGUI::%s", e.getMessage().c_str() );
      }
    }
   }
 }



But if I press 'F1' Key, the following error message is displayed in the console Window and Popup Menu is not displayed:


Warn: 14:58:10:<TestGUIApp::KeyPressed>CEGUI::WindowManager::createWindow - A Winodow object with the name already exists with in the system.

What to do?

Posted: Tue Sep 09, 2008 13:18
by scriptkid
Hi,

you should only create windows once (if you don't destroy them). This probably happens because the 'keypressed' event is called a few times. Change your code to something like:

Code: Select all

if (wm->isWindowPresent("help"))
{ // Reuse
  menu1 = static_cast<CEGUI::PopupMenu*>(wm->getWindow("help"));
}
else
{ // Create
  menu1 = static_cast<CEGUI::PopupMenu*>(wm->createWindow  ("WindowsLook/PopupMenu", "help"));
}


HTH.

Posted: Wed Sep 10, 2008 10:04
by rtr_18
Thank u. It's working now.