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

📄 display.c

📁 S3C44B0X全套培训资料及源代码 e008s3c44b0x
💻 C
📖 第 1 页 / 共 3 页
字号:
		OSMboxPost(LCDFresh_MBox,(void*)1);	//刷新LCD	OSSemPost(Lcd_Disp_Sem);}void MoveTo(PDC pdc, int x, int y){	pdc->DrawPointx=x;	pdc->DrawPointy=y;}U8 SetPenWidth(PDC pdc, U8 width){	U8 oldpenwidth=pdc->PenWidth;	pdc->PenWidth=width;	return oldpenwidth;}void DrawRectFrame(PDC pdc, int left,int top ,int right, int bottom){	U8 oldupMode=pdc->bUpdataBuffer;	pdc->bUpdataBuffer=FALSE;	MoveTo(pdc,left,top);	LineTo(pdc,left,bottom);	LineTo(pdc,right,bottom);	LineTo(pdc,right,top);	pdc->bUpdataBuffer=oldupMode;	LineTo(pdc,left,top);}void DrawRectFrame2(PDC pdc, structRECT *rect){	DrawRectFrame(pdc,rect->left,rect->top ,rect->right,rect->bottom);}void FillRect(PDC pdc, int left,int top ,int right, int bottom,U32 DrawMode, U32 color){	int i,j;	INT8U err;	OSSemPend(Lcd_Disp_Sem,0, &err);	for(i=left;i<=right;i++){		for(j=top;j<=bottom;j++)			SetPixel(pdc,i,j,color);	}	OSSemPost(Lcd_Disp_Sem);	if(pdc->bUpdataBuffer)		OSMboxPost(LCDFresh_MBox,(void*)1);	//刷新LCD}void FillRect2(PDC pdc, structRECT *rect,U32 DrawMode, U32 color){	FillRect(pdc, rect->left,rect->top ,rect->right,rect->bottom,DrawMode,color);}void ClearScreen(){	PDC pdc;	pdc=CreateDC();	FillRect(pdc,0,0,LCDWIDTH-1,LCDHEIGHT-1,GRAPH_MODE_NORMAL,COLOR_WHITE);	DestoryDC(pdc);}U32 SetPenMode(PDC pdc, U32 mode){	U32 oldMode=pdc->PenMode;	pdc->PenMode=mode;	return oldMode;}void Circle(PDC pdc, int x0, int y0, int r){	int x,y,delta,delta1,delta2,direction;	INT8U err;	x=0;	y=r;	delta=2*(1-r);	OSSemPend(Lcd_Disp_Sem, 0, &err);	while(y>=0){		SetPixel(pdc, x0+x,y0+y, pdc->PenColor);		SetPixel(pdc, x0+x,y0-y, pdc->PenColor);		SetPixel(pdc, x0-x,y0+y, pdc->PenColor);		SetPixel(pdc, x0-x,y0-y, pdc->PenColor);		if(delta<0){			delta1=2*(delta+y)-1;			if(delta1<=0)				direction=1;			else				direction=2;		}		else if(delta>0){			delta2=2*(delta-x)-1;			if(delta2<=0)				direction=2;			else				direction=3;		}		else			direction=2;		switch(direction){		case 1:			x++;			delta+=2*x+1;			break;		case 2:			x++;			y--;			delta+=2*(x-y+1);			break;		case 3:			y--;			delta+=-2*y+1;			break;		}	}	OSSemPost(Lcd_Disp_Sem);		if(pdc->bUpdataBuffer)		OSMboxPost(LCDFresh_MBox,(void*)1);	//刷新LCD}int Getdelta1(int x0,int y0, int R){	int delta;	if(x0>0 && y0>0)	//第一象限		delta = x0-y0+1;	else if(x0<0 && y0>0)	//第二象限		delta = x0+y0+1;	else if(x0<0 && y0<0)	//第三象限		delta = -x0+y0+1;	else if(x0>0 && y0<0)	//第四象限		delta = -x0-y0+1;	else		delta = -ABS(R)+1;	delta*=2;	return delta;}int Getdelta2(int x0,int y0, int R){	int delta;	if(x0>0 && y0>0)	//第一象限		delta = -x0+y0+1;	else if(x0<0 && y0>0)	//第二象限		delta = -x0-y0+1;	else if(x0<0 && y0<0)	//第三象限		delta = x0-y0+1;	else if(x0>0 && y0<0)	//第四象限		delta = x0+y0+1;	else		delta = -ABS(R)+1;	delta*=2;	return delta;}//画顺圆void ArcTo1(PDC pdc, int x1, int y1, int R){		int	delta, delta1, delta2, direction,x0,y0,dAB2,x2,y2;	int tmpx,tmpy;	double tmp;	x2=pdc->DrawPointx;	y2=pdc->DrawPointy;	tmpx=x1-x2;	tmpy=y1-y2;	dAB2=tmpx*tmpx+tmpy*tmpy;	if(dAB2==0)		return;	if(R*2>dAB2)		return;	tmp=sqrt(((double)R*R)/((double)dAB2)-0.25);	if(R>0){//劣弧		x0=(int)(0.5*(x1-x2)+tmp*(y1-y2)+x2);	//圆心坐标		y0=(int)(0.5*(y1-y2)-tmp*(x1-x2)+y2);	}	else{	//优弧		x0=(int)(0.5*(x1-x2)-tmp*(y1-y2)+x2);	//圆心坐标		y0=(int)(0.5*(y1-y2)+tmp*(x1-x2)+y2);	}		x2-=x0;
	y2-=y0;	x1-=x0;	y1-=y0;	delta=Getdelta1(x2,y2, R);	while ( ABS(x1-x2)>1 || ABS(y1-y2)>1){		SetPixel(pdc, x2+x0, y2+y0,pdc->PenColor);		if(x2>0 && y2>0){	//第一象限			if ( delta < 0 ){				delta1 = 2 * ( delta + y2) - 1;				if ( delta1 <= 0 )					direction = 1;//选择H点				else					direction = 2;//选择D点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta - x2 ) - 1;				if ( delta2 <= 0 )					direction = 2;//选择D点				else					direction = 3;//选择V点			}			else	//选择D点				direction = 2;		}		else if(x2<0 && y2>0){	//第二象限			if ( delta < 0 ){				delta1 = 2 * ( delta + y2) - 1;				if ( delta1 <= 0 )					direction = 1;//选择H点				else					direction = 8;//选择U点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta + x2 ) - 1;				if ( delta2 <= 0 )					direction = 8;//选择U点				else					direction = 7;//选择T点			}			else	//选择U点				direction = 8;		}		else if(x2<0 && y2<0){	//第三象限			if ( delta < 0 ){				delta1 = 2 * ( delta - y2) - 1;				if ( delta1 <= 0 )					direction = 5;//选择R点				else					direction = 6;//选择S点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta + x2 ) - 1;				if ( delta2 <= 0 )					direction = 6;//选择S点				else					direction = 7;//选择T点			}			else	//选择S点				direction = 6;		}		else if(x2>0 && y2<0){	//第四象限			if ( delta < 0 ){				delta1 = 2 * ( delta - y2) - 1;				if ( delta1 <= 0 )					direction = 5;//选择R点				else					direction = 4;//选择Q点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta - x2 ) - 1;				if ( delta2 <= 0 )					direction = 4;//选择Q点				else					direction = 3;//选择V点			}			else	//选择Q点				direction = 4;		}		else{			if(x2==0){				if(y2>0)					x2++;				else					x2--;			}			else{	//y2==0				if(x2>0)					y2--;				else					y2++;			}			delta=Getdelta1(x2,y2, R);		}		switch (direction)	{		case 1:			x2++;			delta += 2 * ABS(x2) + 1;			break;		case 2:
			x2++;			y2--;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		case 3:			y2--;			delta += ( -2 * ABS(y2) + 1 );			break;		case 4:			x2--;			y2--;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		case 5:			x2--;			delta += 2 * ABS(x2) + 1;			break;		case 6:			x2--;			y2++;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		case 7:			y2++;			delta += ( -2 * ABS(y2) + 1 );			break;		case 8:			x2++;			y2++;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		}	}}//画逆圆void ArcTo2(PDC pdc, int x1, int y1, int R){		int	delta, delta1, delta2, direction,x0,y0,dAB2,x2,y2;	int tmpx,tmpy;
	double tmp;	x2=pdc->DrawPointx;	y2=pdc->DrawPointy;	tmpx=x1-x2;	tmpy=y1-y2;	dAB2=tmpx*tmpx+tmpy*tmpy;	if(dAB2==0)		return;	if(R*2>dAB2)		return;	tmp=sqrt(((double)R*R)/((double)dAB2)-0.25);	if(R>0){//劣弧		x0=(int)(0.5*(x1-x2)-tmp*(y1-y2)+x2);	//圆心坐标		y0=(int)(0.5*(y1-y2)+tmp*(x1-x2)+y2);	}	else{	//优弧		x0=(int)(0.5*(x1-x2)+tmp*(y1-y2)+x2);	//圆心坐标		y0=(int)(0.5*(y1-y2)-tmp*(x1-x2)+y2);	}		x2-=x0;	y2-=y0;	x1-=x0;	y1-=y0;	delta=Getdelta2(x2,y2, R);	while ( ABS(x1-x2)>1 || ABS(y1-y2)>1){		SetPixel(pdc, x2+x0, y2+y0,pdc->PenColor);		if(x2>0 && y2>0){	//第一象限			if ( delta < 0 ){				delta1 = 2 * ( delta + y2) - 1;				if ( delta1 <= 0 )					direction = 5;//选择R点				else					direction = 6;//选择S点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta - x2 ) - 1;				if ( delta2 <= 0 )					direction = 6;//选择S点				else					direction = 7;//选择T点			}			else	//选择S点				direction = 6;		}		else if(x2<0 && y2>0){	//第二象限			if ( delta < 0 ){				delta1 = 2 * ( delta + y2) - 1;				if ( delta1 <= 0 )					direction = 5;//选择R点				else					direction = 4;//选择Q点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta + x2 ) - 1;				if ( delta2 <= 0 )					direction = 4;//选择Q点				else					direction = 3;//选择V点			}			else	//选择Q点				direction = 4;		}		else if(x2<0 && y2<0){	//第三象限			if ( delta < 0 ){				delta1 = 2 * ( delta - y2) - 1;				if ( delta1 <= 0 )					direction = 1;//选择H点				else					direction = 2;//选择D点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta + x2 ) - 1;				if ( delta2 <= 0 )					direction = 2;//选择D点				else					direction = 3;//选择V点			}			else	//选择D点				direction = 2;		}		else if(x2>0 && y2<0){	//第四象限			if ( delta < 0 ){				delta1 = 2 * ( delta - y2) - 1;				if ( delta1 <= 0 )					direction = 1;//选择H点				else					direction = 8;//选择U点			}			else if ( delta > 0 ){				delta2 = 2 * ( delta - x2 ) - 1;				if ( delta2 <= 0 )					direction = 8;//选择U点				else					direction = 7;//选择T点			}			else	//选择U点				direction = 8;		}		else{			if(x2==0){				if(y2>0)					x2--;				else					x2++;			}			else{	//y2==0				if(x2>0)					y2++;				else					y2--;			}			delta=Getdelta2(x2,y2, R);		}		switch (direction)	{		case 1:			x2++;			delta += 2 * ABS(x2) + 1;			break;		case 2:			x2++;			y2--;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		case 3:			y2--;			delta += ( -2 * ABS(y2) + 1 );			break;		case 4:			x2--;			y2--;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		case 5:			x2--;			delta += 2 * ABS(x2) + 1;			break;		case 6:			x2--;			y2++;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		case 7:			y2++;			delta += ( -2 * ABS(y2) + 1 );			break;
		case 8:			x2++;			y2++;			delta += 2 * ( ABS(x2) - ABS(y2) + 1);			break;		}//		OSMboxPost(LCDFresh_MBox,(void*)1);	//刷新LCD//		OSTimeDly(100);	}}void ArcTo(PDC pdc, int x1, int y1, U8 arctype, int R){	INT8U err;	OSSemPend(Lcd_Disp_Sem, 0, &err);	if(arctype){//逆圆		ArcTo2(pdc,x1,y1,R);	}	else{	//顺圆		ArcTo1(pdc,x1,y1,R);	}	pdc->DrawPointx=x1;	pdc->DrawPointy=y1;		OSSemPost(Lcd_Disp_Sem);	if(pdc->bUpdataBuffer)		OSMboxPost(LCDFresh_MBox,(void*)1);	//刷新LCD}U8 SetLCDUpdata(PDC pdc, U8 isUpdata){	U8 old=pdc->bUpdataBuffer;	pdc->bUpdataBuffer=isUpdata;	return old;}void Draw3DRect(PDC pdc, int left,int top, int right, int bottom, COLORREF color1, COLORREF color2){	int i;	INT8U err;	OSSemPend(Lcd_Disp_Sem, 0, &err);	////绘制左右边框	for(i=top;i<=bottom;i++){		SetPixel(pdc, left,i, color1);		SetPixel(pdc,right,i, color2);	}	////绘制上下边框	for(i=left;i<=right;i++){		SetPixel(pdc, i,top,color1);		SetPixel(pdc,i,bottom, color2);	}	OSSemPost(Lcd_Disp_Sem);	if(pdc->bUpdataBuffer)		OSMboxPost(LCDFresh_MBox,(void*)1);	//刷新LCD}void Draw3DRect2(PDC pdc, structRECT *rect, COLORREF color1, COLORREF color2){	Draw3DRect(pdc, rect->left,rect->top,rect->right,rect->bottom,color1,color2);}U8 GetPenWidth(PDC pdc){	return pdc->PenWidth;}U32 GetPenMode(PDC pdc){	return pdc->PenMode;}U32 SetPenColor(PDC pdc, U32 color){	U32 old=pdc->PenColor;	pdc->PenColor=color;	return old;}U32 GetPenColor(PDC pdc){	return pdc->PenColor;}void GetBmpSize(char filename[], int* Width, int *Height){	BITMAPFILEHEADER bmpfileheader;	BITMAPINFOHEADER bmpinfoheader;	static char bmp[1024];	FILE* pfile;	if((pfile=OpenOSFile(filename, FILEMODE_READ))==NULL)		return;	ReadOSFile(pfile, (U8*)bmp, 2);//	if((bmp[0]&0xffff)!='MB' )	//不是bmp文件	if(bmp[0]!='B' ||bmp[1] !='M')		return;	ReadOSFile(pfile, (U8*)&bmpfileheader, sizeof(BITMAPFILEHEADER));	ReadOSFile(pfile, (U8*)&bmpinfoheader, sizeof(BITMAPINFOHEADER));	*Width=bmpinfoheader.biWidth;	*Height=bmpinfoheader.biHeight;}void ShowBmp(PDC pdc, char filename[], int x, int y){	int i,j,k,nbyte;	U32 cx,cy;	U32 color;	FILE* pfile;	U8 *pbmp;	static U8 bmp[4096];	INT8U err;	BITMAPFILEHEADER bmpfileheader;	BITMAPINFOHEADER bmpinfoheader;	if((pfile=OpenOSFile(filename, FILEMODE_READ))==NULL)		return;	ReadOSFile(pfile, (U8*)bmp, 2);//	if((bmp[0]&0xffff)!='MB' )	//不是bmp文件	if(bmp[0]!='B' ||bmp[1] !='M')		return;	ReadOSFile(pfile, (U8*)&bmpfileheader, sizeof(BITMAPFILEHEADER));	ReadOSFile(pfile, (U8*)&bmpinfoheader, sizeof(BITMAPINFOHEADER));	cx=bmpinfoheader.biWidth;

⌨️ 快捷键说明

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