2,425
社区成员
发帖
与我相关
我的任务
分享
/**************************************************************
TFT LCD移动观察窗口
**************************************************************/
void MoveViewPort(void)
{
int vx=0,vy=0,vd=1;
Uart_Printf("\n*Move the LCD view windos:\n");
Uart_Printf(" press 8 is up\n");
Uart_Printf(" press 2 is down\n");
Uart_Printf(" press 4 is left\n");
Uart_Printf(" press 6 is right\n");
Uart_Printf(" press Enter to exit!\n");
while(1)
{
switch( Uart_GetKey() )
{
case '8':
if(vy>=vd)vy-=vd;
break;
case '4':
if(vx>=vd)vx-=vd;
break;
case '6':
if(vx<=(SCR_XSIZE_TFT-LCD_XSIZE_TFT-vd))vx+=vd;
break;
case '2':
if(vy<=(SCR_YSIZE_TFT-LCD_YSIZE_TFT-vd))vy+=vd;
break;
case '\r':
return;
default:
break;
}
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
}
}
#endif
/**************************************************************
LCD屏幕显示垂直翻转
// LCD display is flipped vertically
// But, think the algorithm by mathematics point.
// 3I2
// 4 I 1
// --+-- <-8 octants mathematical cordinate
// 5 I 8
// 6I7
**************************************************************/
void Glib_Line(int x1,int y1,int x2,int y2,int color)
{
int dx,dy,e;
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 8/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}