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

📄 gdi.c

📁 嵌入式系统ucgui图形接口源程序在arm7 s3c44b0x 开发板上的移植测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	HDC hDC,有效的HDC指针
出口:
	返回颜色值
***********************************************************************/
COLORREF GetTextColor(HDC hDC)
{
	if(!hDC) return 0;
	return hDC->ccTextColor;
}

/**************************函数名称:SetTextColor()*********************
功能:设置HDC的文字颜色
入口:
	HDC hDC,HDC指针
	COLORREF ccColor,要更改的颜色值
出口:
	返回原来的颜色值
************************************************************************/
COLORREF SetTextColor(HDC hDC,COLORREF ccColor)
{
	COLORREF ret=0;
	if(!hDC) return 0;
	ret=hDC->ccTextColor;
	hDC->ccTextColor=ccColor;
	return ret;
}		

/**************************函数名称:GetBkColor()***********************
功能:返回HDC的文字背景颜色
入口:
	HDC hDC,HDC指针
出口:
	返回指定的HDC的文字背景颜色
***********************************************************************/
COLORREF GetBkColor(HDC hDC)
{
	if(!hDC) return 0;
	return hDC->ccBkColor;
}

/**************************函数名称:SetBkColor()***********************
功能:设置HDC的文字背景颜色
入口:
	HDC hDC,HDC指针
	COLORREF ccColor,要更改的背景颜色
出口:
	返回指定的HDC的文字背景颜色
***********************************************************************/
COLORREF SetBkColor(HDC hDC,COLORREF ccColor)
{
	COLORREF ret;
	if(!hDC) return 0;
	ret=hDC->ccBkColor;
	hDC->ccBkColor=ccColor;
	return ret;
}

/**************************函数名称:GetBkMode()***********************
功能:返回HDC的背景输出模式
入口:
	HDC hDC,HDC指针
出口:
	返回指定的HDC的背景输出模式(0=使用背景颜色,1=透明显示)
***********************************************************************/
int GetBkMode(HDC hDC)
{
	if(!hDC) return 0;
	return hDC->nMode;
}

/**************************函数名称:SetBkMode()***********************
功能:设置HDC的文字背景输出模式
入口:
	HDC hDC,HDC指针
	int nMode,模式值,0=使用背景颜色,1=透明显示文字
出口:
	成功,返回原来文字背景模式
	失败,返回-1
***********************************************************************/
int SetBkMode(HDC hDC,int nMode)
{
	int ret;
	if(!hDC||nMode<0||nMode>1) return -1;
	ret=hDC->nMode;
	hDC->nMode=nMode;
	return ret;
}



/**************************函数名称:LineTo()***********************
功能:返回HDC(x,y)处的颜色
入口:
	HDC hDC:HDC指针
	x,y:x,y坐标
出口:
	成功,返回1
	失败,总是返回0
***********************************************************************/
BOOL LineTo(HDC hDC,int x,int y)
{
	int x1,y1,x2=x,y2=y;
	int dx,dy,e;
	COLORREF ccColor=0xff;
	if(!hDC) return 0;
	if(hDC->hPen)ccColor=hDC->hPen->ccColor;

	x1=hDC->nX;
	y1=hDC->nY;
	dx=x2-x1; 
	dy=y2-y1;
    
	if(dx>=0)
	{
		if(dy >= 0) 
		{
			if(dx>=dy) 
			{
				e=dy-dx/2;
				while(x1<=x2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){y1+=1;e-=dx;}	
					x1+=1;
					e+=dy;
				}
			}
			else	
			{
				e=dx-dy/2;
				while(y1<=y2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){x1+=1;e-=dy;}	
					y1+=1;
					e+=dx;
				}
			}
		}
		else		   
		{
			dy=-dy;   

			if(dx>=dy) 
			{
				e=dy-dx/2;
				while(x1<=x2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){y1-=1;e-=dx;}	
					x1+=1;
					e+=dy;
				}
			}
			else		
			{
				e=dx-dy/2;
				while(y1>=y2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){x1+=1;e-=dy;}	
					y1-=1;
					e+=dx;
				}
			}
		}	
	}
	else 
	{
		dx=-dx;		
		if(dy >= 0) 
		{
			if(dx>=dy) 
			{
				e=dy-dx/2;
				while(x1>=x2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){y1+=1;e-=dx;}	
					x1-=1;
					e+=dy;
				}
			}
			else	
			{
				e=dx-dy/2;
				while(y1<=y2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){x1-=1;e-=dy;}	
					y1+=1;
					e+=dx;
				}
			}
		}
		else	
		{
			dy=-dy; 

			if(dx>=dy) 
			{
				e=dy-dx/2;
				while(x1>=x2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){y1-=1;e-=dx;}	
					x1-=1;
					e+=dy;
				}
			}
			else	
			{
				e=dx-dy/2;
				while(y1>=y2)
				{
					SetPixel(hDC,x1,y1,ccColor);
					if(e>0){x1-=1;e-=dy;}	
					y1-=1;
					e+=dx;
				}
			}
		}	
	}

	hDC->nX=x;
	hDC->nY=y;
	return 1;
}

/**************************函数名称:MoveToEx()***********************
功能:返回HDC(x,y)处的颜色
入口:
	HDC hDC:HDC指针
	x,y:x,y坐标
	pt:保存原来的位置
出口:
	成功,返回1
	失败,总是返回0
***********************************************************************/
BOOL MoveToEx(HDC hDC,int x,int y,LPPOINT pt)
{
	if(!hDC) return 0;
	if(pt)
	{
		pt->x=hDC->nX;
		pt->y=hDC->nY;
	}
	hDC->nX=x;
	hDC->nY=y;
	return 1;
}

/**************************函数名称:MoveTo()***********************
功能:返回HDC(x,y)处的颜色
入口:
	HDC hDC:HDC指针
	x,y:x,y坐标
出口:
	成功,返回1
	失败,总是返回0
***********************************************************************/
BOOL MoveTo(HDC hDC,int x,int y)
{
	return MoveToEx(hDC,x,y,NULL);
}


/**************************函数名称:Polyline()***********************
功能:返回HDC(x,y)处的颜色
入口:
	HDC hDC:HDC指针
	pt:坐标数组
	ccPoints:坐标个数
出口:
	成功,返回1
	失败,总是返回0
***********************************************************************/
BOOL Polyline(HDC hDC,POINT *pt,int ccPoints)
{
	POINT ret;
	int i;
	if(!hDC||!pt||ccPoints<2) return 0;
	ret.x=hDC->nX;
	ret.y=hDC->nY;
	for(i=0;i<ccPoints-1;i++)
	{
		MoveTo(hDC,pt[i].x,pt[i].y);
		LineTo(hDC,pt[i+1].x,pt[i+1].y);
	}	
	MoveTo(hDC,pt[0].x,pt[0].y);
	LineTo(hDC,pt[ccPoints-1].x,pt[ccPoints-1].y);
	MoveTo(hDC,ret.x,ret.y);
	return 1;
}

/**************************函数名称:Rectangle()***********************
功能:返回HDC(x,y)处的颜色
入口:
	HDC hDC:HDC指针
	nLeft,nTop,nRight,nBottom:四个点的坐标
出口:
	成功,返回1
	失败,总是返回0
***********************************************************************/
BOOL Rectangle(HDC hDC,int nLeft,int nTop,int nRight,int nBottom)
{
	UINT i;
	if(!hDC) return 0;
	if(!hDC->bFilled)
	{
		MoveTo(hDC,nLeft,nTop);
		LineTo(hDC,nRight,nTop);
		MoveTo(hDC,nRight,nTop);
		LineTo(hDC,nRight,nBottom);
		MoveTo(hDC,nLeft,nBottom);
		LineTo(hDC,nRight,nBottom);
		MoveTo(hDC,nLeft,nTop);
		LineTo(hDC,nLeft,nBottom);
	}
	else
	{
	    for(i=nTop;i<=nBottom;i++)
		{
			MoveTo(hDC,nLeft,i);
			LineTo(hDC,nRight,i);
		}
	}
	return 1;
}


/**************************函数名称:BitBlt()***********************
功能:
	两个HDC之间进行位块传输(^_^,暂时只是用Pixel操作,速度慢得可以)
入口:
	HDC hdcDest:HDC目的指针
	nXDest,nYDest:目标DC开始坐标
	nWidth,nHeight:复制的大小(必须是源DC的大小)
	HDC hdcSource:HDC源指针
	nXSrc,nYSrc:源DC开始坐标(必须是0)
	dwRop:复制属性
出口:
	成功,返回1
	失败,总是返回0
***********************************************************************/
BOOL BitBlt(HDC hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,HDC hdcSource,int nXSrc,int nYSrc,DWORD dwRop)
{
	UINT i,j;
	UINT x,y;
	COLORREF color;
	if(!hdcDest||!hdcSource) return 0;
	if(hdcDest==hdcSource) return 1;
	if(nXDest>=hdcDest->nWidth||nYDest>=hdcDest->nHeight) return 0;
	if(nXSrc>=hdcSource->nWidth||nYSrc>=hdcSource->nHeight) return 0;
	y=nYDest;
	for(i=nYSrc;i<nWidth;i++)
	{
		x=nXDest;
		for(j=nXSrc;j<nHeight;j++)
		{
			color=GetPixel(hdcSource,j,i);
			SetPixel(hdcDest,x++,y,color);				
		}
		y++;
	}

	return 1;
}

/****************************函数名称:CreateFont()***********************************
功能:建立一个字体
入口:
	int nHeight:字体宽
	int nWidth:字体长
	其他:未使用,全部应该是0
出口:
	成功,返回一个HFONT指针
	失败,返回NULL
************************************************************************************/
HFONT CreateFont(int nHeight,int nWidth,int nReserved1,int nReserved2,int nReserved3,int nReserved4,int nReserved5,int nReserved6,int nReserved7,int nReserved8,int nReserved9,int nReserved10,int nReserved11,LPCTSTR szFontName)
{
	HFONT hFont=(HFONT)malloc(sizeof(_HFONT_));
	if(!hFont) return NULL;
	while(nHeight%8) nHeight++;
	while(nWidth%8) nWidth++;
	hFont->nObject=OBJ_FONT;
	hFont->nXOrg=8;
	hFont->nYOrg=8;
	hFont->nXScale=nWidth/8;
	hFont->nYScale=nHeight/8;
	return hFont;
}

/****************************函数名称:CreatePen()******************************
功能:
	用指定的颜色创建画笔
入口:
	nPenStyle,nWidth:暂时不支持
	ccColor:画笔的颜色
出口:
	成功,返回HPEN的指针
	失败,返回NULL
******************************************************************************/
HPEN CreatePen(UINT nPenStyle,UINT nWidth,COLORREF ccColor)
{
	HPEN hPen=(HPEN)malloc(sizeof(_HPEN_));
	if(!hPen) return NULL;
	hPen->nObject=OBJ_PEN;
	hPen->ccColor=ccColor;
	return hPen;
}


/********************************函数名称:SelectObject()***************************
功能:装载指定的GDI Object
入口:
	HDC hDC,目标HDC
	HGDIOBJ hObj,要装入的对象
出口:
	返回原来的HGDIOBJ
**********************************************************************************/
HGDIOBJ SelectObject(HDC hDC,HGDIOBJ hObj)
{
	HGDIOBJ hret;
	unsigned int *item=(UINT*)hObj;
	if(!hDC||!hObj) return NULL;
/*查找发现是哪种Object*/
	switch(*item)
	{
		case OBJ_FONT:
			hret=(HGDIOBJ)hDC->hFont;
			hDC->hFont=(HFONT)hObj;
			break;
		case OBJ_PEN:
			hret=(HGDIOBJ)hDC->hPen;
			hDC->hPen=(HPEN)hObj;
			break;
		case OBJ_BRUSH:/*其他的OBJECT暂时不支持*/
		default:
			break;
	}
	return hret;	
}	

/*********************************函数名称:FloodFill()******************************
功能:
	对HDC用指定颜色填充
入口:
	HDC hdc,设备Handle
	int nXStart,nYStart,未使用
	COLORREF crFill,要填充的颜色
出口:
	成功,总是返回1
	失败,返回0
************************************************************************************/

BOOL FloodFill(HDC hdc,int nXStart,int nYStart,COLORREF crFill)
{
	UINT color;
	UINT *buff;
	UINT nSize;
	if(!hdc) return 0;
	buff=(UINT*)hdc->lpImage;
	if(!buff) return 0;
	switch(hdc->nColors)
	{
		case 1:
			if(!crFill) color=0x00000000;
			else color=0xffffffff;
			break;
		case 2:
			crFill&=0x03;
			color=(crFill<<30)|(crFill<<28)|(crFill<<24)|(crFill<<22)|(crFill<<20)|(crFill<<18)|(crFill<<16)|(crFill<<14)|(crFill<<12)|(crFill<<10)|(crFill<<8)|(crFill<<6)|(crFill<<4)|(crFill<<2)|crFill;
			break;
		case 4:
			crFill&=0x0f;
			color=(crFill<<28)|(crFill<<24)|(crFill<<20)|(crFill<<16)|(crFill<<12)|(crFill<<8)|(crFill<<4)|crFill;
			break;
		case 8:
			crFill&=0xff;
			color=(crFill<<24)|(crFill<<16)|(crFill<<8)|crFill;
			break;
	}
	nSize=GetImageSize(hdc);
	while(nSize--) *buff++=color;
	return 1;
}

#endif

⌨️ 快捷键说明

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