How to clone/copy windows

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

tedlin01
Just popping in
Just popping in
Posts: 12
Joined: Wed Apr 29, 2009 19:22

How to clone/copy windows

Postby tedlin01 » Wed Dec 16, 2009 21:14

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.

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:

Re: How to clone/copy windows

Postby scriptkid » Thu Dec 17, 2009 10:58

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

Sairon
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Sun Dec 07, 2008 01:11

Re: How to clone/copy windows

Postby Sairon » Wed Apr 07, 2010 18:09

As this is something which is rather common, have there been any thoughts of adding a clone() member to CEGUI::Window?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: How to clone/copy windows

Postby CrazyEddie » Mon Apr 12, 2010 08:40

I have not given it any thought, no. I'll add a ticket for a feature request.

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 6 guests