about Sprite struture.. i need some advices

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
what, normaly, you use for acomplete Sprite structure, besides position and size?
i have 2 strutures and 3 functions:struct Images
{
HBITMAP ImageImage;
BITMAP Imagebm;
HDC ImagehdcMem;
HBITMAP ImageMaskImage;
BITMAP ImageMaskbm;
HDC ImageMaskhdcMem;
};


struct Sprite
{
RECT Position;
BOOL Visible;
};

enum DrawWay {Normal, Stretch};

//if MaskColor is -2 then the transparency is ignored;
//if MaskColor is -1 then the transparent color is the pixel 0,0
int LoadImage(Images &imagem, char *FileName,COLORREF MaskColor)
{
int posx;
int posy;

COLORREF b;


//Load the image
imagem.ImageImage = (HBITMAP)LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
GetObject(imagem.ImageImage , sizeof(BITMAP), &imagem.Imagebm);
imagem.ImagehdcMem = CreateCompatibleDC(NULL);
SelectObject(imagem.ImagehdcMem, imagem.ImageImage);

//Create the mask
if (MaskColor==-2)
{
//dont do the mask
}
else
{
imagem.ImageMaskImage = (HBITMAP)LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
GetObject(imagem.ImageMaskImage , sizeof(BITMAP), &imagem.ImageMaskbm);
imagem.ImageMaskhdcMem = CreateCompatibleDC(NULL);
SelectObject(imagem.ImageMaskhdcMem, imagem.ImageMaskImage);

if (MaskColor==-1) MaskColor= GetPixel(imagem.ImageMaskhdcMem,0 ,0);

for (posy=0;posy<imagem.Imagebm.bmHeight;posy++)
{
for (posx=0;posx<imagem.Imagebm.bmWidth ;posx++)
{
b=GetPixel(imagem.ImageMaskhdcMem,posx,posy);
if (b==MaskColor)
SetPixel(imagem.ImageMaskhdcMem,posx,posy,RGB(255,255,255));
else
SetPixel(imagem.ImageMaskhdcMem,posx,posy,RGB(0,0,0));
}
}
}
return 0;
}

int DrawImages(HDC &Destination, Images &Origem, BOOL Transparent, int PosX, int PosY, int Width, int Height,DrawWay dwDraw)
{
if (Transparent==TRUE)
{
if (dwDraw==Stretch)
{
StretchBlt (Destination,
PosX, PosY,
Width, Height,
Origem.ImagehdcMem,
0, 0,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight,SRCINVERT);
StretchBlt (Destination,
PosX, PosY,
Width, Height,
Origem.ImageMaskhdcMem,
0, 0,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight, SRCAND);
StretchBlt (Destination,
PosX, PosY,
Width, Height,
Origem.ImagehdcMem,
0, 0,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight, SRCINVERT);
}
else if (dwDraw==Normal)
{
BitBlt( Destination,
PosX, PosY,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight,
Origem.ImagehdcMem,
0, 0,
SRCINVERT);

BitBlt( Destination,
PosX, PosY,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight,
Origem.ImageMaskhdcMem,
0, 0,
SRCAND);
BitBlt( Destination,
PosX, PosY,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight,
Origem.ImagehdcMem,
0, 0,
SRCINVERT);
}
}
else
{
if (dwDraw==Stretch)
{
StretchBlt (Destination,
PosX, PosY,
Width, Height,
Origem.ImagehdcMem,
0, 0,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight,SRCCOPY);
}
else
{
BitBlt( Destination,
PosX, PosY,
Origem.Imagebm.bmWidth, Origem.Imagebm.bmHeight,
Origem.ImagehdcMem,
0, 0,
SRCCOPY);
}
}
return 0;
}

int DeleteObjects(Images &BitmapImage)
{
DeleteDC(BitmapImage.ImagehdcMem);
DeleteObject((HBITMAP)BitmapImage.ImageImage);
return 0;
}
i wanted join everything, for be more easy to use. but i need some advices, please

View the full article
 
Back
Top