Page 1 of 1

How to clone/copy windows

Posted: Wed Dec 16, 2009 21:14
by tedlin01
hello!
I am trying to do such a basic thing as copying a window. How do I do it? :O
I have a CEGUI::Pushbutton that I want to duplicate.

Re: How to clone/copy windows

Posted: Thu Dec 17, 2009 10:58
by scriptkid
Hi,

Such a basic thing is not possible out of the box ;) You'd need a copy method which copies all your properties and such. Something like this:

Code: Select all

//------------------------------------------------------------------------
Window* CopyWindow( const CEGUI::Window* pSource )
{
    // create window of same type, but different name
    Window* copy = CEGUI::WindowManager::getSingleton().createWindow(pSource->getType(), pSource->getName() + "_copy");

    // Copy the properties
    CEGUI::PropertySet::Iterator propertyIt = pSource->getPropertyIterator();

    while (!propertyIt.isAtEnd())
    {
      const CEGUI::String propertyName = propertyIt.getCurrentKey();
      copy->setProperty(propertyName,  pSource->getProperty(propertyName));
      propertyIt++;
   }
   return copy;
}


This should compile pretty well i hope :) Of course, wrap some try-catch handlers and all that. And maybe you want an argument to specify your own copy name, instead my "_copy" example. Copying properties like this is more expensive then copying members, but this is the most generic, since different window types support different kinds of properties.

HTH.

Re: How to clone/copy windows

Posted: Wed Apr 07, 2010 18:09
by Sairon
As this is something which is rather common, have there been any thoughts of adding a clone() member to CEGUI::Window?

Re: How to clone/copy windows

Posted: Mon Apr 12, 2010 08:40
by CrazyEddie
I have not given it any thought, no. I'll add a ticket for a feature request.

CE.