bool
CFormBackendImp::LoadLayout( GUCEF::CORE::CIOAccess& layoutStorage )
{GUCE_TRACE;
    
    CEGUI::Window* rootWindow = NULL;
    CEGUI::WindowManager* wmgr = CEGUI::WindowManager::getSingletonPtr();
    
    GUCEF_DEBUG_LOG( 0, "Starting layout load for a GUI Form" );
    
    try
    {
        // provide hacky access to the given data
        m_dummyArchive->AddResource( layoutStorage, "currentFile" );

        // Now we can load the window layout from the given storage
        // Note that if CEGUI ever provides an interface to do this directly
        // clean up this mess !!!
        rootWindow = wmgr->loadWindowLayout( "currentFile"                  , 
                                             m_widgetNamePrefix.C_String()  ,
                                             m_resourceGroupName.C_String() );     
        m_dummyArchive->ClearResourceList();
    }
    catch ( Ogre::Exception& e )
    {
        GUCEF_ERROR_LOG( 0, CString( "Ogre Exception while attempting to load form layout: " ) + e.getFullDescription().c_str() );
        return false;
    }
    
    // Now that we completed loading lets see what we got from CEGUI
    if ( NULL != rootWindow )
    {
        // Begin by providing a wrapper for the root window
        m_rootWindow = CreateAndHookWrapperForWindow( rootWindow );
        if ( NULL != m_rootWindow )
        {
            CString localWidgetName = m_rootWindow->GetName().SubstrToChar( '/', false );
            m_widgetMap[ localWidgetName ] = m_rootWindow;
            WrapAndHookChildWindows( rootWindow );
            
            // We will directly add the form as a child of the root for now
            CEGUI::Window* globalRootWindow = wmgr->getWindow( "root" );
            if ( NULL != globalRootWindow )
            {
                globalRootWindow->addChildWindow( rootWindow );
                
                GUCEF_DEBUG_LOG( 0, "Successfully loaded a GUI Form layout" );
                return true;                
            }
            else
            {
                GUCEF_ERROR_LOG( 0, "Failed to add form as a child to the global \"root\" window" );    
            }
        }
        rootWindow->hide();
    }

    GUCEF_DEBUG_LOG( 0, "Failed to loaded a GUI Form layout" );
    return false; 
}
LoginScreenInterface::LoginScreenInterface(){
#ifdef WITH_CEGUI_SUPPORT
    CEGUI::WindowManager *wmanager = CEGUI::WindowManager::getSingletonPtr();

    m_LoginScreenWindow = wmanager->loadWindowLayout(
        "loginscreen.layout",
        ""
    );

    if (m_LoginScreenWindow)
    {
        CEGUI::System::getSingleton().getGUISheet()->addChildWindow(m_LoginScreenWindow);
    }
#endif
}
Exemple #3
0
bool StartMe::Application()
{
  // Set up window transparency. Must happen _before_ system is opened!
  csRef<iGraphics2D> g2d = csQueryRegistry<iGraphics2D> (GetObjectRegistry ());
  if (!g2d) return ReportError ("Failed to obtain canvas!");
  natwin = scfQueryInterface<iNativeWindow> (g2d);
  if (natwin)
  {
    natwin->SetWindowTransparent (true);
  }

  // Open the main system. This will open all the previously loaded plug-ins.
  // i.e. all windows will be opened.
  if (!OpenApplication(GetObjectRegistry()))
    return ReportError("Error opening system!");

  // The window is open, so lets make it disappear! 
  if (natwin)
  {
    natwin->SetWindowDecoration (iNativeWindow::decoCaption, false);
    natwin->SetWindowDecoration (iNativeWindow::decoClientFrame, false);
  }

  // Now get the pointer to various modules we need. We fetch them
  // from the object registry. The RequestPlugins() call we did earlier
  // registered all loaded plugins with the object registry.
  g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry());
  if (!g3d) return ReportError("Failed to locate 3D renderer!");

  engine = csQueryRegistry<iEngine> (GetObjectRegistry());
  if (!engine) return ReportError("Failed to locate 3D engine!");

  vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry());
  if (!vc) return ReportError("Failed to locate Virtual Clock!");

  kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry());
  if (!kbd) return ReportError("Failed to locate Keyboard Driver!");

  loader = csQueryRegistry<iLoader> (GetObjectRegistry());
  if (!loader) return ReportError("Failed to locate Loader!");

  vfs = csQueryRegistry<iVFS> (GetObjectRegistry());
  if (!vfs) return ReportError("Failed to locate VFS!");

  confman = csQueryRegistry<iConfigManager> (GetObjectRegistry());
  if (!confman) return ReportError("Failed to locate Config Manager!");

  cegui = csQueryRegistry<iCEGUI> (GetObjectRegistry());
  if (!cegui) return ReportError("Failed to locate CEGUI plugin");

  // Initialize the CEGUI wrapper
  cegui->Initialize ();
  
  // Let the CEGUI plugin take care of the rendering by itself
  cegui->SetAutoRender (true);
  
  // Set the logging level
  cegui->GetLoggerPtr ()->setLoggingLevel(CEGUI::Informative);

  vfs->ChDir ("/cegui/");

  // Load the 'ice' skin (which uses the Falagard skinning system)
  cegui->GetSchemeManagerPtr ()->create("ice.scheme");

  cegui->GetSystemPtr ()->setDefaultMouseCursor("ice", "MouseArrow");

  // Setup the fonts
  cegui->GetFontManagerPtr ()->createFreeTypeFont
    (FONT_NORMAL, 10, true, "/fonts/ttf/DejaVuSerif.ttf");
  cegui->GetFontManagerPtr ()->createFreeTypeFont
    (FONT_NORMAL_ITALIC, 10, true, "/fonts/ttf/DejaVuSerif-Italic.ttf");
  cegui->GetFontManagerPtr ()->createFreeTypeFont
    (FONT_TITLE, 15, true, "/fonts/ttf/DejaVuSerif-Bold.ttf");
  cegui->GetFontManagerPtr ()->createFreeTypeFont
    (FONT_TITLE_ITALIC, 15, true, "/fonts/ttf/DejaVuSerif-BoldItalic.ttf");

  CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr ();

  // Load the CEGUI layout and set it as the root layout
  vfs->ChDir ("/data/startme/");
  cegui->GetSchemeManagerPtr ()->create ("crystal.scheme");
  cegui->GetSystemPtr ()->setGUISheet(winMgr->loadWindowLayout ("startme.layout"));

  // We need a View to the virtual world.
  view.AttachNew (new csView (engine, g3d));

  LoadConfig ();

  CEGUI::Window* logo = winMgr->getWindow("Logo");
  logo->subscribeEvent(CEGUI::Window::EventMouseClick,
      CEGUI::Event::Subscriber(&StartMe::OnLogoClicked, this));

  ///TODO: Using 'EventMouseEntersArea' is more correct but is only available 
  /// in 0.7.2+
  logo->subscribeEvent(CEGUI::Window::EventMouseEnters,
      CEGUI::Event::Subscriber(&StartMe::OnEnterLogo, this));
  logo->subscribeEvent(CEGUI::Window::EventMouseLeaves,
      CEGUI::Event::Subscriber(&StartMe::OnLeaveLogo, this));

  vfs->ChDir ("/lib/startme");

  CEGUI::Window* root = winMgr->getWindow("root");

  for (size_t i = 0 ; i < demos.GetSize () ; i++)
  {
    demos[i].window = winMgr->createWindow("crystal/Icon");
    demos[i].window->setSize(CEGUI::UVector2(CEGUI::UDim(0.0f, 128.0f), CEGUI::UDim(0.0f, 128.0f)));
    demos[i].window->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0f, 0.0f), CEGUI::UDim(0.0f, 0.0f)));
    demos[i].window->setVisible(false);

    CEGUI::ImagesetManager* imsetmgr = cegui->GetImagesetManagerPtr();
    if (!imsetmgr->isDefined(demos[i].image))
      imsetmgr->createFromImageFile(demos[i].image, demos[i].image);
    std::string img = "set:"+std::string(demos[i].image)+" image:full_image";
    demos[i].window->setProperty("Image", img);

    root->addChildWindow(demos[i].window);

    demos[i].window->subscribeEvent(CEGUI::Window::EventMouseClick,
      CEGUI::Event::Subscriber(&StartMe::OnClick, this));
  }

  // Initialize the starting position of the demo wheel to a random value
  csRandomFloatGen frandomGenerator;
  position = frandomGenerator.Get (demos.GetSize () - 1);

  // Let the engine prepare everything
  engine->Prepare ();
  printer.AttachNew (new FramePrinter (object_reg));

  // This calls the default runloop. This will basically just keep
  // broadcasting process events to keep the application going on.
  Run();

  return true;
}
bool CEGUITest::Application()
{
  if (!OpenApplication(GetObjectRegistry()))
    return ReportError("Error opening system!");

  vfs = csQueryRegistry<iVFS> (GetObjectRegistry());
  if (!vfs) return ReportError("Failed to locate VFS!");

  g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry());
  if (!g3d) return ReportError("Failed to locate 3D renderer!");

  engine = csQueryRegistry<iEngine> (GetObjectRegistry());
  if (!engine) return ReportError("Failed to locate 3D engine!");

  vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry());
  if (!vc) return ReportError("Failed to locate Virtual Clock!");

  kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry());
  if (!kbd) return ReportError("Failed to locate Keyboard Driver!");

  loader = csQueryRegistry<iLoader> (GetObjectRegistry());
  if (!loader) return ReportError("Failed to locate Loader!");

  cegui = csQueryRegistry<iCEGUI> (GetObjectRegistry());
  if (!cegui) return ReportError("Failed to locate CEGUI plugin");

  // Initialize CEGUI wrapper
  cegui->Initialize ();
  
  /* Let CEGUI plugin install an event handler that takes care of rendering
     every frame */
  cegui->SetAutoRender (true);
  
  // Set the logging level
  cegui->GetLoggerPtr ()->setLoggingLevel(CEGUI::Informative);

  vfs->ChDir ("/cegui/");

  // Load the ice skin (which uses Falagard skinning system)
  cegui->GetSchemeManagerPtr ()->create("ice.scheme");

  cegui->GetSystemPtr ()->setDefaultMouseCursor("ice", "MouseArrow");

  cegui->GetFontManagerPtr ()->createFreeTypeFont("DejaVuSans", 10, true, "/fonts/ttf/DejaVuSans.ttf");

  CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr ();

  // Load layout and set as root
  vfs->ChDir ("/ceguitest/");
  cegui->GetSystemPtr ()->setGUISheet(winMgr->loadWindowLayout("ice.layout"));

  // Subscribe to the clicked event for the exit button
  CEGUI::Window* btn = winMgr->getWindow("Demo7/Window1/Quit");
  btn->subscribeEvent(CEGUI::PushButton::EventClicked,
    CEGUI::Event::Subscriber(&CEGUITest::OnExitButtonClicked, this));

  // These are used store the current orientation of the camera.
  rotY = rotX = 0;

  view.AttachNew(new csView (engine, g3d));
  iGraphics2D* g2d = g3d->GetDriver2D ();
  view->SetRectangle(0, 0, g2d->GetWidth(), g2d->GetHeight ());

  printer.AttachNew (new FramePrinter (object_reg));

  CreateRoom();
  view->GetCamera()->SetSector (room);
  view->GetCamera()->GetTransform().SetOrigin(csVector3 (0, 5, 0));

  Run();

  return true;
}