Table of Contents

 
DrawImage
 

Purpose

Blits an image from one surface to another

 

Protoype

void CImageMngr::DrawImage (string str_id_src, string str_id_dst, CVector v_src, CVector v_dest, int i_width = 0, 
                            int i_height = 0)
 

Parameters

id_src the surface or image object to blit from
id_dst

the surface or image object to blit to

src the position of the source rectangle (NULL if no cells)
dest the destination location of the blit
width the width of the source rectangle
height the height of the source rectangle
 

Description

This function is the function that is called by almost every other manager class when they want to render images that are bound to them. Remember that bound images are not rendered by the CImageMngr class itself - technically they are rendered by the other manager classes that are associated with them through this function. The function allows the blitting of data from one surface onto another. Remember, each image object is really a surface. Usually this function is used to blit from an image object onto the primary surface. In this case you would use the predefined PRIMARY for str_id_dst and the ID of the image you wish to blit for str_id_src. However since you can blit freely from surface to surface and image objects are really surfaces, you can also blit from image object to image object! To do this instead of using PRIMARY for str_id_dst you would pass in the ID of the image object you want the src image to blit onto. This is how you use blank surfaces created with CreateImage().

If you are using a template, then you can blit a single cell in the template by simply passing in the x,y location of the cell for v_src (which can be obtained via CellPosXY()) - the function will automatically handle the size of the source rectangle. If you are not using templates and want to blit the entire image, then you can pass in NULL for v_src. If you are not using templates but still wish to restrict the amount of surface being blitted, then you can set the location of the source rectangle with v_src and its size via i_width and i_height. This source rectangle will outline the area that will be blitted to the location on the destination surface defined by v_dest.

 

Use

CImageMngr image;
// blit a non-templated image onto the primary surface
image.DrawImage("my_image", PRIMARY, NULL, CVector(25, 25));
// blit a cell from one image object to another
image.DrawImage("src_image", "dst_image", CVector(30, 30), CVector(25, 25));
// blit part of an image onto the main surface
image.DrawImage("my_image", PRIMARY, CVector(50, 50), CVector(25, 25), 100, 100);
 

Prev: CreateImage