int FillRect_32bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) { int x, y; uint32 *dstp; uint32 color32; int nXDest, nYDest; int nWidth, nHeight; gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); if (gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL) == 0) return 0; color32 = gdi_get_color_32bpp(hdc, hbr->color); for (y = 0; y < nHeight; y++) { dstp = (uint32*) gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); if (dstp != 0) { for (x = 0; x < nWidth; x++) { *dstp = color32; dstp++; } } } gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight); return 0; }
BOOL FillRect_16bpp(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr) { int x, y; UINT16 *dstp; int nXDest, nYDest; int nWidth, nHeight; UINT16 color16; gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) return TRUE; color16 = gdi_get_color_16bpp(hdc, hbr->color); for (y = 0; y < nHeight; y++) { dstp = (UINT16*) gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); if (dstp != 0) { for (x = 0; x < nWidth; x++) { *dstp = color16; dstp++; } } } if (!gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight)) return FALSE; return TRUE; }
BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr) { UINT32 x, y; UINT32 color, dstColor; BOOL monochrome = FALSE; UINT32 nXDest, nYDest; UINT32 nWidth, nHeight; const BYTE* srcp; DWORD formatSize; gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); if (!hdc || !hbr) return FALSE; if (!gdi_ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL)) return TRUE; switch (hbr->style) { case GDI_BS_SOLID: color = hbr->color; for (x = 0; x < nWidth; x++) { BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, nYDest); if (dstp) WriteColor(dstp, hdc->format, color); } srcp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest); formatSize = GetBytesPerPixel(hdc->format); for (y = 1; y < nHeight; y++) { BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); memcpy(dstp, srcp, nWidth * formatSize); } break; case GDI_BS_HATCHED: case GDI_BS_PATTERN: monochrome = (hbr->pattern->format == PIXEL_FORMAT_MONO); formatSize = GetBytesPerPixel(hbr->pattern->format); for (y = 0; y < nHeight; y++) { for (x = 0; x < nWidth; x++) { const UINT32 yOffset = ((nYDest + y) * hbr->pattern->width % hbr->pattern->height) * formatSize; const UINT32 xOffset = ((nXDest + x) % hbr->pattern->width) * formatSize; const BYTE* patp = &hbr->pattern->data[yOffset + xOffset]; BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, nYDest + y); if (!patp) return FALSE; if (monochrome) { if (*patp == 0) dstColor = hdc->bkColor; else dstColor = hdc->textColor; } else { dstColor = ReadColor(patp, hbr->pattern->format); dstColor = ConvertColor(dstColor, hbr->pattern->format, hdc->format, NULL); } if (dstp) WriteColor(dstp, hdc->format, dstColor); } } break; default: break; } if (!gdi_InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight)) return FALSE; return TRUE; }
BOOL gdi_ClipCoords(HGDI_DC hdc, INT32* x, INT32* y, INT32* w, INT32* h, INT32* srcx, INT32* srcy) { GDI_RECT bmp; GDI_RECT clip; GDI_RECT coords; HGDI_BITMAP hBmp; int dx = 0; int dy = 0; BOOL draw = TRUE; if (hdc == NULL) return FALSE; hBmp = (HGDI_BITMAP) hdc->selectedObject; if (hBmp != NULL) { if (hdc->clip->null) { gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &clip); } else { gdi_RgnToRect(hdc->clip, &clip); gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &bmp); if (clip.left < bmp.left) clip.left = bmp.left; if (clip.right > bmp.right) clip.right = bmp.right; if (clip.top < bmp.top) clip.top = bmp.top; if (clip.bottom > bmp.bottom) clip.bottom = bmp.bottom; } } else { gdi_RgnToRect(hdc->clip, &clip); } gdi_CRgnToRect(*x, *y, *w, *h, &coords); if (coords.right >= clip.left && coords.left <= clip.right && coords.bottom >= clip.top && coords.top <= clip.bottom) { /* coordinates overlap with clipping region */ if (coords.left < clip.left) { dx = (clip.left - coords.left); coords.left = clip.left; } if (coords.right > clip.right) coords.right = clip.right; if (coords.top < clip.top) { dy = (clip.top - coords.top); coords.top = clip.top; } if (coords.bottom > clip.bottom) coords.bottom = clip.bottom; } else { /* coordinates do not overlap with clipping region */ coords.left = 0; coords.right = 0; coords.top = 0; coords.bottom = 0; draw = FALSE; } if (srcx != NULL) *srcx += dx; if (srcy != NULL) *srcy += dy; gdi_RectToCRgn(&coords, x, y, w, h); return draw; }