Page 1 of 1

StaticImage - Loading/Setting background image

Posted: Fri Aug 19, 2005 11:01
by Van
Would someone please explain to me clearly how one goes about setting the background image of a window?

We have a StaticImage window with widgets. The goal is to change the StaticImage window background based on some criteria. I want to load the image from a file (like a png or jpg for example). What are the steps needed to accomplish this?

Re: StaticImage - Loading/Setting background image

Posted: Fri Aug 19, 2005 13:39
by CrazyEddie
The first thing you need in order to do this is an Imageset that defines the Image that you wish to use. When wanting to use an image file for this as you suggest, you basically have an imageset defined like this:

Code: Select all

<?xml version="1.0" ?>
<Imageset Name="BackdropImageset" Imagefile="backdrop.tga" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true">
   <Image Name="Backdrop" XPos="0" YPos="0" Width="1024" Height="768" />
</Imageset>


What this does is define an Imageset using the backdrop.tga. A single image "Backdrop" is defined that starts at location (0,0) and is 1024 x 768 in size. You should be careful in that the source image file should have dimensions that are powers of two - this is because the image is loaded as a texture, and may be stretched if the powers-of-two requirement is not observed.

Once you have your imageset defined, you can load it either by adding a reference to it in whichever scheme you are loading, or manually using the ImagesetManager:

Code: Select all

CEGUI::ImagesetManager::getSingleton().createImageset("myImageset.imagset");


Once the thing is loaded, you set the image into the StaticImage like so:

Code: Select all

myStaticImage->setImage("BackdropImageset", "Backdrop");


Notice that the names we specify here are the ones that were originally specified in the imageset XML file.

There are other ways of going about this, you can create the whole lot dynamically in code, though you have to provide a pre-loaded image as a texture - so the above is probably the easiest way at the moment.

In 0.4.0 there will be support for creating Imagesets directly from images (in fact I added in CVS earlier today).

HTH

CE.

Re: StaticImage - Loading/Setting background image

Posted: Fri Aug 19, 2005 20:07
by Van
Thanks Boss...

BTW, does the image have to be static as the widget name implies? That is could you use something like an animated gif?

Re: StaticImage - Loading/Setting background image

Posted: Sat Aug 20, 2005 18:09
by CrazyEddie
Currently it needs to be static. CEGUI has no integrated animation support at the moment.

If you want animation, you'd need to collect all the animation frames together and build a more complex imageset XML file, then you'd need some code in the app to control the animation yourself.