How to properly load and destroy layouts...?

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
Rayoom
Just popping in
Just popping in
Posts: 11
Joined: Sat Apr 30, 2005 03:27
Contact:

How to properly load and destroy layouts...?

Postby Rayoom » Sat Apr 30, 2005 04:11

I've been using CEGUI for a few days now...so far I love it.

I ran into a problem with the layouts. I have 3 layouts and I'm trying to switch between them when the user clicks on certain buttons, and I'm getting crashes which I believe are caused because events are still being generated (or proccessed) for windows after I've deleted them with WindowManager::destroyAllWindows.

What is the proper what to load a layout, release it, and load a new one?

TIA

User avatar
daesdemon
Quite a regular
Quite a regular
Posts: 60
Joined: Fri Mar 11, 2005 21:19
Contact:

Re: How to properly load and destroy layouts...?

Postby daesdemon » Sat Apr 30, 2005 09:27

I would use that to destroy the layout:

Code: Select all

Window * mRoot; // Your Main window
Window *mLayout = 0; // Your Layout Window

onButtonPressed(const CEGUI::EventArgs& e)
{
    const WindowEventArgs& we = (const WindowEventArgs&)e;   
    switch(we.window->getname())
    {
    case BUTTON_NAME1:loadMyLayout(LAYOUT1_NAME);break;
    case BUTTON_NAME2:loadMyLayout(LAYOUT2_NAME);break;
    case BUTTON_NAME3:loadMyLayout(LAYOUT3_NAME);break;
    }   
}

loadMyLayout(const String& name)
{
    if (mLayout) WindowManager::getSingletonPtr()->destroyWindow(mLayout);
    mLayout = WindowManager::getSingletonPtr()->loadWindowLayout(name);
    mRoot->addChildWindow(mLayout);
}

but it would be probably better to do it like this:

Code: Select all

Window *mRoot; // Your Main window
Window* mLayout1 = WindowManager::getSingletonPtr()->loadWindowLayout(LAYOUT1_NAME);
Window* mLayout2 = WindowManager::getSingletonPtr()->loadWindowLayout(LAYOUT2_NAME);
Window* mLayout3 = WindowManager::getSingletonPtr()->loadWindowLayout(LAYOUT3_NAME);
mRoot->addChildWindow(mLayout1);
mRoot->addChildWindow(mLayout2);
mRoot->addChildWindow(mLayout3);

onButtonPressed(const CEGUI::EventArgs& e)
{
    const WindowEventArgs& we = (const WindowEventArgs&)e;   
    switch(we.window->getname())
    {
    case BUTTON_NAME1:displayMyLayout(1);break;
    case BUTTON_NAME2:displayMyLayout(2);break;
    case BUTTON_NAME3:displayMyLayout(3);break;
    }   
}

displayMyLayout(int i)
{
    switch(i)
    {
    case 1: mLayout1->setVisible(true);
            mLayout2->setVisible(false);
            mLayout3->setVisible(false);
            break;
    case 2: mLayout1->setVisible(false);
            mLayout2->setVisible(true);
            mLayout3->setVisible(false);
            break;
    case 3: mLayout1->setVisible(false);
            mLayout2->setVisible(false);
            mLayout3->setVisible(true);
            break;
    }

}


I haven't test that but it could work ;)


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 8 guests