📄 gdi.c
字号:
src += pdc->step; w -= pdc->step; } } else while (w > 0) { *row &= *src; row += pdc->step; src += pdc->step; w -= pdc->step; }}static void _dc_put_hline_and_2 (PDC pdc, Uint8* src, int w){ Uint16* dstrow = (Uint16*)pdc->cur_dst; Uint16* srcrow = (Uint16*)src;#ifdef ASM_memandcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT && !((Uint32)dstrow & 3) && !((Uint32)srcrow & 3) && !(w & 1)) { ASM_memandcpy4 (dstrow, srcrow, w >> 1); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*srcrow != pdc->skip_pixel) *dstrow &= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; } } else while (w > 0) { *dstrow &= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; }}static void _dc_put_hline_and_3 (PDC pdc, Uint8* src, int w){ Uint8* row = (Uint8*)pdc->cur_dst; int step = (pdc->step << 1) + pdc->step;#ifdef ASM_memandcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT) { int i; int n = (w << 1) + w; int len = n >> 2; if (!((Uint32)row & 3) && !((Uint32)src & 3) && len) ASM_memandcpy4 (row, src, len); len <<= 2; row += len; src += len; for (i = 0; i < (n % 4); i++) { *row++ &= *src++; } return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (((* (Uint32*)row) & 0x00FFFFFF) != pdc->skip_pixel) { *row &= *src; *(row + 1) &= *(src + 1); *(row + 2) &= *(src + 2); } row += step; src += step; w -= pdc->step; } } else while (w > 0) { *row &= *src; *(row + 1) &= *(src + 1); *(row + 2) &= *(src + 2); row += step; src += step; w -= pdc->step; }}static void _dc_put_hline_and_4 (PDC pdc, Uint8* src, int w){ Uint32* dstrow = (Uint32*)pdc->cur_dst; Uint32* srcrow = (Uint32*)src;#ifdef ASM_memandcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT) { ASM_memandcpy4 (dstrow, srcrow, w); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*srcrow != pdc->skip_pixel) *dstrow &= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; } } else while (w > 0) { *dstrow &= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; }}static void _dc_put_hline_or_1 (PDC pdc, Uint8* src, int w){ Uint8* row = pdc->cur_dst;#ifdef ASM_memorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT && !((Uint32)row & 3) && !((Uint32)src & 3) && !(w & 3)) { ASM_memorcpy4 (row, src, w >> 2); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*src != pdc->skip_pixel) *row |= *src; row += pdc->step; src += pdc->step; w -= pdc->step; } } else while (w > 0) { *row |= *src; row += pdc->step; src += pdc->step; w -= pdc->step; }}static void _dc_put_hline_or_2 (PDC pdc, Uint8* src, int w){ Uint16* dstrow = (Uint16*)pdc->cur_dst; Uint16* srcrow = (Uint16*)src;#ifdef ASM_memorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT && !((Uint32)dstrow & 3) && !((Uint32)srcrow & 3) && !(w & 1)) { ASM_memorcpy4 (dstrow, srcrow, w >> 1); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*srcrow != pdc->skip_pixel) *dstrow |= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; } } else while (w > 0) { *dstrow |= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; }}static void _dc_put_hline_or_3 (PDC pdc, Uint8* src, int w){ Uint8* row = (Uint8*)pdc->cur_dst; int step = (pdc->step << 1) + pdc->step;#ifdef ASM_memorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT) { int i; int n = (w << 1) + w; int len = n >> 2; if (!((Uint32)row & 3) && !((Uint32)src & 3) && len) ASM_memorcpy4 (row, src, len); len <<= 2; row += len; src += len; for (i = 0; i < (n % 4); i++) { *row++ |= *src++; } return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (((* (Uint32*)row) & 0x00FFFFFF) != pdc->skip_pixel) { *row |= *src; *(row + 1) |= *(src + 1); *(row + 2) |= *(src + 2); } row += step; src += step; w -= pdc->step; } } else while (w > 0) { *row |= *src; *(row + 1) |= *(src + 1); *(row + 2) |= *(src + 2); row += step; src += step; w -= pdc->step; }}static void _dc_put_hline_or_4 (PDC pdc, Uint8* src, int w){ Uint32* dstrow = (Uint32*)pdc->cur_dst; Uint32* srcrow = (Uint32*)src;#ifdef ASM_memorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT) { ASM_memorcpy4 (dstrow, srcrow, w); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*srcrow != pdc->skip_pixel) *dstrow |= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; } } while (w > 0) { *dstrow |= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; }}static void _dc_put_hline_xor_1 (PDC pdc, Uint8* src, int w){ Uint8* row = pdc->cur_dst;#ifdef ASM_memxorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT && !((Uint32)row & 3) && !((Uint32)src & 3) && !(w & 3)) { ASM_memxorcpy4 (row, src, w >> 2); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*src != pdc->skip_pixel) *row ^= *src; row += pdc->step; src += pdc->step; w -= pdc->step; } } else while (w > 0) { *row ^= *src; row += pdc->step; src += pdc->step; w -= pdc->step; }}static void _dc_put_hline_xor_2 (PDC pdc, Uint8* src, int w){ Uint16* dstrow = (Uint16*)pdc->cur_dst; Uint16* srcrow = (Uint16*)src;#ifdef ASM_memxorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT && !((Uint32)dstrow & 3) && !((Uint32)srcrow & 3) && !(w & 1)) { ASM_memxorcpy4 (dstrow, srcrow, w >> 1); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*srcrow != pdc->skip_pixel) *dstrow ^= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; } } else while (w > 0) { *dstrow ^= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; }}static void _dc_put_hline_xor_3 (PDC pdc, Uint8* src, int w){ Uint8* row = (Uint8*)pdc->cur_dst; int step = (pdc->step << 1) + pdc->step;#ifdef ASM_memxorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT) { int i; int n = (w << 1) + w; int len = n >> 2; if (!((Uint32)row & 3) && !((Uint32)src & 3) && len) ASM_memxorcpy4 (row, src, len); len <<= 2; row += len; src += len; for (i = 0; i < (n % 4); i++) { *row++ ^= *src++; } return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (((* (Uint32*)row) & 0x00FFFFFF) != pdc->skip_pixel) { *row ^= *src; *(row + 1) ^= *(src + 1); *(row + 2) ^= *(src + 2); } row += step; src += step; w -= pdc->step; } } while (w > 0) { *row ^= *src; *(row + 1) ^= *(src + 1); *(row + 2) ^= *(src + 2); row += step; src += step; w -= pdc->step; }}static void _dc_put_hline_xor_4 (PDC pdc, Uint8* src, int w){ Uint32* dstrow = (Uint32*)pdc->cur_dst; Uint32* srcrow = (Uint32*)src;#ifdef ASM_memxorcpy4 if (pdc->step == 1 && pdc->bkmode != BM_TRANSPARENT) { ASM_memxorcpy4 (dstrow, srcrow, w); return; }#endif if (pdc->bkmode == BM_TRANSPARENT) { while (w > 0) { if (*srcrow != pdc->skip_pixel) *dstrow ^= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; } } while (w > 0) { *dstrow ^= *srcrow; dstrow += pdc->step; srcrow += pdc->step; w -= pdc->step; }}#define NR_ROPS 4#define NR_PIXEL_LEN 4static DC_SET_PIXEL set_pixel_ops [NR_ROPS][NR_PIXEL_LEN] ={ {_dc_set_pixel_1, _dc_set_pixel_2, _dc_set_pixel_3, _dc_set_pixel_4}, {_dc_and_pixel_1, _dc_and_pixel_2, _dc_and_pixel_3, _dc_and_pixel_4}, {_dc_or_pixel_1, _dc_or_pixel_2, _dc_or_pixel_3, _dc_or_pixel_4}, {_dc_xor_pixel_1, _dc_xor_pixel_2, _dc_xor_pixel_3, _dc_xor_pixel_4}};static DC_DRAW_HLINE draw_hline_ops [NR_ROPS][NR_PIXEL_LEN] ={ {_dc_draw_hline_set_1, _dc_draw_hline_set_2, _dc_draw_hline_set_3, _dc_draw_hline_set_4}, {_dc_draw_hline_and_1, _dc_draw_hline_and_2, _dc_draw_hline_and_3, _dc_draw_hline_and_4}, {_dc_draw_hline_or_1, _dc_draw_hline_or_2, _dc_draw_hline_or_3, _dc_draw_hline_or_4}, {_dc_draw_hline_xor_1, _dc_draw_hline_xor_2, _dc_draw_hline_xor_3, _dc_draw_hline_xor_4}};static DC_PUT_HLINE put_hline_ops [NR_ROPS][NR_PIXEL_LEN] ={ {_dc_put_hline_set_1, _dc_put_hline_set_2, _dc_put_hline_set_3, _dc_put_hline_set_4}, {_dc_put_hline_and_1, _dc_put_hline_and_2, _dc_put_hline_and_3, _dc_put_hline_and_4}, {_dc_put_hline_or_1, _dc_put_hline_or_2, _dc_put_hline_or_3, _dc_put_hline_or_4}, {_dc_put_hline_xor_1, _dc_put_hline_xor_2, _dc_put_hline_xor_3, _dc_put_hline_xor_4}};static DC_MOVE_TO move_to_ops [NR_PIXEL_LEN] = { _dc_move_to_1, _dc_move_to_2, _dc_move_to_3, _dc_move_to_4};static DC_STEP_X step_x_ops [NR_PIXEL_LEN] = { _dc_step_x_1, _dc_step_x_2, _dc_step_x_3, _dc_step_x_4};// This function init DC.// set the default parameters.static void dc_InitDC (PDC pdc, HWND hWnd, BOOL bIsClient){ PCONTROL pCtrl; pdc->hwnd = hWnd; pdc->bkcolor = GAL_MapRGB (pdc->surface->format, 0xFF, 0xFF, 0xFF); pdc->bkmode = 0; pdc->brushtype = BT_SOLID; pdc->brushcolor = GAL_MapRGB (pdc->surface->format, 0xFF, 0xFF, 0xFF); pdc->BrushOrig.x = pdc->BrushOrig.y = 0; pdc->pentype = PT_SOLID; pdc->pencolor = GAL_MapRGB (pdc->surface->format, 0x00, 0x00, 0x00); pdc->textcolor = GAL_MapRGB (pdc->surface->format, 0x00, 0x00, 0x00); if (!(pdc->pLogFont = GetWindowFont (hWnd))) pdc->pLogFont = GetSystemFont (SYSLOGFONT_WCHAR_DEF); pdc->tabstop = 8; pdc->cExtra = pdc->alExtra = pdc->blExtra = 0; pdc->mapmode = MM_TEXT; pdc->ViewOrig.x = pdc->ViewOrig.y = 0; pdc->ViewExtent.x = pdc->ViewExtent.y = 1; pdc->WindowOrig.x = pdc->WindowOrig.y = 0; pdc->WindowExtent.x = pdc->WindowExtent.y = 1; // assume that the local clip region is empty. // Get global clip region info and generate effective clip region. if (dc_IsGeneralDC (pdc)) { RECT minimal; pdc->pGCRInfo = GetGCRgnInfo (hWnd); LOCK (&pdc->pGCRInfo->lock); pdc->oldage = pdc->pGCRInfo->age; ClipRgnCopy (&pdc->ecrgn, &pdc->pGCRInfo->crgn); pdc->bIsClient = bIsClient; if (bIsClient) WndClientRect (pdc->hwnd, &pdc->DevRC); else WndRect (pdc->hwnd, &pdc->DevRC); minimal = pdc->DevRC; pCtrl = Control (pdc->hwnd); if (pCtrl && !(pCtrl->dwExStyle & WS_EX_CTRLASMAINWIN)) RestrictControlECRGN (&minimal, pCtrl); IntersectClipRect (&pdc->ecrgn, &minimal); UNLOCK (&pdc->pGCRInfo->lock); } // context info and raster operations. pdc->CurPenPos.x = pdc->CurTextPos.x = 0; pdc->CurPenPos.y = pdc->CurTextPos.y = 0; pdc->rop = ROP_SET; pdc->step = 1; pdc->set_pixel = set_pixel_ops [pdc->rop][pdc->surface->format->BytesPerPixel - 1]; pdc->draw_hline = draw_hline_ops [pdc->rop][pdc->surface->format->BytesPerPixel - 1]; pdc->put_hline = put_hline_ops [pdc->rop][pdc->surface->format->BytesPerPixel - 1]; pdc->cur_dst = pdc->surface->pixels + pdc->surface->pitch * pdc->DevRC.top + pdc->surface->format->BytesPerPixel * pdc->DevRC.left; pdc->move_to = move_to_ops [pdc->surface->format->BytesPerPixel - 1]; pdc->step_x = step_x_ops [pdc->surface->format->BytesPerPixel - 1];}static void dc_InitScreenDC (void){ __mg_screen_dc.DataType = TYPE_HDC; __mg_screen_dc.DCType = TYPE_SCRDC; __mg_screen_dc.hwnd = 0; __mg_screen_dc.surface = __gal_screen; __mg_screen_dc.bkcolor = PIXEL_lightwhite; __mg_screen_dc.bkmode = 0; __mg_screen_dc.brushtype = BT_SOLID; __mg_screen_dc.brushcolor = PIXEL_lightwhite; __mg_screen_dc.BrushOrig.x = __mg_screen_dc.BrushOrig.y = 0; __mg_screen_dc.pentype = PT_SOLID; __mg_screen_dc.pencolor = PIXEL_black; __mg_screen_dc.CurPenPos.x = __mg_screen_dc.CurPenPos.y = 0; __mg_screen_dc.textcolor = PIXEL_black; __mg_screen_dc.pLogFont = GetSystemFont (SYSLOGFONT_WCHAR_DEF); __mg_screen_dc.tabstop = 8; __mg_screen_dc.CurTextPos.x = __mg_screen_dc.CurTextPos.y = 0; __mg_screen_dc.cExtra = __mg_screen_dc.alExtra = __mg_screen_dc.blExtra = 0; __mg_screen_dc.ViewOrig.x = __mg_screen_dc.ViewOrig.y = 0; __mg_screen_dc.ViewExtent.x = __mg_screen_dc.ViewExtent.y = 1; __mg_screen_dc.WindowOrig.x = __mg_screen_dc.WindowOrig.y = 0; __mg_screen_dc.WindowExtent.x = __mg_screen_dc.WindowExtent.y = 1; __mg_screen_dc.bIsClient = FALSE; // init local clippping region // InitClipRgn (&__mg_screen_dc.lcrgn, &sg_FreeClipRectList); // init effective clippping region InitClipRgn (&__mg_screen_dc.ecrgn, &sg_FreeClipRectList); // init global clip region information __mg_screen_dc.pGCRInfo = NULL; __mg_screen_dc.oldage = 0; __mg_screen_dc.DevRC.left = 0; __mg_screen_dc.DevRC.top = 0; __mg_screen_dc.DevRC.right = WIDTHOFPHYGC - 1; __mg_screen_dc.DevRC.bottom = HEIGHTOFPHYGC - 1; // Set effetive clippping region to the screen. // SetClipRgn (&__mg_screen_dc.lcrgn, &__mg_screen_dc.DevRC); SetClipRgn (&__mg_screen_dc.ecrgn, &__mg_screen_dc.DevRC); // context info and raster operations. __mg_screen_dc.rop = ROP_SET; __mg_screen_dc.step = 1; __mg_screen_dc.set_pixel = set_pixel_ops [__mg_screen_dc.rop] [__mg_screen_dc.surface->format->BytesPerPixel - 1]; __mg_screen_dc.draw_hline = draw_hline_ops [__mg_screen_dc.rop] [__mg_screen_dc.surface->format->BytesPerPixel - 1]; __mg_screen_dc.put_hline = put_hline_ops [__mg_screen_dc.rop] [__mg_screen_dc.surface->format->BytesPerPixel - 1]; __mg_screen_dc.cur_dst = __mg_screen_dc.surface->pixels; __mg_screen_dc.move_to = move_to_ops [__mg_screen_dc.surface->format->BytesPerPixel - 1]; __mg_screen_dc.step_x = step_x_ops [__mg_screen_dc.surface->format->BytesPerPixel - 1];} int GUIAPI GetRasterOperation (HDC hdc){ PDC pdc; pdc = dc_HDC2PDC (hdc); return pdc->rop;}int GUIAPI SetRasterOperation (HDC hdc, int rop){ PDC pdc; int old; pdc = dc_HDC2PDC (hdc); old = pdc->rop; if (rop >= 0 && rop < NR_ROPS) { pdc->rop = rop; pdc->set_pixel = set_pixel_ops [rop] [pdc->surface->format->BytesPerPixel - 1]; pdc->draw_hline = draw_hline_ops [rop]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -