Page 1 of 1

loading static image at runtime (SOLVED)

Posted: Wed Jun 13, 2007 19:51
by duindain
hey im trying to change a static image defined in a layout file at runtime with several different pictures depending on user input ive read as many forum posts as i can so far but its still not working right

for instance i have a set of 5 map images each click swaps to the relevant image but the code is crashing i think when the image has already been loaded before and we try to set to it again and the image size is wrong

this is my layout info for the static image

Code: Select all

<Window Type="TaharezLook/StaticImage" Name="createmapimage" >
                <Property Name="Image" Value="set:BackgroundImage image:full_image" />
                <Property Name="FrameEnabled" Value="False" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0.57,0},{0.1,0},{0.98,0},{0.25,0}}" />
                <Property Name="BackgroundEnabled" Value="False" />
            </Window>


can someone tell me the code for the layout file that determines the size of the image btw all my images are 150x150 and i think im loading them as backgrounds so it makes them way to huge

this is the code which switchs the images with a new image

Code: Select all

string maploc = "../datafiles/maps/" + maps[id].mapimage;
         ImagesetManager::getSingleton().createImagesetFromImageFile("ImageForStaticImage",maploc);
         CEGUI::DefaultWindow* win = static_cast<CEGUI::DefaultWindow*>(WindowManager::getSingleton().getWindow("createmapimage"));
         win->setSize(CEGUI::UVector2(CEGUI::UDim(150,1),CEGUI::UDim(150,1)));
         win->setProperty("Image","set:ImageForStaticImage image:full_image");


can someone show me a simple easy way of making the images display right that will work for redisplaying them as well not just the initial set
please and so the images are set in the code using the filename

thankyou if you can help

Posted: Wed Jun 13, 2007 20:11
by Rackle
Rather than 150 try 1.0f instead; 1.0f represents 100% of the screen, 0.5f represents 50% of the screen, ...

If that doesn't work fiddle with the StaticImage within WidgetGalore. That should provide a good testing base; starting with something that works and modifying it until you reach your goal. Then you can update your own project.

code problem

Posted: Wed Jun 13, 2007 21:52
by duindain
ok thankyou for the size info

can someone take a look at my layout and code though please?
since its crashing when i run it at the moment and it wont reload images that have already been displayed

ive been through alot of peoples examples and the widget galore stuff alot of the methods are very different and i cant get a working version going

i just want it to display the small image using the static image window created in the layout

Posted: Thu Jun 14, 2007 09:18
by scriptkid
Hi,

have you checked the cegui.log file? That will at least show the reason of your crash. Besided that i don't see anything odd. Rackle is right about the sizes and the sample code in widget galore.

However you can get the exact size of an image: you can query an Imageset for an image by its name. An Image in its turn has GetWidth and GetHeight methods which return pixels.

Code: Select all

string maploc = "../datafiles/maps/" + maps[id].mapimage;
Imageset* set = ImagesetManager::getSingleton().createImagesetFromImageFile("ImageForStaticImage",maploc);
float width = set->getImage("full_image").getWidth();
float height = set->getImage("full_image").getHeight();
CEGUI::DefaultWindow* win = static_cast<CEGUI::DefaultWindow*>(WindowManager::getSingleton().getWindow("createmapimage"));       win->setSize(UVector2(UDim(0,width),CEGUI::UDim(0,height)));
win->setProperty("Image","set:ImageForStaticImage image:full_image");


Good luck!

finally got image loading

Posted: Thu Jun 14, 2007 12:48
by duindain
finally got it working this code displays an image using the name of the image as the unique identifier only loads if the image is unloaded otherwise it just gets the image from imagemanager

theres no need for size info becuase the image is loaded and set to the correct size of the window that contains it

so it doesnt crash on loading a previous image or when displaying to a fresh one all good after a day or day n a half of trolling thru the tutorials and forums for a good example and experimenting

Code: Select all

string maploc = "../datafiles/maps/" + maps[id].mapimage;

         Imageset* img;
         if(CEGUI::ImagesetManager::getSingleton().isImagesetPresent(maps[id].mapimage) == false)
            img = CEGUI::ImagesetManager::getSingleton().createImagesetFromImageFile(maps[id].mapimage,maploc);
         else
            img = CEGUI::ImagesetManager::getSingleton().getImageset(maps[id].mapimage);

         CEGUI::DefaultWindow* win = static_cast<CEGUI::DefaultWindow*>(WindowManager::getSingleton().getWindow("createmapimage"));     
         win->setProperty("Image","set:"+ maps[id].mapimage +" image:full_image");