📄 directdisplay.c
字号:
{
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;
}
#if COLORDEPTH_GRAY ==0 //单色模式
void mem8invcpy(U8 *dest, U8 *src, int n)
{
for(;n>=0;n--){
*((U8*)((((int)dest)&(~0x3))+3-(((int)src)&0x3)))=*src;
dest++;
src++;
}
}
#endif
void Direct_ShowBmp(PDC pdc, char filename[], int x, int y)
{
static U8 bmp[4096];
int i,j,k,nbyte;
U32 cx,cy;
U32 color;
OSFILE* pfile;
U8 *pbmp;
U8 *p;
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;
#if COLORDEPTH_GRAY ==0 //单色模式
ReadOSFile(pfile, bmp, 8);
p=(U8*)(pDirectLCDBuffer);
p+=LCDWIDTH/8*y+x/8;
if(bmpinfoheader.biBitCount==1){ //单色模式位图
for(i=cy-1;i>=0;i--){
pbmp=bmp;
if(!ReadOSFile(pfile, bmp,cx/8))
break;
if(x%8==0){////x位于8的整数倍位置
mem8invcpy(p+LCDWIDTH/8*i, bmp, cx/8);
}
else {////x位于8的非整数倍位置
}
}
goto showbmpend;
}
#endif
nbyte=bmpinfoheader.biBitCount/8;
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);
}
}
showbmpend:
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
#endif //#if USE_MINIGUI==0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -