📄 gdi.c
字号:
[pdc->surface->format->BytesPerPixel - 1]; pdc->put_hline = put_hline_ops [rop] [pdc->surface->format->BytesPerPixel - 1]; } return old;}/* * Function: HDC GUIAPI GetClientDC (HWND hWnd) * This function get the specified window client's DC. * Parameter: * HWND hWnd: The window, 0 for screen. * Return: * The handle of wanted DC. */HDC GUIAPI GetClientDC (HWND hWnd){ int i; LOCK (&dcslot); for (i = 0; i < DCSLOTNUMBER; i++) { if (!DCSlot[i].inuse) { DCSlot[i].inuse = TRUE; DCSlot[i].DataType = TYPE_HDC; DCSlot[i].DCType = TYPE_GENDC; DCSlot[i].surface = __gal_screen; break; } } UNLOCK (&dcslot); if (i >= DCSLOTNUMBER) return HDC_SCREEN; dc_InitDC (DCSlot + i, hWnd, TRUE); return (HDC) (DCSlot + i);}/* * Function: HDC GUIAPI GetDC(HWND hWnd) * This function get the specified window's DC. * Parameter: * HWND hWnd: The window, 0 for screen. * Return: * The handle of wanted DC. */HDC GUIAPI GetDC(HWND hWnd){ int i; // allocate an empty dc slot exclusively LOCK (&dcslot); for (i = 0; i < DCSLOTNUMBER; i++) { if(!DCSlot[i].inuse) { DCSlot[i].inuse = TRUE; DCSlot[i].DataType = TYPE_HDC; DCSlot[i].DCType = TYPE_GENDC; DCSlot[i].surface = __gal_screen; break; } } UNLOCK(&dcslot); if (i >= DCSLOTNUMBER) return HDC_SCREEN; dc_InitDC(DCSlot + i, hWnd, FALSE); return (HDC)(DCSlot + i);}/* * Function: void GUIAPI ReleaseDC(HDC hDC) * This function release the specified DC. * Parameter: * HDC hDC: The DC handle want to release. * Return: * None. */void GUIAPI ReleaseDC (HDC hDC){ PMAINWIN pWin; PDC pdc; PCONTROL pCtrl; pdc = dc_HDC2PDC(hDC); EmptyClipRgn (&pdc->lcrgn); pWin = (PMAINWIN)(pdc->hwnd); if (pWin && pWin->privCDC == hDC) { RECT minimal; /* for private DC, we reset the clip region info. */ LOCK (&pdc->pGCRInfo->lock); pdc->oldage = pdc->pGCRInfo->age; ClipRgnCopy (&pdc->ecrgn, &pdc->pGCRInfo->crgn); if (pdc->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); } else { EmptyClipRgn (&pdc->ecrgn); pdc->pGCRInfo = NULL; pdc->oldage = 0; LOCK (&dcslot); pdc->inuse = FALSE; UNLOCK(&dcslot); }}HDC GUIAPI CreatePrivateDC(HWND hwnd){ PDC pdc; if (!(pdc = malloc (sizeof(DC)))) return HDC_INVALID; InitClipRgn (&pdc->lcrgn, &sg_FreeClipRectList); InitClipRgn (&pdc->ecrgn, &sg_FreeClipRectList); pdc->inuse = TRUE; pdc->DataType = TYPE_HDC; pdc->DCType = TYPE_GENDC; pdc->surface = __gal_screen; dc_InitDC (pdc, hwnd, FALSE); return (HDC)(pdc);}HDC GUIAPI CreatePrivateClientDC(HWND hwnd){ PDC pdc; if (!(pdc = malloc (sizeof(DC)))) return HDC_INVALID; InitClipRgn (&pdc->lcrgn, &sg_FreeClipRectList); InitClipRgn (&pdc->ecrgn, &sg_FreeClipRectList); pdc->inuse = TRUE; pdc->DataType = TYPE_HDC; pdc->DCType = TYPE_GENDC; pdc->surface = __gal_screen; dc_InitDC(pdc, hwnd, TRUE); return (HDC)(pdc);}void GUIAPI DeletePrivateDC(HDC hdc){ PDC pdc; pdc = (PDC)hdc; EmptyClipRgn (&pdc->lcrgn); EmptyClipRgn (&pdc->ecrgn); free (pdc);}HDC GUIAPI GetPrivateClientDC (HWND hwnd){ PMAINWIN pWin = (PMAINWIN)hwnd; return pWin->privCDC;}/* LockDC/UnlockDC to get direct access to the pixels in a DC. */Uint8* GUIAPI LockDC (HDC hdc, const RECT* rw_rc, int* width, int* height, int* pitch){ PDC pdc; Uint8* pixels = NULL; if (!(pdc = check_ecrgn (hdc))) return NULL; if (rw_rc) { pdc->rc_output = *rw_rc; /* Transfer device to device to screen here. */ coor_DP2SP (pdc, &pdc->rc_output.left, &pdc->rc_output.top); coor_DP2SP (pdc, &pdc->rc_output.right, &pdc->rc_output.bottom); if (!IntersectRect (&pdc->rc_output, &pdc->rc_output, &pdc->DevRC)) goto fail; } else pdc->rc_output = pdc->DevRC; BLOCK_DRAW_SEM (pdc);#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (!mgIsServer && (pdc->surface == __gal_screen) && !IntersectRect (&pdc->rc_output, &pdc->rc_output, (const RECT*)&SHAREDRES_CLI_SCR_LX)) goto fail;#endif if (!IntersectRect (&pdc->rc_output, &pdc->rc_output, &pdc->ecrgn.rcBound)) goto fail; LOCK (&__mg_gdilock); if (!dc_IsMemDC (pdc)) ShowCursorForGDI (FALSE, &pdc->rc_output); if (width) *width = RECTW(pdc->rc_output); if (height) *height = RECTH(pdc->rc_output); if (pitch) *pitch = pdc->surface->pitch; pixels = pdc->surface->pixels; pixels += pdc->surface->pitch * pdc->rc_output.top; pixels += pdc->surface->format->BytesPerPixel * pdc->rc_output.left;fail: UNBLOCK_DRAW_SEM (pdc); UNLOCK_GCRINFO (pdc); return pixels;}void GUIAPI UnlockDC (HDC hdc){ PDC pdc; pdc = dc_HDC2PDC (hdc); if (!dc_IsMemDC (pdc)) ShowCursorForGDI (TRUE, &pdc->rc_output); UNLOCK (&__mg_gdilock); UNBLOCK_DRAW_SEM (pdc); UNLOCK_GCRINFO (pdc);}/******************************* Memory DC ***********************************/HDC GUIAPI CreateCompatibleDCEx (HDC hdc, int width, int height){ PDC pdc; PDC pmem_dc = NULL; GAL_Surface* surface; pdc = dc_HDC2PDC (hdc); if (!(pmem_dc = malloc (sizeof(DC)))) return HDC_INVALID; if (width <= 0 || height <= 0) { width = RECTW (pdc->DevRC); height = RECTH (pdc->DevRC); } LOCK (&__mg_gdilock); surface = GAL_CreateRGBSurface (GAL_HWSURFACE, width, height, pdc->surface->format->BitsPerPixel, pdc->surface->format->Rmask, pdc->surface->format->Gmask, pdc->surface->format->Bmask, pdc->surface->format->Amask); UNLOCK (&__mg_gdilock); if (!surface) { free (pmem_dc); return HDC_INVALID; } /* Set surface attributes */ if (pdc->surface->format->BitsPerPixel <= 8) { GAL_SetPalette (surface, GAL_LOGPAL, (GAL_Color*) pdc->surface->format->palette->colors, 0, 1<<pdc->surface->format->BitsPerPixel); } memcpy (pmem_dc, pdc, sizeof(DC)); pmem_dc->DataType = TYPE_HDC; pmem_dc->DCType = TYPE_MEMDC; pmem_dc->inuse = TRUE; pmem_dc->surface = surface; // clip region info InitClipRgn (&pmem_dc->ecrgn, &sg_FreeClipRectList); pmem_dc->pGCRInfo = NULL; pmem_dc->oldage = 0; pmem_dc->DevRC.left = 0; pmem_dc->DevRC.top = 0; pmem_dc->DevRC.right = width; pmem_dc->DevRC.bottom = height; SetClipRgn (&pmem_dc->ecrgn, &pmem_dc->DevRC); return (HDC)pmem_dc;}HDC GUIAPI CreateMemDC (int width, int height, int depth, DWORD flags, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask){ PDC pmem_dc = NULL; GAL_Surface* surface; if (!(pmem_dc = malloc (sizeof(DC)))) return HDC_INVALID; LOCK (&__mg_gdilock); surface = GAL_CreateRGBSurface (flags, width, height, depth, Rmask, Gmask, Bmask, Amask); UNLOCK (&__mg_gdilock); if (!surface) { free (pmem_dc); return HDC_INVALID; } pmem_dc->DataType = TYPE_HDC; pmem_dc->DCType = TYPE_MEMDC; pmem_dc->inuse = TRUE; pmem_dc->surface = surface; dc_InitDC (pmem_dc, HWND_DESKTOP, FALSE); InitClipRgn (&pmem_dc->ecrgn, &sg_FreeClipRectList); pmem_dc->pGCRInfo = NULL; pmem_dc->oldage = 0; pmem_dc->DevRC.left = 0; pmem_dc->DevRC.top = 0; pmem_dc->DevRC.right = width; pmem_dc->DevRC.bottom = height; SetClipRgn (&pmem_dc->ecrgn, &pmem_dc->DevRC); return (HDC)pmem_dc;}HDC GUIAPI CreateMemDCFromBitmap (HDC hdc, BITMAP* bmp){ PDC pdc, pmem_dc = NULL; GAL_Surface* surface; Uint32 Rmask = 0, Gmask = 0, Bmask = 0, Amask = 0; pdc = dc_HDC2PDC (hdc); if (bmp->bmType & BMP_TYPE_ALPHA) { switch (bmp->bmBitsPerPixel) { case 4: case 8: break; case 16: Rmask = 0x0000F000; Gmask = 0x00000F00; Bmask = 0x000000F0; Amask = 0x0000000F; break; case 24: Rmask = 0x00FC0000; Gmask = 0x0003F000; Bmask = 0x00000FC0; Amask = 0x0000003F; break; case 32: Rmask = 0xFF000000; Gmask = 0x00FF0000; Bmask = 0x0000FF00; Amask = 0x000000FF; break; default: /* not supported */ return HDC_INVALID; } } else { Rmask = pdc->surface->format->Rmask; Gmask = pdc->surface->format->Gmask; Bmask = pdc->surface->format->Bmask; Amask = pdc->surface->format->Amask; } if (!(pmem_dc = malloc (sizeof(DC)))) return HDC_INVALID; surface = GAL_CreateRGBSurfaceFrom (bmp->bmBits, bmp->bmWidth, bmp->bmHeight, bmp->bmBitsPerPixel, bmp->bmPitch, Rmask, Gmask, Bmask, Amask); if (!surface) { free (pmem_dc); return HDC_INVALID; } /* Set surface attributes */ if (bmp->bmBitsPerPixel <= 8) { GAL_SetPalette (surface, GAL_LOGPAL, pdc->surface->format->palette->colors, 0, 1<<bmp->bmBitsPerPixel); } if (bmp->bmType & BMP_TYPE_ALPHACHANNEL) { GAL_SetAlpha (surface, GAL_SRCALPHA | GAL_RLEACCEL, bmp->bmAlpha); } if (bmp->bmType & BMP_TYPE_COLORKEY) { GAL_SetColorKey (surface, GAL_SRCCOLORKEY | GAL_RLEACCEL, bmp->bmAlpha); } pmem_dc->DataType = TYPE_HDC; pmem_dc->DCType = TYPE_MEMDC; pmem_dc->inuse = TRUE; pmem_dc->surface = surface; dc_InitDC (pmem_dc, HWND_DESKTOP, FALSE); InitClipRgn (&pmem_dc->ecrgn, &sg_FreeClipRectList); pmem_dc->pGCRInfo = NULL; pmem_dc->oldage = 0; pmem_dc->DevRC.left = 0; pmem_dc->DevRC.top = 0; pmem_dc->DevRC.right = bmp->bmWidth; pmem_dc->DevRC.bottom = bmp->bmHeight; SetClipRgn (&pmem_dc->ecrgn, &pmem_dc->DevRC); return (HDC)pmem_dc;}HDC GUIAPI CreateMemDCFromMyBitmap (const MYBITMAP* my_bmp, RGB* pal){ PDC pmem_dc; GAL_Surface* surface; Uint32 Rmask = 0, Gmask = 0, Bmask = 0, Amask = 0; if (my_bmp->flags & MYBMP_FLOW_UP) return HDC_INVALID; switch (my_bmp->depth) { case 4: case 8: break; case 24: if (my_bmp->flags & MYBMP_ALPHA) { Amask = 0x0000003F; if ((my_bmp->flags & MYBMP_TYPE_MASK) == MYBMP_TYPE_RGB) { Rmask = 0x00FC0000; Gmask = 0x0003F000; Bmask = 0x00000FC0; } else { Rmask = 0x00000FC0; Gmask = 0x0003F000; Bmask = 0x00FC0000; } } else { Amask = 0x00000000; if ((my_bmp->flags & MYBMP_TYPE_MASK) == MYBMP_TYPE_RGB) { Rmask = 0x00FF0000; Gmask = 0x0000FF00; Bmask = 0x000000FF; } else { Rmask = 0x000000FF; Gmask = 0x0000FF00; Bmask = 0x00FF0000; } } break; case 32: if ((my_bmp->flags & MYBMP_TYPE_MASK) == MYBMP_TYPE_RGB) { Rmask = 0xFF000000; Gmask = 0x00FF0000; Bmask = 0x0000FF00; } else { Bmask = 0xFF000000; Gmask = 0x00FF0000; Rmask = 0x0000FF00; } if (my_bmp->flags & MYBMP_ALPHA) Amask = 0x000000FF; else Amask = 0x00000000; break; default: return HDC_INVALID; } if (!(pmem_dc = malloc (sizeof(DC)))) return HDC_INVALID; surface = GAL_CreateRGBSurfaceFrom (my_bmp->bits, my_bmp->w, my_bmp->h, my_bmp->depth, my_bmp->pitch, Rmask, Gmask, Bmask, Amask); if (!surface) { free (pmem_dc); return HDC_INVALID; } /* Set surface attributes */ if (my_bmp->depth <= 8) { GAL_SetPalette (surface, GAL_LOGPAL, (GAL_Color*) pal, 0, 1<<my_bmp->depth); } if (my_bmp->flags & MYBMP_ALPHACHANNEL) { GAL_SetAlpha (surface, GAL_SRCALPHA | GAL_RLEACCEL, my_bmp->alpha); } if (my_bmp->flags & MYBMP_TRANSPARENT) { GAL_SetColorKey (surface, GAL_SRCCOLORKEY | GAL_RLEACCEL, my_bmp->transparent); } pmem_dc->DataType = TYPE_HDC; pmem_dc->DCType = TYPE_MEMDC; pmem_dc->inuse = TRUE; pmem_dc->surface = surface; dc_InitDC (pmem_dc, HWND_DESKTOP, FALSE); InitClipRgn (&pmem_dc->ecrgn, &sg_FreeClipRectList); pmem_dc->pGCRInfo = NULL; pmem_dc->oldage = 0; pmem_dc->DevRC.left = 0; pmem_dc->DevRC.top = 0; pmem_dc->DevRC.right = my_bmp->w; pmem_dc->DevRC.bottom = my_bmp->h; SetClipRgn (&pmem_dc->ecrgn, &pmem_dc->DevRC); return (HDC)pmem_dc;}BOOL GUIAPI ConvertMemDC (HDC mem_dc, HDC ref_dc, DWORD flags){ PDC pmem_dc, pref_dc; GAL_Surface* new_surface; pmem_dc = dc_HDC2PDC (mem_dc); pref_dc = dc_HDC2PDC (ref_dc); new_surface = GAL_ConvertSurface (pmem_dc->surface, pref_dc->surface->format, flags | GAL_RLEACCEL); if (!new_surface) return FALSE; GAL_FreeSurface (pmem_dc->surface); pmem_dc->surface = new_surface; return TRUE;}BOOL GUIAPI SetMemDCAlpha (HDC mem_dc, DWORD flags, Uint8 alpha){ PDC pmem_dc = dc_HDC2PDC (mem_dc); return !GAL_SetAlpha (pmem_dc->surface, flags, alpha);}BOOL GUIAPI SetMemDCColorKey (HDC mem_dc, DWORD flags, Uint32 color_key){ PDC pmem_dc = dc_HDC2PDC (mem_dc); return !GAL_SetColorKey (pmem_dc->surface, flags, color_key);}void GUIAPI DeleteMemDC (HDC hdc){ PDC pmem_dc; pmem_dc = dc_HDC2PDC(hdc); GAL_FreeSurface (pmem_dc->surface); EmptyClipRgn (&pmem_dc->ecrgn); free (pmem_dc);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -