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

📄 gdi.c

📁 详细的MiniGUI源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
){	if(hDC->iCoordType == DC_COORDTYPE_CLIENT)		cliFillRectangle(hDC, nLeftRect, nTopRect, nRightRect, nBottomRect, crColor, crFillColor);	else		winFillRectangle(hDC, nLeftRect, nTopRect, nRightRect, nBottomRect, crColor, crFillColor);}//this function only called by functions to draw no client area of a windowBOOL cliFillRectangle(	HDC hDC,	int nLeftRect,	int nTopRect,	int nRightRect,	int nBottomRect,	COLORREF crColor,	COLORREF crFillColor){	int y;	POINT Point;	COLORREF crBackColor;	if(!hDC)		return false;	//backup pen color	crBackColor=((PPEN)(hDC->hPen))->crPenColor;	((PPEN)(hDC->hPen))->crPenColor=crColor;	cliRectangle(hDC,nLeftRect,nTopRect,nRightRect,nBottomRect);	((PPEN)(hDC->hPen))->crPenColor=crFillColor;	for(y=nTopRect+1;y<nBottomRect;y++){		cliMoveToEx(hDC,nLeftRect+1,y,&Point);		cliLineTo(hDC,nRightRect-1,y);	}	//restore pen color	((PPEN)(hDC->hPen))->crPenColor=crBackColor;	return true;}//this function only called by functions to draw no client area of a windowBOOL winFillRectangle(	HDC hDC,	int nLeftRect,	int nTopRect,	int nRightRect,	int nBottomRect,	COLORREF crColor,	COLORREF crFillColor){	int y;	POINT Point;	COLORREF crBackColor;	if(!hDC)		return false;	//backup pen color	crBackColor=((PPEN)(hDC->hPen))->crPenColor;	((PPEN)(hDC->hPen))->crPenColor=crColor;	winRectangle(hDC,nLeftRect,nTopRect,nRightRect,nBottomRect);	((PPEN)(hDC->hPen))->crPenColor=crFillColor;	for(y=nTopRect+1;y<nBottomRect;y++){		winMoveToEx(hDC,nLeftRect+1,y,&Point);		winLineTo(hDC,nRightRect-1,y);	}	//restore pen color	((PPEN)(hDC->hPen))->crPenColor=crBackColor;	return true;}BOOL GUIAPI Circle(	 HDC hDC, 	 int xCenter, 	 int yCenter, 	 int radius){	POINT ptOriginal;	COLORREF crColor;	COLORREF crBackColor;	if(!hDC)		return false;		ptOriginal.x = hDC->point.x;	ptOriginal.y = hDC->point.y;			if(!IsNullBrush(hDC)){		if(IsSolidBrush(hDC)){			crColor = GetSolidBrushColor(hDC);			crBackColor = ((PEN*)(hDC->hPen))->crPenColor;			((PEN*)(hDC->hPen))->crPenColor = crColor;			circleMiddlePointFill(hDC,xCenter, yCenter,radius);			((PEN*)(hDC->hPen))->crPenColor = crBackColor;		}	}	circleMiddlePoint(hDC,xCenter,yCenter, radius);	hDC->point.x = ptOriginal.x;	hDC->point.y = ptOriginal.y;	return true;}void circleMiddlePoint(	HDC hDC, 	int xCenter, 	int yCenter, 	int radius){	COLORREF color;	int x =0;	int y = radius;	int p = 1-radius;	color = ((PEN*)(hDC->hPen))->crPenColor;		SetPixel(hDC,xCenter+x,yCenter+y,color);	SetPixel(hDC,xCenter-x,yCenter+y,color);	SetPixel(hDC,xCenter+x,yCenter-y,color);	SetPixel(hDC,xCenter-x,yCenter-y,color);		SetPixel(hDC,xCenter+y,yCenter+x,color);	SetPixel(hDC,xCenter-y,yCenter+x,color);	SetPixel(hDC,xCenter+y,yCenter-x,color);	SetPixel(hDC,xCenter-y,yCenter-x,color);	while(x<y){		x++;		if(p<0)			p+=2*x+1;		else{			y--;			p+=2*(x-y)+1;		}		SetPixel(hDC,xCenter+x,yCenter+y,color);		SetPixel(hDC,xCenter-x,yCenter+y,color);		SetPixel(hDC,xCenter+x,yCenter-y,color);		SetPixel(hDC,xCenter-x,yCenter-y,color);		SetPixel(hDC,xCenter+y,yCenter+x,color);		SetPixel(hDC,xCenter-y,yCenter+x,color);		SetPixel(hDC,xCenter+y,yCenter-x,color);		SetPixel(hDC,xCenter-y,yCenter-x,color);	}}void circleMiddlePointFill(	HDC hDC, 	int xCenter, 	int yCenter, 	int radius){	POINT point;	COLORREF color;	int x =0;	int y = radius;	int p = 1-radius;	color = ((PEN*)(hDC->hPen))->crPenColor;	MoveToEx(hDC,xCenter-y,yCenter,&point);	LineTo(hDC,xCenter+y,yCenter);	while(x<y){		x++;		if(p<0)			p+=2*x+1;		else{			y--;			p+=2*(x-y)+1;		}		MoveToEx(hDC,xCenter+x,yCenter+y,&point);		LineTo(hDC,xCenter-x,yCenter+y);		MoveToEx(hDC,xCenter+x,yCenter-y,&point);		LineTo(hDC,xCenter-x,yCenter-y);		MoveToEx(hDC,xCenter+y,yCenter+x,&point);		LineTo(hDC,xCenter-y,yCenter+x);		MoveToEx(hDC,xCenter+y,yCenter-x,&point);		LineTo(hDC,xCenter-y,yCenter-x);	}}BOOL GUIAPIEllipse(	HDC hDC,	int nLeftRect,	int nTopRect,	int nRightRect, 	int nBottomRect){	POINT ptOriginal;	COLORREF crColor;	COLORREF crBackColor;	ClientToWindow(hDC->hWnd,&nLeftRect,&nTopRect);	ClientToWindow(hDC->hWnd,&nRightRect,&nBottomRect);		//backup original current point;	ptOriginal.x = hDC->point.x;	ptOriginal.y = hDC->point.y;	if(!IsNullBrush(hDC)){		if(IsSolidBrush){			crBackColor = ((PPEN)(hDC->hPen))->crPenColor;			crColor = GetSolidBrushColor(hDC);			((PPEN)(hDC->hPen))->crPenColor = crColor;					EllipseFill(hDC,nLeftRect,nTopRect,nRightRect,nBottomRect);			((PPEN)(hDC->hPen))->crPenColor = crBackColor;					}	}	EllipseBorder(hDC,nLeftRect,nTopRect,nRightRect,nBottomRect);		//restore current point of dc	hDC->point.x = ptOriginal.x;	hDC->point.y = ptOriginal.y;}BOOL EllipseBorder(	HDC hDC,	int nLeftRect,	int nTopRect,	int nRightRect, 	int nBottomRect){	int x0,y0,a,b;	int x,y;	float d1,d2;	COLORREF crColor;	if(!hDC)		return false;	crColor=((PEN*)(hDC->hPen))->crPenColor;	x0=nLeftRect+(nRightRect-nLeftRect)/2;	y0=nTopRect+(nBottomRect-nTopRect)/2;	a=nRightRect-x0;	b=nBottomRect-y0;	x=0;	y=b;	d1=(float)(b*b+a*a*(0.25-b));	SetPixel(hDC,x0+x,y0+y,crColor);	SetPixel(hDC,x0+x,y0-y,crColor);	SetPixel(hDC,x0-x,y0-y,crColor);	SetPixel(hDC,x0-x,y0+y,crColor);	while(b*b*(x+1)<a*a*(y-0.5))	{		if(d1<0){			d1+=b*b*(2*x+3);			x++;		}		else{			d1+=(b*b*(2*x+3)+a*a*(2-2*y));			x++;			y--;		}		SetPixel(hDC,x0+x,y0+y,crColor);		SetPixel(hDC,x0+x,y0-y,crColor);		SetPixel(hDC,x0-x,y0-y,crColor);		SetPixel(hDC,x0-x,y0+y,crColor);	}	d2=(float)(sqrt(b*(x+0.5))+a*(y-1)-a*b);	while(y>0){		if(d2<0){			d2+=b*b*(2*x+2)+a*a*(3-2*y);			x++;			y--;		}		else{			d2+=a*a*(3-2*y);			y--;		}		SetPixel(hDC,x0+x,y0+y,crColor);		SetPixel(hDC,x0+x,y0-y,crColor);		SetPixel(hDC,x0-x,y0-y,crColor);		SetPixel(hDC,x0-x,y0+y,crColor);	}	return true;}BOOL EllipseFill(	HDC hDC,	int nLeftRect,	int nTopRect,	int nRightRect, 	int nBottomRect){	int x0,y0,a,b;	int x,y;	float d1,d2;	POINT point;	if(!hDC)		return false;	x0=nLeftRect+(nRightRect-nLeftRect)/2;	y0=nTopRect+(nBottomRect-nTopRect)/2;	a=nRightRect-x0;	b=nBottomRect-y0;	x=0;	y=b;	d1=(float)(b*b+a*a*(0.25-b));	MoveToEx(hDC,x0+x,y0+y,&point);	LineTo(hDC,x0+x,y0-y);	MoveToEx(hDC,x0-x,y0-y,&point);	LineTo(hDC,x0-x,y0+y);	while(b*b*(x+1)<a*a*(y-0.5))	{		if(d1<0){			d1+=b*b*(2*x+3);			x++;		}		else{			d1+=(b*b*(2*x+3)+a*a*(2-2*y));			x++;			y--;		}		MoveToEx(hDC,x0+x,y0+y,&point);		LineTo(hDC,x0+x,y0-y);		MoveToEx(hDC,x0-x,y0-y,&point);		LineTo(hDC,x0-x,y0+y);			}	d2=(float)(sqrt(b*(x+0.5))+a*(y-1)-a*b);	while(y>0){		if(d2<0){			d2+=b*b*(2*x+2)+a*a*(3-2*y);			x++;			y--;		}		else{			d2+=a*a*(3-2*y);			y--;		}		MoveToEx(hDC,x0+x,y0+y,&point);		LineTo(hDC,x0+x,y0-y);		MoveToEx(hDC,x0-x,y0-y,&point);		LineTo(hDC,x0-x,y0+y);	}	return true;}/*----------------  	Polyline-----------------*/BOOL GUIAPIPolyline(	HDC hDC, 	POINT *lpPoints, 	int nCount){	POINT tmpPoint;	POINT point;	int i;	if(!hDC)		return false;	if(nCount<3)		return false;	//backup current point	point.x = hDC->point.x;	point.y = hDC->point.y;	MoveToEx(hDC,lpPoints[0].x,lpPoints[0].y,&tmpPoint);	for(i=1;i<nCount-1;i++){		//MoveToEx(hDC,lpPoints[i].x,lpPoints[i].y,&tmpPoint);		LineTo(hDC,lpPoints[i].x,lpPoints[i].y);	}	//restore current point 	hDC->point.x = point.x;	hDC->point.y = point.y;	return true;}/*----------------  	Polygon -----------------*/BOOL GUIAPIPolygon(	HDC hDC, 	POINT *lpPoints,	int nCount){	POINT tmpPoint;	POINT point;	int i;	POLYGON p;	COLORREF crColor;	COLORREF crBackColor;	if(nCount<3)		return false;	if(!hDC)		return false;		//backup current point position	point.x = hDC->point.x;	point.y = hDC->point.y;	if(!IsNullBrush(hDC)){		if(IsSolidBrush(hDC)){			p.num = nCount;			p.points = lpPoints;			//get brush color			crColor = GetSolidBrushColor(hDC);			//backup old pen color			crBackColor = ((PPEN)(hDC->hPen))->crPenColor;			((PPEN)(hDC->hPen))->crPenColor = crColor;			ras_FillPolygon(hDC, crColor, &p);			//restore old pen color			((PPEN)(hDC->hPen))->crPenColor = crBackColor;		}	}	MoveToEx(hDC,lpPoints[0].x,lpPoints[0].y,&tmpPoint);	for(i=1;i<nCount;i++){		LineTo(hDC,lpPoints[i].x,lpPoints[i].y);	}		LineTo(hDC,lpPoints[0].x,lpPoints[0].y);		//restore point position of dc	hDC->point.x = point.x;	hDC->point.y = point.y;	return true;} inline int polygon_GetN(	POLYGON* p){	return p->num;}inline POINT* polygon_RefNth(	POLYGON* p, 	int i){	return &(p->points[i]);}inline int point_GetY(	POINT* point){	return point->y;}inline int point_GetX(	POINT* point){	return point->x;}inline int SGN(	int data){	if(data > 0)		return 1;	if(data < 0)		return -1;	if(data == 0)		return 0;}inline int GetMinY(	POLYGON* p){	int i;	int iTotal;	int iMinY;	iTotal = p->num;	iMinY = p->points[0].y;	for(i=1;i<iTotal;i++){		if(p->points[i].y < iMinY)			iMinY = p->points[i].y;	}	if(iMinY < 0)		return iMinY;	else		return 0;}void ras_FillPolygon(	HDC hDC, 	COLORREF crColor, 	POLYGON *p){	static struct edge* edgeTable[MAXVERTICAL];	struct edge *active;	int curY;	int iMinY;		iMinY = GetMinY(p);	FillEdges(p, edgeTable,iMinY);	for (curY = 0; edgeTable[curY] == NULL; curY++)		if (curY == MAXVERTICAL - 1)			return;     /* No edges in polygon */	for (active = NULL; (active = UpdateActive(active, edgeTable, curY, iMinY)) != NULL; curY++)		DrawRuns(hDC, crColor, active, curY + iMinY);}void FillEdges(	POLYGON *p, 	struct edge *edgeTable[], 	int iMinY){	int i, j, n = polygon_GetN(p);	for (i = 0; i < MAXVERTICAL; i++)		edgeTable[i] = NULL;	for (i = 0; i < n; i++) {		POINT *p1, *p2, *p3;		struct edge *e;		p1 = polygon_RefNth(p, i);		p2 = polygon_RefNth(p, (i + 1) % n);		if (point_GetY(p1) == point_GetY(p2))			continue;   /* Skip horiz. edges */		/* Find next vertex not level with p2 */		for (j = (i + 2) % n; ; j = (j + 1) % n) {			p3 = polygon_RefNth(p, j);			if (point_GetY(p2) != point_GetY(p3))				break;		}		e = (struct edge*)malloc(sizeof(struct edge));		//e = New(struct edge);		e->xNowNumStep = abs(point_GetX(p1) - point_GetX(p2));		if (point_GetY(p2) > point_GetY(p1)) {			e->yTop = point_GetY(p1);			e->yBot = point_GetY(p2);			e->xNowWhole = point_GetX(p1);			e->xNowDir = SGN(point_GetX(p2) - point_GetX(p1));			e->xNowDen = e->yBot - e->yTop;			e->xNowNum = (e->xNowDen >> 1);			if (point_GetY(p3) > point_GetY(p2))				e->yBot--;		}		 else {			e->yTop = point_GetY(p2);			e->yBot = point_GetY(p1);			e->xNowWhole = point_GetX(p2);			e->xNowDir = SGN(point_GetX(p1) - point_GetX(p2));			e->xNowDen = e->yBot - e->yTop;			e->xNowNum = (e->xNowDen >> 1);			if (point_GetY(p3) < point_GetY(p2)) {				e->yTop++;				e->xNowNum += e->xNowNumStep;				while (e->xNowNum >= e->xNowDen) {				e->xNowWhole += e->xNowDir;				e->xNowNum -= e->xNowDen;				}			}		}		e->next = edgeTable[e->yTop - iMinY];		edgeTable[e->yTop - iMinY] = e;	}}struct edge*UpdateActive(	struct edge* active, 	struct edge* edgeTable[], 	int curY, 	int iMinY){	struct edge *e, **ep;	for (ep = &active, e = *ep; e != NULL; e = *ep)		if (e->yBot < curY+ iMinY) {			*ep = e->next;			free(e);		}		 else			ep = &e->next;	*ep = edgeTable[curY];	return active;}void DrawRuns(	HDC hDC, 	COLORREF crColor, 	struct edge* active,	int curY){	struct edge *e;	static int xCoords[100];	int numCoords = 0;	int i, x;	for (e = active; e != NULL; e = e->next) {		for (i = numCoords; i > 0 &&		xCoords[i - 1] > e->xNowWhole; i--)		xCoords[i] = xCoords[i - 1];		xCoords[i] = e->xNowWhole;		numCoords++;		e->xNowNum += e->xNowNumStep;		while (e->xNowNum >= e->xNowDen) {		e->xNowWhole += e->xNowDir;		e->xNowNum -= e->xNowDen;		}	}	if (numCoords % 2)  /* Protect from degenerate polygons */		xCoords[numCoords] = xCoords[numCoords - 1],		numCoords++;	for (i = 0; i < numCoords; i += 2) {		for (x = xCoords[i] + 1; x <xCoords[i + 1]; x++)			SetPixel(hDC,x,curY,crColor);	}}

⌨️ 快捷键说明

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