[Freeciv-Dev] WinCE port - masking woes
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Okay, I am giving up here in frustration. I have tried and tried, but
I can not figure out why my masks are all black. I changed the mask
creation to force it to monochrome, but no luck. I even took the
entire crop and draw code and ran it through a test app. There,
everything works fine! So, this means that it might be going wrong
somewhere else? Please, I am so desperate. I can't figure this out.
If anyone could help me on this, I would be so grateful.
Jenn
struct Sprite* crop_sprite(struct Sprite *source,
int x, int y, int width, int height)
{
SPRITE *mysprite;
HDC hdc;
HBITMAP smallbitmap;
HBITMAP smallmask;
HBITMAP bigbitmap;
HBITMAP bigmask;
HBITMAP bigsave;
HBITMAP smallsave;
hdc=GetDC(hMainWindow);
mysprite=NULL;
smallmask=NULL;
if (!hdcbig)
hdcbig=CreateCompatibleDC(hdc);
if (!hdcsmall)
hdcsmall=CreateCompatibleDC(hdc);
if (sprcache!=source)
{
if (bitmapcache)
{
DeleteObject(bitmapcache);
}
sprcache=source;
bitmapcache = create_bitmap_copy(source->bmp);
}
bigbitmap = bitmapcache;
if (!bigbitmap)
{
freelog(LOG_FATAL,"create_bitmap_copy failed");
return NULL;
}
if (!(hdcsmall && hdcbig))
{
freelog(LOG_FATAL,"CreateCompatibleDC failed");
return NULL;
}
if (!(smallbitmap=CreateCompatibleBitmap(hdc,width,height)))
{
freelog(LOG_FATAL,"CreateCompatibleBitmap failed");
return NULL;
}
bigsave=SelectObject(hdcbig,bigbitmap);
smallsave=SelectObject(hdcsmall,smallbitmap);
BitBlt(hdcsmall,0,0,width,height,hdcbig,x,y,SRCCOPY);
if (source->has_mask)
{
bigmask = create_mask_copy(source->mask);
SelectObject(hdcbig, bigmask);
if ((smallmask = CreateBitmap(width,height,1,1,NULL)))
{
SelectObject(hdcsmall,smallmask);
BitBlt(hdcsmall,0,0,width,height,hdcbig,x,y,SRCCOPY);
}
DeleteObject(bigmask);
}
mysprite=fc_malloc(sizeof(struct Sprite));
mysprite->width=width;
mysprite->height=height;
mysprite->bmp = create_bitmap_copy(smallbitmap);
mysprite->has_mask=0;
if (smallmask)
{
mysprite->has_mask=1;
mysprite->mask = create_mask_copy(smallmask);
}
SelectObject(hdcbig,bigsave);
SelectObject(hdcsmall,smallsave);
ReleaseDC(hMainWindow,hdc);
if (smallmask)
{
DeleteObject(smallmask);
}
DeleteObject(smallbitmap);
return mysprite;
}
void draw_sprite_part(struct Sprite *sprite,HDC hdc,int x, int y,int
w, int h,
int xsrc, int ysrc)
{
static HDC hdccomp = NULL;
HBITMAP tempbit;
HBITMAP bitmap;
HBITMAP maskbit;
if (!sprite) return;
if (!hdccomp)
{
hdccomp=CreateCompatibleDC(hdc);
}
bitmap = create_bitmap_copy(sprite->bmp);
if (sprite->has_mask)
{
COLORREF fgold,bgold;
fgold=SetTextColor(hdc,RGB(0,0,0));
bgold=SetBkColor(hdc,RGB(255,255,255));
maskbit = create_mask_copy(sprite->mask);
tempbit=SelectObject(hdccomp,maskbit);
BitBlt(hdc,x,y,w,h,hdccomp,xsrc,ysrc,SRCAND);
SelectObject(hdccomp,bitmap);
BitBlt(hdc,x,y,w,h,hdccomp,xsrc,ysrc,SRCINVERT);
DeleteObject(maskbit);
SetBkColor(hdc,bgold);
SetTextColor(hdc,fgold);
}
else
{
tempbit=SelectObject(hdccomp,bitmap);
BitBlt(hdc,x,y,w,h,hdccomp,xsrc,ysrc,SRCCOPY);
}
SelectObject(hdccomp,tempbit);
/* DeleteDC(hdccomp); */
DeleteObject(bitmap);
}
HBITMAP create_mask_copy(HBITMAP hBitmap)
{
BITMAP bm;
HDC sourceDC = NULL;
HDC destDC = NULL;
HBITMAP hbmOldSource = NULL;
HBITMAP hbmResult = NULL;
HBITMAP hbmOldDest = NULL;
sourceDC = CreateCompatibleDC(NULL);
destDC = CreateCompatibleDC(NULL);
GetObject(hBitmap, sizeof(bm), &bm);
hbmOldSource = (HBITMAP) SelectObject(sourceDC, hBitmap);
hbmResult = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
hbmOldDest = (HBITMAP) SelectObject(destDC, hbmResult);
BitBlt(destDC, 0, 0, bm.bmWidth, bm.bmHeight, sourceDC, 0, 0,
SRCCOPY);
SelectObject(sourceDC, hbmOldSource);
DeleteDC(sourceDC);
SelectObject(destDC, hbmOldDest);
DeleteDC(destDC);
return hbmResult;
}
|
|