loading static image at runtime (SOLVED)

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

duindain
Just popping in
Just popping in
Posts: 19
Joined: Sat Jun 09, 2007 08:51

loading static image at runtime (SOLVED)

Postby duindain » Wed Jun 13, 2007 19:51

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
Last edited by duindain on Thu Jun 14, 2007 12:48, edited 2 times in total.

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

Postby Rackle » Wed Jun 13, 2007 20:11

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.

duindain
Just popping in
Just popping in
Posts: 19
Joined: Sat Jun 09, 2007 08:51

code problem

Postby duindain » Wed Jun 13, 2007 21:52

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

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Thu Jun 14, 2007 09:18

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!

duindain
Just popping in
Just popping in
Posts: 19
Joined: Sat Jun 09, 2007 08:51

finally got image loading

Postby duindain » Thu Jun 14, 2007 12:48

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");


Return to “Help”

Who is online

Users browsing this forum: No registered users and 26 guests