⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wingdi.c

📁 神龙卡开发原代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	return TRUE;}BOOL WINAPIRectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom){	HWND	hwnd;	RECT	rc;	hwnd = MwPrepareDC(hdc);	if(!hwnd)		return FALSE;	SetRect(&rc, nLeft, nTop, nRight, nBottom);	if(MwIsClientDC(hdc))		MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);	/* draw rectangle in current pen color*/	if(hdc->pen->style != PS_NULL) {		GdSetForeground(GdFindColor(hdc->pen->color));		GdRect(hdc->psd, rc.left, rc.top,			rc.right - rc.left, rc.bottom - rc.top);	}	/* fill rectangle in current brush color*/	if(hdc->brush->style != BS_NULL) {		InflateRect(&rc, -1, -1);		GdSetForeground(GdFindColor(hdc->brush->color));		GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,			rc.bottom - rc.top);	}	return TRUE;}BOOL WINAPIEllipse(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect){	HWND	hwnd;	int	rx, ry;	RECT	rc;	hwnd = MwPrepareDC(hdc);	if(!hwnd)		return FALSE;	SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);	if(MwIsClientDC(hdc))		MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);	rx = (rc.right - rc.left)/2 - 1;	ry = (rc.bottom - rc.top)/2 - 1;	rc.left += rx;	rc.top += ry;	/* fill ellipse in current brush color*/	if(hdc->brush->style != BS_NULL) {		InflateRect(&rc, -1, -1);		GdSetForeground(GdFindColor(hdc->brush->color));		GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, TRUE);	}	/* draw ellipse outline in current pen color*/	if(hdc->pen->style != PS_NULL) {		GdSetForeground(GdFindColor(hdc->pen->color));		GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, FALSE);	}	return TRUE;}static voiddopiearc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,	int ax, int ay, int bx, int by, int type){	HWND	hwnd;	int	rx, ry;	RECT	rc, rc2;	hwnd = MwPrepareDC(hdc);	if(!hwnd)		return;	SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);	SetRect(&rc2, ax, ay, bx, by);	if(MwIsClientDC(hdc)) {		MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);		MapWindowPoints(hwnd, NULL, (LPPOINT)&rc2, 2);	}	rx = (rc.right - rc.left)/2 - 1;	ry = (rc.bottom - rc.top)/2 - 1;	rc.left += rx;	rc.top += ry;	/* fill ellipse in current brush color*/	if(hdc->brush->style != BS_NULL && type == MWPIE) {		GdSetForeground(GdFindColor(hdc->brush->color));		GdArc(hdc->psd, rc.left, rc.top, rx, ry,			rc2.left, rc2.top, rc2.right, rc2.bottom, MWPIE);	}	/* draw ellipse outline in current pen color*/	if(hdc->pen->style != PS_NULL) {		GdSetForeground(GdFindColor(hdc->pen->color));		if(type == MWPIE)			type = MWARC;	/* MWARCOUTLINE?*/		GdArc(hdc->psd, rc.left, rc.top, rx, ry,			rc2.left, rc2.top, rc2.right, rc2.bottom, type);	}}BOOL WINAPIArc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,	int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc){	dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,		nXStartArc, nYStartArc, nXEndArc, nYEndArc, MWARC);	return TRUE;}BOOL WINAPIPie(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,	int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2){	dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,		nXRadial1, nYRadial1, nXRadial2, nYRadial2, MWPIE);	return TRUE;}BOOL WINAPIPolygon(HDC hdc, CONST POINT *lpPoints, int nCount){	HWND	hwnd;	int	i;	LPPOINT	pp, ppAlloc = NULL;	hwnd = MwPrepareDC(hdc);	if(!hwnd)		return FALSE;	if(MwIsClientDC(hdc)) {		/* convert points to client coords*/		ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT));		if(!ppAlloc)			return FALSE;		memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT));		pp = ppAlloc;		for(i=0; i<nCount; ++i)			ClientToScreen(hwnd, pp++);		pp = ppAlloc;	} else pp = (LPPOINT)lpPoints;	/* fill polygon in current brush color*/	if(hdc->brush->style != BS_NULL) {		GdSetForeground(GdFindColor(hdc->brush->color));		GdFillPoly(hdc->psd, nCount, pp);	}	/* draw polygon outline in current pen color*/	if(hdc->pen->style != PS_NULL) {		GdSetForeground(GdFindColor(hdc->pen->color));		GdPoly(hdc->psd, nCount, pp);	}	if(ppAlloc)		free(ppAlloc);	return TRUE;}/* draw nCount polygons*/BOOL WINAPIPolyPolygon(HDC hdc, CONST POINT *lpPoints, LPINT lpPolyCounts, int nCount){	while(--nCount >= 0) {		if (!Polygon(hdc, lpPoints, *lpPolyCounts))			return FALSE;		lpPoints += *lpPolyCounts++;	}	return TRUE;}int WINAPIFillRect(HDC hdc, CONST RECT *lprc, HBRUSH hbr){	HWND		hwnd;	RECT 		rc;	MWBRUSHOBJ *	obr = (MWBRUSHOBJ *)hbr;	COLORREF	crFill;	hwnd = MwPrepareDC(hdc);	if(!hwnd || !obr)		return FALSE;	if(!lprc) {		if(MwIsClientDC(hdc))			GetClientRect(hwnd, &rc);		else			GetWindowRect(hwnd, &rc);		lprc = &rc;	} else		rc = *lprc;	if(MwIsClientDC(hdc))		MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);	/* handle COLOR_xxx + 1 passed as HBRUSH*/	if((PTRTOINT)obr <= MAXSYSCOLORS)		crFill = GetSysColor((int)obr-1);	else {		/* get color from passed HBRUSH*/		if(obr->style == BS_NULL)			return TRUE;		crFill = obr->color;	}	/* fill rectangle in passed brush color*/	GdSetForeground(GdFindColor(crFill));	GdFillRect(hdc->psd, rc.left, rc.top,		rc.right - rc.left, rc.bottom - rc.top);	return TRUE;}/* ascii*/BOOL WINAPITextOut(HDC hdc, int x, int y, LPCSTR lpszString, int cbString){	/* kaffe port wants MWTF_UTF8 here...*/	return MwExtTextOut(hdc, x, y, 0, NULL, lpszString, cbString, NULL,		MWTF_ASCII);}/* ascii*/BOOL WINAPIExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,	LPCSTR lpszString, UINT cbCount, CONST INT *lpDx){	return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,		cbCount, lpDx, MWTF_ASCII);}/* unicode*/BOOL WINAPIExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,	LPCWSTR lpszString, UINT cbCount, CONST INT *lpDx){	return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,		cbCount, lpDx, MWTF_UC16);}/* internal version of ExtTextOut, passed flags for text data type*/static BOOLMwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,	LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags){	HWND	hwnd;	POINT	pt;	RECT	rc;	hwnd = MwPrepareDC(hdc);	if(!hwnd)		return FALSE;	pt.x = x;	pt.y = y;	if(MwIsClientDC(hdc))		ClientToScreen(hwnd, &pt);	/* optionally fill passed rectangle*/	if(lprc && (fuOptions&ETO_OPAQUE)) {		rc = *lprc;		if(MwIsClientDC(hdc))			MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);		/* fill rectangle with current background color*/		GdSetForeground(GdFindColor(hdc->bkcolor));		GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,			rc.bottom - rc.top);		GdSetUseBackground(FALSE);	} else {		/* use current background mode for text background draw*/		GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE);		/* always set background color in case GdArea is		 * used to draw, which compares gr_foreground != gr_background		 * if gr_usebg is false...		 */		/*if(hdc->bkmode == OPAQUE)*/			GdSetBackground(GdFindColor(hdc->bkcolor));	}	/* nyi: lpDx*/	/* draw text in current text foreground and background color*/	GdSetForeground(GdFindColor(hdc->textcolor));	GdSetFont(hdc->font->pfont);	/* this whole text alignment thing needs rewriting*/	if((hdc->textalign & TA_BASELINE) == TA_BASELINE) {		 /* this is not right... changed for kaffe port		flags |= MWTF_TOP;		 */		flags |= MWTF_BASELINE;	} else if(hdc->textalign & TA_BOTTOM) {		MWCOORD	ph, pw, pb;		if(lprc)			pt.y += lprc->bottom - lprc->top;		else {			GdGetTextSize(hdc->font->pfont, lpszString, cbCount,				&pw, &ph, &pb, flags);			pt.y += ph;		}		flags |= MWTF_BOTTOM;	} else		flags |= MWTF_TOP;	GdText(hdc->psd, pt.x, pt.y, lpszString, cbCount, flags);	return TRUE;}/* ascii*/int WINAPIDrawTextA(HDC hdc, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat){	return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_ASCII);}/* unicode*/int WINAPIDrawTextW(HDC hdc, LPCWSTR lpString, int nCount, LPRECT lpRect, UINT uFormat){	return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_UC16);}/* note: many DT_x aren't implemented in this function*//* internal version of DrawText, passed flags for text data type*/static intMwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat,	int flags){	MWCOORD	x, y, width, height, baseline;	if(nCount == -1)		nCount = strlen(lpString);	if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) {		if(!hdc)			return 0;		GdGetTextSize(hdc->font->pfont, lpString, nCount,			&width, &height, &baseline, MWTF_ASCII);	}	x = lpRect->left;	y = lpRect->top;	if(uFormat & DT_CALCRECT) {		lpRect->right = x + width;		lpRect->bottom = y + height;		return height;	}	if(uFormat & DT_CENTER)		x = (lpRect->left + lpRect->right - width) / 2;	else if(uFormat & DT_RIGHT)		x += lpRect->right - width;	/* draw text at DT_TOP using current fg, bg and bkmode*/	MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags);	return height;}/* Microwindows only*/BOOL WINAPIDrawDIB(HDC hdc,int x,int y,PMWIMAGEHDR pimage){	HWND		hwnd;	POINT		pt;	hwnd = MwPrepareDC(hdc);	if(!hwnd || !pimage)		return FALSE;	pt.x = x;	pt.y = y;	if(MwIsClientDC(hdc))		ClientToScreen(hwnd, &pt);	GdDrawImage(hdc->psd, pt.x, pt.y, pimage);	return TRUE;}/* define color scheme: A (tan), B (winstd) or C (old)*/#if ELKS#define B#else#define A#endif#define A_RGB(r,g,b)#define B_RGB(r,g,b)#define C_RGB(r,g,b)#ifdef A#undef  A_RGB#define A_RGB(r,g,b)	RGB(r,g,b),#endif#ifdef B#undef  B_RGB#define B_RGB(r,g,b)	RGB(r,g,b),#endif#ifdef C#undef  C_RGB#define C_RGB(r,g,b)	RGB(r,g,b),#endifstatic COLORREF sysColors[MAXSYSCOLORS] = {	RGB(192, 192, 192),	/* COLOR_SCROLLBAR          0*/	RGB(  0, 128, 128),     /* COLOR_BACKGROUND          */	A_RGB(128,   0,   0)	/* COLOR_ACTIVECAPTION       */	B_RGB(128,   0, 128)	/* COLOR_ACTIVECAPTION       */	C_RGB(128,   0, 128)	/* COLOR_ACTIVECAPTION       */	A_RGB(162, 141, 104)	/* COLOR_INACTIVECAPTION     */	B_RGB(128, 128, 128)  	/* COLOR_INACTIVECAPTION     */	C_RGB(  0,  64, 128)	/* COLOR_INACTIVECAPTION     */	RGB(192, 192, 192),     /* COLOR_MENU                */	RGB(255, 255, 255),     /* COLOR_WINDOW             5*/	RGB(  0,   0,   0),     /* COLOR_WINDOWFRAME         */	RGB(  0,   0,   0),     /* COLOR_MENUTEXT            */	RGB(  0,   0,   0),     /* COLOR_WINDOWTEXT          */	RGB(255, 255, 255),     /* COLOR_CAPTIONTEXT         */	RGB(192, 192, 192),   	/* COLOR_ACTIVEBORDER      10*/	RGB(192, 192, 192), 	/* COLOR_INACTIVEBORDER      */	RGB(128, 128, 128),   	/* COLOR_APPWORKSPACE        */	RGB(128,   0,   0),     /* COLOR_HIGHLIGHT           */	RGB(255, 255, 255),     /* COLOR_HIGHLIGHTTEXT       */	A_RGB(213, 204, 187)	/* COLOR_BTNFACE           15*/	B_RGB(192, 192, 192)	/* COLOR_BTNFACE           15*/	C_RGB(160, 160, 160)	/* COLOR_BTNFACE           15*/	A_RGB(162, 141, 104)	/* COLOR_BTNSHADOW           */	B_RGB(128, 128, 128)	/* COLOR_BTNSHADOW           */	C_RGB(128, 128, 128)	/* COLOR_BTNSHADOW           */	RGB( 64,  64,  64),     /* COLOR_GRAYTEXT            */	RGB(  0,   0,   0),     /* COLOR_BTNTEXT             */	RGB(192, 192, 192),    	/* COLOR_INACTIVECAPTIONTEXT */	A_RGB(234, 230, 221)  	/* COLOR_BTNHIGHLIGHT      20*/	B_RGB(255, 255, 255)  	/* COLOR_BTNHIGHLIGHT      20*/	C_RGB(223, 223, 223)  	/* COLOR_BTNHIGHLIGHT      20*/	RGB(  0,   0,   0),     /* COLOR_3DDKSHADOW          */	A_RGB(213, 204, 187)	/* COLOR_3DLIGHT             */	B_RGB(223, 223, 223)	/* COLOR_3DLIGHT             */	C_RGB(192, 192, 192)	/* COLOR_3DLIGHT             */	RGB(  0,   0,   0),     /* COLOR_INFOTEXT            */	RGB(225, 255, 255), 	/* COLOR_INFOBK              */	RGB(184, 180, 184),  	/* COLOR_ALTERNATEBTNFACE  25*/	RGB(  0,   0, 255),     /* COLOR_HOTLIGHT 	     */	RGB( 16, 132, 208),  	/* COLOR_GRADIENTACTIVECAPTION */	RGB(184, 180, 184) 	/* COLOR_GRADIENTINACTIVECAPTION 28*/};DWORD WINAPIGetSysColor(int nIndex){	if(nIndex >= 0 && nIndex < MAXSYSCOLORS)		return sysColors[nIndex];	return 0;}COLORREF WINAPISetSysColor(int nIndex, COLORREF crColor)	/* Microwindows only*/{	COLORREF oldColor;	if(nIndex >= 0 && nIndex < MAXSYSCOLORS) {		oldColor = sysColors[nIndex];		sysColors[nIndex] = crColor;		return oldColor;	}	return 0;}static MWBRUSHOBJ OBJ_WHITE_BRUSH = {	{OBJ_BRUSH, TRUE}, BS_SOLID, RGB(255, 255, 255)};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -