Page 1 of 1

How to properly load and destroy layouts...?

Posted: Sat Apr 30, 2005 04:11
by Rayoom
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

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

Posted: Sat Apr 30, 2005 09:27
by daesdemon
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 ;)