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

📄 directdisplay.c

📁 ucos-II+移植到arm+s3c2410的全套代码
💻 C
📖 第 1 页 / 共 3 页
字号:

}


void Direct_DrawSBresenham_Line(PDC pdc, int x1, int y1,int x2, int y2)
{
	int x, y,dx,dy;
	int e,i;
	dx=x2-x1;
	dy=y2-y1;
	x=x1;	y=y1;

	if ( ABS(dx) >= ABS(dy) ){
		if ( dx >= 0 &&  dy>=0 ){
			e = -dx;
			for ( i = 0; i <= dx; i++ )	{
				Direct_SetPixel(pdc,x++,y,pdc->PenColor);
				e += 2 * dy;
				if (e >= 0)	{
					y = y + 1;
					e -= 2 * dx;
				}
			}
		}
		else if( dx < 0 &&  dy<0 ){
			e = -dx;
			for ( i = 0; i >= dx; i-- ){
				Direct_SetPixel(pdc,x--,y,pdc->PenColor);
				e += 2 * dy;
				if (e <= 0)	{
					y = y - 1;
					e -=  2 * dx;
				}
			}
		}
		else if(dx>=0 && dy<=0){
			e = dx;
			for ( i = 0; i <= dx; i++ ){
				Direct_SetPixel(pdc,x++,y,pdc->PenColor);
				e +=  2 * dy;
				if (e <= 0)	{
					y = y - 1;
					e +=  2 * dx;
				}
			}
		}
		else{	//dx<0 && dy>0
			e = dx;
			for ( i = 0; i >= dx; i-- ){
				Direct_SetPixel(pdc,x--,y,pdc->PenColor);
				e +=  2 * dy;
				if (e >= 0)	{
					y = y + 1;
					e +=  2 * dx;
				}
			}
		}
	}
	else{
		if ( dx >= 0 &&  dy>=0 ){
			e = -dy;
			for ( i = 0; i <= dy; i++ )	{
				Direct_SetPixel(pdc,x,y++,pdc->PenColor);
				e +=  2 * dx;
				if (e >= 0)	{
					x = x + 1;
					e -=  2 * dy;
				}
			}
		}
		else if( dx < 0 &&  dy<0 ){
			e = -dy;
			for ( i = 0; i >= dy; i-- ){
				Direct_SetPixel(pdc,x,y--,pdc->PenColor);
				e +=  2 * dx;
				if (e <= 0)	{
					x = x - 1;
					e -=  2 * dy;
				}
			}
		}
		else if(dx<=0 && dy>=0){
			e = dy;
			for ( i = 0; i <= dy; i++ ){
				Direct_SetPixel(pdc,x,y++,pdc->PenColor);
				e +=  2 * dx;
				if (e <= 0)	{
					x = x - 1;
					e +=  2 * dy;
				}
			}
		}
		else{	//dx>0 && dy<0
			e = dy;
			for ( i = 0; i >= dy; i-- ){
				Direct_SetPixel(pdc,x,y--,pdc->PenColor);
				e +=  2 * dx;
				if (e >= 0)	{
					x = x + 1;
					e +=  2 * dy;
				}
			}
		}
	}
}

void Direct_FillRect(PDC pdc, int left,int top ,int right, int bottom,U32 DrawMode, U32 color)
{
	int i=0;
	int j=0;

	int  temp_left=0;
	int  temp_right=0;

	U32 temp_color=0x00000000;
	U32* p;

       pdc->PenMode=DrawMode;

	i=left;

	#if  COLORDEPTH_GRAY==1	

	
	while(i%8!=0&&i<=right){
		    for( j=top;j<=bottom;j++)
				Direct_SetPixel(pdc, i, j, color);
		    i++;
               }
	if(i==right+1)
		return;
	
	for( j=top;j<=bottom;j++)
				Direct_SetPixel(pdc, i, j, color);
	temp_left=i;

	i=right;
	while(i%8!=0){
		    for(j=top;j<=bottom;j++)
				Direct_SetPixel(pdc, i, j, color);
		    i--;
		}
			
	temp_right=i;

	if(temp_left==temp_right)
		return;
    temp_color=color|color<<4|color<<8|color<<12
	   	            |color<<16|color<<20|color<<24|color<<28;
	   
	p=pDirectLCDBuffer+LCDWIDTH/8*top+temp_left/8;
	for(i=0;i<(temp_right-temp_left)/8;i++){
		for(j=0;j<=(bottom-top);j++){
			switch(DrawMode){
				case   GRAPH_MODE_NORMAL:		
			         	if(color>0x00000000)
					*(p+LCDWIDTH/8*j+i)|=temp_color;
					else if(color==0x00000000)
					*(p+LCDWIDTH/8*j+i)&=temp_color;
					break;
					
                             case GRAPH_MODE_OR:
		                     *(p+LCDWIDTH/8*j+i)|=temp_color;
			              break;

				case GRAPH_MODE_AND:
					*(p+LCDWIDTH/8*j+i)&=temp_color;
					break;
					
                            case GRAPH_MODE_XOR:
			             *(p+LCDWIDTH/8*j+i)^=temp_color;
			             break;

				case GRAPH_MODE_NOR:
					*(p+LCDWIDTH/8*j+i)=~*(p+LCDWIDTH/8*j+i);
					break;
					
				
				}
			}		
		}
#endif


#if  COLORDEPTH_GRAY==0

	
	while(i%32!=0&&i<=right){
		    for( j=top;j<=bottom;j++)
				Direct_SetPixel(pdc, i, j, color);
		    i++;
               }
	if(i==right+1)
		return;
	
	for( j=top;j<=bottom;j++)
				Direct_SetPixel(pdc, i, j, color);
	temp_left=i;

	i=right;
	while(i%32!=0){
		    for(j=top;j<=bottom;j++)
				Direct_SetPixel(pdc, i, j, color);
		    i--;
		}
			
	temp_right=i;

	if(temp_left==temp_right)
		return;

  //     temp_color=color|color<<4|color<<8|color<<12
//	   	            |color<<16|color<<20|color<<24|color<<28;

	if(color>0)	
	       temp_color=0xffffffff;

   
	p=pDirectLCDBuffer+LCDWIDTH/32*top+temp_left/32;
	for(i=0;i<(temp_right-temp_left)/32;i++){
		for(j=0;j<=(bottom-top);j++){
			switch(DrawMode){
				case   GRAPH_MODE_NORMAL:		
			         	if(color>0x00000000)
					*(p+LCDWIDTH/32*j+i)|=temp_color;
					else if(color==0x00000000)
					*(p+LCDWIDTH/32*j+i)&=temp_color;
					break;
					
                             case GRAPH_MODE_OR:
		                     *(p+LCDWIDTH/32*j+i)|=temp_color;
			              break;

				case GRAPH_MODE_AND:
					*(p+LCDWIDTH/32*j+i)&=temp_color;
					break;
					
                            case GRAPH_MODE_XOR:
			             *(p+LCDWIDTH/32*j+i)^=temp_color;
			             break;

				case GRAPH_MODE_NOR:
					*(p+LCDWIDTH/32*j+i)=~*(p+LCDWIDTH/32*j+i);
					break;
					
				
				}
			}		
		}
   
#endif



}
void Direct_FillRect2(PDC pdc, structRECT *rect,U32 DrawMode, U32 color)
{
       Direct_FillRect( pdc, rect->left, rect->top, rect->right, rect->bottom, DrawMode, color);
}
void Direct_Circle(PDC pdc,int x0,int y0,int r)
{
 
	   	
	   int x,y;
          int y1,y2;
          int x1,x2;
          int detx,dety;

       
//////first draw the four special point
          for(x=x0;x>=x0-(int)(r*sqrt(2)/2)-1;x--)
          	{
          	y1=y0+(int)(sqrt(r*r-(x-x0)*(x-x0)));
		y2=y0-(int)(sqrt(r*r-(x-x0)*(x-x0)));

		detx=ABS(x0-x);//det大于0;
		dety=ABS(y0-y2);
            			  
              Direct_SetPixel(pdc, x, y1, 0x0000000f);
              Direct_SetPixel(pdc, 2*x0-x, y1, 0x0000000f);
              Direct_SetPixel(pdc, x, y2, 0x0000000f);
              Direct_SetPixel(pdc, 2*x0-x, y2, 0x0000000f);	
			  
              Direct_SetPixel(pdc, x0-dety, y0+detx, 0x0000000f);
	       Direct_SetPixel(pdc, x0+dety, y0+detx, 0x0000000f);
		Direct_SetPixel(pdc, x0-dety, y0-detx, 0x0000000f);
		Direct_SetPixel(pdc, x0+dety, y0-detx, 0x0000000f);		
	       
          	}         
	   
}
/*void Direct_GetChPointer(U8** pChfont, structSIZE* size, U16 ch, U8 bunicode,U8 fnt)
{
	if(bunicode){	//显示UNICODE字符集
		if(ch<256){	//ASCII字符
			size->cy=OSFontSize[fnt&0x03];
			size->cx=size->cy/2;
			switch(fnt&0x03){
			case FONTSIZE_SMALL:
				if(sucloadedfile|LOADU12FONT){
					*pChfont=UFont12[ch];
				}
				return;
			case FONTSIZE_MIDDLE:
				if(sucloadedfile|LOADU16FONT){
					*pChfont=UFont16[ch];
				}
				return;
			case FONTSIZE_BIG:
				if(sucloadedfile|LOADU24FONT){
					*pChfont=UFont24[ch];
				}
			}
			return;
		}
		//全宽度字符
		if(ch<0x2680)//特殊字符1
			ch-=0x2600;
		else if(ch<0x27c0)//特殊字符2
			ch-=0x2700-0x80;
		else if(ch<0xa000)//汉字
			ch-=0x4e00-0x80-0xc0;
		else//未定义字符
			ch=0x9fff-0x4e00+0x80+0xc0;

		size->cx=size->cy=OSFontSize[fnt&0x03];

		switch(fnt&0x03){
		case FONTSIZE_SMALL:
			if(sucloadedfile|LOADU12FONT){
				*pChfont=UCFont12[ch];
			}
			return;
		case FONTSIZE_MIDDLE:
			if(sucloadedfile|LOADU16FONT){
				*pChfont=UCFont16[ch];
			}
			return;
		case FONTSIZE_BIG:
			if(sucloadedfile|LOADU24FONT){
				*pChfont=UCFont24[ch];
			}
		}
	}
}*/
void Direct_CharactorOutRect(PDC pdc,int * x,int* y, structRECT* prect,U16 ch,U8 bunicode, U8 fnt)
{
       U8 *pfont;
	U8 nxbyte;//字符的水平占用的字节数
	U32 i,j,k,fntclr;
	INT8U err;
	structSIZE size;
	GetChPointer(&pfont, &size, ch, bunicode, fnt);

	nxbyte=size.cx/8;
	if(size.cx%8)
		nxbyte++;

//	OSSemPend(Lcd_Disp_Sem,0, &err);
	switch(fnt&0xc){
	case FONT_TRANSPARENT:	//透明背景
		for(i=0;i<size.cy;i++){
			k=7;
			for(j=0;j<size.cx;j++){
				if(IsInRect(prect, j+(*x), i+(*y))){
					if((pfont[i*nxbyte+j/8]>>k)&0x01)
						fntclr=pdc->Fontcolor;
					else
						fntclr=COLOR_WHITE;
					Direct_SetPixelOR(pdc,j+(*x),i+(*y),fntclr);
				}
				k--;
				k&=0x7;
			}
		}
		break;
	case FONT_BLACKBK:	//黑底白字
		for(i=0;i<size.cy;i++){
			k=7;
			for(j=0;j<size.cx;j++){
				if(IsInRect(prect, j+(*x), i+(*y))){
					if((~(pfont[i*nxbyte+j/8]>>k))&0x01)
						fntclr=pdc->Fontcolor;
					else
						fntclr=COLOR_WHITE;
					Direct_SetPixel(pdc,j+(*x),i+(*y),fntclr);
				}
				k--;
				k&=0x7;
			}
		}
		break;
	default:	//正常模式
		for(i=0;i<size.cy;i++){
			k=7;
			for(j=0;j<size.cx;j++){
				if(IsInRect(prect, j+(*x), i+(*y))){
					if((pfont[i*nxbyte+j/8]>>k)&0x01)
						fntclr=pdc->Fontcolor;
					else
						fntclr=COLOR_WHITE;
					Direct_SetPixel(pdc,j+(*x),i+(*y),fntclr);
				}
				k--;
				k&=0x7;
			}
		}
	}
	(*x)+=size.cx;
}

void Direct_CharactorOut(PDC pdc, int* x, int* y, U16 ch, U8 bunicode, U8 fnt) //显示单个字符
{
	U8 *pfont;
	U8 nxbyte;//字符的水平占用的字节数
	U32 i,j,k,fntclr;
	INT8U err;
	structSIZE size;
       GetChPointer(&pfont, &size, ch, bunicode, fnt);

	nxbyte=size.cx/8;
	if(size.cx%8)
		nxbyte++;

	//OSSemPend(Lcd_Disp_Sem,0, &err);
	switch(fnt&0xc){
	case FONT_TRANSPARENT:	//透明背景
		for(i=0;i<size.cy;i++){
			k=7;
			for(j=0;j<size.cx;j++){
				if((pfont[i*nxbyte+j/8]>>k)&0x1)
					fntclr=pdc->Fontcolor;
				else
					fntclr=COLOR_WHITE;
				Direct_SetPixelOR(pdc, j+(*x),i+(*y),fntclr);
				k--;
				k&=0x7;
			}
		}
		break;
	case FONT_BLACKBK:	//黑底白字
		for(i=0;i<size.cy;i++){
			k=7;
			for(j=0;j<size.cx;j++){
				if((~(pfont[i*nxbyte+j/8]>>k))&0x01)
					fntclr=pdc->Fontcolor;
					
				else
					fntclr=COLOR_WHITE;
				Direct_SetPixel(pdc,j+(*x),i+(*y),fntclr);
				k--;
				k&=0x7;
			}
		}
		break;
	default:	//正常模式
		for(i=0;i<size.cy;i++){
			k=7;
			for(j=0;j<size.cx;j++){
				if((pfont[i*nxbyte+j/8]>>k)&0x01)
					fntclr=pdc->Fontcolor;
				    //   fntclr=0x0000000f;
				else
					fntclr=COLOR_WHITE;
			            
				Direct_SetPixel(pdc,j+(*x),i+(*y),fntclr);
				k--;
				k&=0x7;
			}
		}
	}
	(*x)+=size.cx;
}
void Direct_TextOut(PDC pdc, int x, int y, U16* ch, U8 bunicode, U8 fnt)	//显示文字
{
	int i;
	pdc->Fontcolor=0x0000008;
	for(i=0;ch[i]!=0;i++){
		pdc->Fontcolor+=i;
		Direct_CharactorOut(pdc, &x, &y, ch[i], bunicode, fnt);
		
	}
	
}
void Direct_DrawRectFrame(PDC pdc, int left,int top ,int right, int bottom)
{
        Direct_MoveTo(pdc, left, top);
	 Direct_LineTo(pdc, left, bottom);
	 Direct_LineTo(pdc, right, bottom);
	 Direct_LineTo(pdc, right, top);
	 Direct_LineTo(pdc, left, top);

}
void Direct_DrawRectFrame2(PDC pdc, structRECT *rect)
{
        Direct_DrawRectFrame(pdc,rect->left,rect->top,rect->right,rect->bottom);
}
void Direct_Draw3DRect(PDC pdc, int left, int top, int right, int bottom,COLORREF color1, COLORREF color2)

⌨️ 快捷键说明

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