Table of Contents

 
AddImage
 

Purpose

Loads an image from disk onto a surface and stores it in the manager

 

Protoype

void CImageMngr::AddImage (string str_filename, string str_img_id, RGB_SET rgb_key = RGB_SET(), int i_width = 0, 
                           int i_height = 0, int i_xpos = 0, int i_ypos = 0, bool b_show = true, bool b_bound = false)
 

Parameters

filename the name or location of the image file to load
img_id the unique ID of the new image object
key the RGB transparency key
width the width of cells in the image
height the height of cells in the image
xpos the X position of the image on the screen
ypos the Y position of the image on the screen
show whether to show (TRUE) or hide (FALSE) the image
bound whether the image is bound to another object (TRUE) or not (FALSE)
 

Description

This function loads an image from the disk and stores it in an SDL surface for use in the application. Use the parameter str_filename to point to the location of the file and assign each new image object a unique ID for str_img_id so that it can be referenced later in the application. You can set an image's initial (x,y) location as well with i_xpos and i_ypos, and toggle its visibility with b_show. This function supports the loading of the following file types: BMP, PNM, XPM, LBM, PCX, GIF, JPEG, PNG and TGA.

Transparency

Image transparency is done with color keys. Since each image is assigned a color key, each image can have its own transparency color. The way color keys work is the key is stored as an RGB value. When an image with a color key is blitted to another surface, all pixels in the image that match the RGB key are not blitted, hence the transparency. Color keys are assigned as RGB_SET objects. Passing in a null RGB_SET will disable color-keying for that image.

Cell Templates

If the image that you are loading contains cells for an animation or otherwise, then you must define the height and width of the cells so that the manager knows how to divide up the image to find a given cell. Cells do not have to be square, as you can pass in both height and width through i_height and i_width, but they all do have to be the exact same size. If there are no cells then simply pass in 0 for the width and height.

Image Binding

This is simply whether or not this image object is going to be used (and thus rendered) by another manager class. For instance, an icon image is bound to a button object of CButtonMngr. CButtonMngr is the class that actually renders the image on the screen, not CImageMngr. However if an image is not bound to any other manager then CImageMngr will render it.

 

Use

CImageMngr image;
image.AddImage("art/test.bmp", "my_image", RGB_SET(255, 0, 255), 0, 0, 50, 50);
 

Prev: Table of Contents
Next: Assign