Page 1 of 1

Copy All Properties

Posted: Fri Apr 11, 2008 19:57
by daves
I have "template widgets" that I create within the layout editor. I then have a dynamic within my application which requires me to create a number of widgets that are "like the template". This means that most of the properties of these newly created widgets should be identical to the properties of the template. The number of properties that differ is a much shorter list than the number of properties that are the same.

For this reason I'd like to use a convenience function that copies all of the properties of the template window to the actual window.

The syntax would be something along the lines of:

Code: Select all

toWindow->copyProperties(fromWindow); // fromWindow must be of same type as toWindow


Does this kind of function exist? If not is there a simple way to construct it?
Thanks.

Posted: Fri Apr 11, 2008 20:34
by Rackle
This code should still work:

Code: Select all

void CloningSystem::copyProperties(CEGUI::Window* pSource, CEGUI::Window* pDestination)
{
   CEGUI::PropertySet::Iterator itPropertySet = ((CEGUI::PropertySet*) pSource)->getIterator();
   while (!itPropertySet.isAtEnd())
   {
      if (itPropertySet.getCurrentKey().length() != 0 // Key is valid (weird that it would not be valid but just in case)
         && pSource->getProperty( itPropertySet.getCurrentKey() ).length() != 0 // Ensures that the key has a value
         )
      {
         if( (itPropertySet.getCurrentKey().compare("LookNFeel") == 0
            && pDestination->getProperty(itPropertySet.getCurrentKey()).length() != 0)
            || (itPropertySet.getCurrentKey().compare("WindowRenderer") == 0
            && pDestination->getProperty(itPropertySet.getCurrentKey()).length() != 0)
            )
         {
            // This property has already been set so avoid generating an error
         }
         else
         {
            //CEGUI::Logger::getSingleton().logEvent(itPropertySet.getCurrentKey() + ": " + pSource->getProperty( itPropertySet.getCurrentKey() ), CEGUI::Informative);
            pDestination->setProperty(   itPropertySet.getCurrentKey(),
                                 pSource->getProperty( itPropertySet.getCurrentKey() ) );
         }
      }
      itPropertySet++;
   }
}

Posted: Tue Apr 15, 2008 12:32
by daves
Thanks Rackle.
Giving this a try... Is this something you already had in your bag of tricks?

Posted: Tue Apr 15, 2008 16:52
by Rackle
Yes, back when I was working on a drag and drop system. This feature was to handle the situation of dragging an item from a spellbook and dropping it on a toolbar. This required creating a copy of the spellbook item. And then I stopped having time and can't play anymore (i.e. program Cegui stuff). /sniff

Posted: Tue Apr 15, 2008 18:34
by daves
Cool..
The "spell book" stuff sounds like a feature from WoW (I'm a big fan of the flexibility within the WoW design). Interestingly CEGUI provides so much power in its flexibility that its easy to see how one can implement the kinds of flexible interfaces that you find in games like that.

Its funny, I'm not programming a game at all, but I go home every night and kid with my wife that "I've been programming games all day", since indeed the fundamental architectural elements are the same.


Sry to hear that time is such a crunch for you. Right now I'm having so much fun coding I'd hate to break away for any reason. I come in in the morning, put on my headset and start to listen to music, and just code away for the next 10 hours without ever wanting to take a break!!

Hope you get back into the fun stuff real soon.

Posted: Tue Apr 22, 2008 14:12
by Pompei2
daves wrote:Right now I'm having so much fun coding I'd hate to break away for any reason. I come in in the morning, put on my headset and start to listen to music, and just code away for the next 10 hours without ever wanting to take a break!!

hehehe u're really lucky :)