?? display.c
字號:
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 + -