Page 1 of 1

Creates Imagesets "on the fly" ... and destroy them?

Posted: Wed Apr 04, 2012 11:57
by matt
Hello!

I need to creates some buttons "on the fly", and these buttons display images that are stored in a folder of my project.
I can't use some ".imageset" file, because it's totally dynamic.

So the solution I've found is to create an imageset, define an image that is 100%*100% of this imageset, and bind this image to my widget.
Is it the fastiest way to acheive it?

I do like that:

Code: Select all

      CustomButton* button = static_cast<CustomButton*>(wmgr.createWindow( "MyWidgets/CustomButton" ));

      try
      {
         std::string imageSetName(button->getName().c_str());  //Define a unique imageSet using the unique name of the button given my the WindowManager
         std::string imageURL(button->getIdStr().c_str());     //This custom property is my Image URL
         //Creates an imageset, and a 100%*100% image
         CEGUI::Imageset& imageSet = CEGUI::ImagesetManager::getSingleton().createFromImageFile(imageSetName,imageURL,"");   
         imageSet.defineImage("fullimage", Point(0.0f,0.0f), imageSet.getNativeResolution(), Point(0.0f,0.0f));
         //Bind the image the widget
         button->setProperty("NormalImage", String("set:")+ imageSetName +" image:fullimage");
      }
      catch( CEGUI::FileIOException &e )
      {      
         CEGUI::Logger::getSingleton().logEvent(e.getFullDescription() + " : " + e.getFile());
         //Use a common image, is the URL of the image is wrong
         item->setProperty( "NormalImage", "set:MyIcons image:dummyImage" );    
      }   


But I regularly need to destroy my widgets, and I don't know if the ImageSets that are bound to are also destroyed ?
Do I need to manage Imageset destruction, to remove the textures from the memory?

Re: Creates Imagesets "on the fly" ... and destroy them?

Posted: Wed Apr 04, 2012 21:08
by Kulik
In 0.7 creating Imagesets with full rectangle images on them is the only way unfortunately.

You have to destroy the imagesets after use, they are not garbage collected automatically.

Re: Creates Imagesets "on the fly" ... and destroy them?

Posted: Thu Apr 05, 2012 14:00
by matt
Thanx Kulik for this short and explicit answer! :)