📄 directdisplay.c
字号:
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)
{
int i;
pdc->PenColor=color1;
Direct_DrawRectFrame(pdc,left,top,right,bottom);
/* Direct_MoveTo(pdc,right,top);
Direct_LineTo( pdc, left, top);
Direct_LineTo( pdc, left, bottom);*/
pdc->PenColor=color2;
Direct_MoveTo(pdc, right+pdc->PenWidth, top+pdc->PenWidth);
Direct_LineTo(pdc, right+pdc->PenWidth, bottom+pdc->PenWidth);
Direct_LineTo(pdc,left+pdc->PenWidth, bottom+pdc->PenWidth);
/* Direct_LineTo( pdc, right, bottom);
Direct_LineTo( pdc, right, top);*/
}
void Direct_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){
Direct_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 Direct_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){
Direct_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;
}
}
}
void Direct_ArcTo(PDC pdc, int x1, int y1, U8 arctype, int R)
{
INT8U err;
if(arctype){//逆圆
ArcTo2(pdc,x1,y1,R);
}
else{ //顺圆
ArcTo1(pdc,x1,y1,R);
}
pdc->DrawPointx=x1;
pdc->DrawPointy=y1;
}
void Direct_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;
cy=bmpinfoheader.biHeight;
nbyte=bmpinfoheader.biBitCount/8;
// pdc->PenMode=GRAPH_MODE_NORMAL;
for(i=cy-1;i>=0;i--){
pbmp=bmp;
if(!ReadOSFile(pfile, bmp,cx*nbyte+((cx*nbyte)%2)))
break;
for(j=0;j<cx;j++){
color=*pbmp;
for(k=0;k<nbyte-1;k++){
pbmp++;
color+=*pbmp;
}
pbmp++;
color/=48;
color=0x0000000f-color;
#if COLORDEPTH_GRAY==0
if(color>0x00000008)
color=0x00000001;
else
color=0;
#endif
Direct_SetPixel(pdc,x+j, y+i, color);
}
}
CloseOSFile(pfile);
}
void Direct_Bmpcopy(U32 *pbmp,int width,int length)
{
memcpy(pDirectLCDBuffer,pbmp,width*length/2);
}
void Direct_SetPixe_mono(PDC pdc, int x, int y, COLORREF color)
{
U32* p;
p=pDirectLCDBuffer+x;
*p=1;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -