Popup Menu

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

rtr_18
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Mon Aug 25, 2008 10:02

Popup Menu

Postby rtr_18 » Tue Sep 09, 2008 09:33

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?

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Tue Sep 09, 2008 13:18

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.
Check out my released snake game using Cegui!

rtr_18
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Mon Aug 25, 2008 10:02

Postby rtr_18 » Wed Sep 10, 2008 10:04

Thank u. It's working now.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 5 guests