Copy All Properties

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

daves
Home away from home
Home away from home
Posts: 253
Joined: Thu Feb 02, 2006 20:12

Copy All Properties

Postby daves » Fri Apr 11, 2008 19:57

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.

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Fri Apr 11, 2008 20:34

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++;
   }
}

daves
Home away from home
Home away from home
Posts: 253
Joined: Thu Feb 02, 2006 20:12

Postby daves » Tue Apr 15, 2008 12:32

Thanks Rackle.
Giving this a try... Is this something you already had in your bag of tricks?

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Tue Apr 15, 2008 16:52

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

daves
Home away from home
Home away from home
Posts: 253
Joined: Thu Feb 02, 2006 20:12

Postby daves » Tue Apr 15, 2008 18:34

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.

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Tue Apr 22, 2008 14:12

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 :)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 10 guests