#include"gui.h"
#include "16x8.h"
#include"chinese.h"
#include"picture.h"
/****************************************************************************
*函数名:GUI_Dot
*输 入:x:点的X坐标;
* * y:点的Y坐标
* * color:点的颜色
*输 出:
*功 能:给单个像素涂上颜色。
****************************************************************************/
void GUI_Point(uint x, uint y, uint color)
{
uchar i;
TFT_SetWindow(x, y, x+1, y+1); //单个像素
for(i=0; i<16; i++)
{
TFT_WriteData(~color);
}
}
///****************************************************************************
//*函数名:GUI_Box
//*输 入:sx:起始X坐标, sy:其实Y坐标,
//* * ex:终止X坐标, ey:终止Y坐标,
//* * color:方框的颜色
//*输 出:
//*功 能:给一个区域涂上颜色。
//****************************************************************************/
void GUI_Box(uint sx, uint sy, uchar ex, uint ey, uint color)
{
uint temp;
TFT_SetWindow(sx, sy, ex, ey);
sx = ex - sx + 1;
sy = ey - sy + 1;
while (sx--)
{
temp = sy;
while (temp--)
{
TFT_WriteData(~color);
}
}
}
/****************************************************************************
*函数名:GUI_Line
*输 入:xStart:线的起始X坐标,
* * yStart:线的其实Y坐标,
* * xEnd:线的终止X坐标,
* * yEnd:线的终止Y坐标,
* * color:线条的颜色
*输 出:
*功 能:画一条直线
****************************************************************************/
void GUI_Line(uint xStart, uint yStart, uchar xEnd, uint yEnd, uint color)
{
uint t;
int xerr = 0, yerr = 0, delta_x, delta_y, distance;
int incx, incy;
uint row, col;
delta_x = xEnd - xStart;//计算坐标增量
delta_y = yEnd - yStart;
col = xStart;
row = yStart;
if (delta_x > 0)
{
incx=1;//设置单步方向
}
else
{
if (delta_x == 0)
{
incx = 0;//垂直线
}
else
{
incx = -1;
delta_x = -delta_x;
}
}
if (delta_y > 0)
{
incy = 1;
}
else
{
if (delta_y == 0)
{
incy = 0;//水平线
}
else
{
incy = -1;
delta_y = -delta_y;
}
}
if (delta_x > delta_y)
{
distance = delta_x;//选取基本增量坐标轴
}
else
{
distance = delta_y;
}
for (t=0; t<=distance+1; t++)
{ //画线输出
GUI_Point(col, row, color);
xerr += delta_x;
yerr += delta_y;
if(xerr > distance)
{
xerr -= distance;
col += incx;
}
if(yerr > distance)
{
yerr -= distance;
row += incy;
}
}
}
/*********************************************
显示1位16进制数
入口参数: (x,y) 是显示内容的左上角坐标,c:欲显示的1位16进制数,color:颜色,b_color:背景颜色。
出口参数: 无
说明:用指定位置上显示1位16进制数。
**********************************************/
void GUI_sprintf_nu(uchar x, uint y,uchar nu, uint color,uint b_color)
{
uchar s_x=0 ,s_y=0, temp=0 ;
uint j;
if (nu>9)
{nu=nu+7;}
nu=nu+16;
for(s_y=0;s_y<16;s_y++)
{
if(s_y+y<320)
{
j=nu;
j=j*16+s_y;
temp=font16x8[j];
//temp = font16x8[nu*16+s_y] ;
for( s_x=0 ; s_x<8 ; s_x++ )
{
if(x+s_x<240)
{
if((temp&(0x80>>(s_x))) == (0x80>>(s_x)) )
{
GUI_Point(x+s_x, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x, y+s_y,b_color) ;
}
}
}
}
}
}
/**********************************************************
无符号字符型数以二进制形式显示
入口参数:(x,y)是显示内容的左上角坐标,color 是显示字符的颜色,
b_color是背景颜色。
出口参数: 无
说明:无符号字符型数用指定的颜色和背景颜色在指定的坐标位置上
以二进制形式显示出来。
************************************************************/
void GUI_sprintf_chartobit(uchar x, uint y,uchar dat, uint color,uint b_color)
{
uchar i ;
for(i=0;i<8;i++)
{
if((dat&(0x80>>i))==(0x80>>i))
{
GUI_sprintf_nu(x,y,1,color,b_color) ;
}
else
{
GUI_sprintf_nu(x,y,0,color,b_color) ;
}
x+=8 ;
}
}
/*********************************************
显示英文或数字字符
入口参数:(x,y) 是显示内容的左上角坐标,c:显示的英文字符,
color:颜色,b_color:背景颜色。
出口参数: 无
说明:用指定位置上显示单个英文字符或数字字符。
**********************************************/
void GUI_sprintf_char(uchar x, uint y,uchar c, uint color,uint b_color)
{
uchar s_x ,s_y, temp ;
uint j;
c -= 32;
for( s_y=0 ; s_y < 16 ; s_y++ )
{
if(s_y+y<320)
{
j=c;
j=j*16+s_y;
temp=font16x8[j];
//temp = font16x8[c*16+s_y] ;
for( s_x=0 ; s_x<8 ; s_x++ )
{
if(x+s_x<240)
{
if((temp&(0x80>>(s_x))) == (0x80>>(s_x)) )
{
GUI_Point(x+s_x, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x, y+s_y,b_color) ;
}
}
}
}
}
}
/**********************************************************
无符号字符型数以十进制形式显示
入口参数:(x,y)是显示内容的左上角坐标,dat是欲显示的无符号字符型数,
color 是显示字符的颜色,b_color是背景颜色。
出口参数: 无
说明:无符号字符型数用指定的颜色和背景颜色在指定的坐标位置上
以十进制形式显示出来。
************************************************************/
void GUI_sprintf_chartodec(uchar x,uint y,uchar dat,uint color,uint b_color)
{
GUI_sprintf_char(x,y,dat/10+'0',color,b_color);
GUI_sprintf_char(x+8,y,dat%10+'0',color,b_color);
}
/*********************************************
显示英文字符串
入口参数:(x,y) 是显示内容的左上角坐标,*s:英文字符串指针,
color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示英文字符串。
**********************************************/
void GUI_sprintf_string(uchar x, uint y,char code *s, uint color,uint b_color)
{
for(;*s!='\0';s++)
{
GUI_sprintf_char(x, y,*s, color,b_color);
x=x+8;
}
//while (*s)
// {
// GUI_sprintf_char(x, y,*s, color,b_color);
// s++;
// x=x+8;
// }
}
/*********************************************
显示预定义汉字字符串
入口参数:(x,y) 是显示内容的左上角坐标,color:颜色,b_color:背景颜色。
出口参数: 无
说明:在指定位置上显示预定义的中文字符串。
要显示的中文字符串事先定义在chinese.h中的china_char[]数组中,
如果想修改中文字符串长度、内容,请修改chinese.h中的
china_char[]数组,建议用字模提取软件zimoV2.2将你要显示的
中文字符串自动转换为数组数据。
**********************************************/
void GUI_sprintf_HZ(uchar x, uint y, uint color,uint b_color)
{
uchar s_x=0 ,s_y=0, temp=0 ;
uchar n;
uint j,words;
words=sizeof(china_char)/32;
for( n=0 ; n<words ; n++ )
{
for( s_x=0 ; s_x<16 ; s_x++ )
{
if(s_x+x<240)
{
j=n;
j=j*32+s_x;
temp = china_char[j] ;
//temp = china_char[n*32+s_x] ;
for( s_y=0 ; s_y<8 ; s_y++ )
{
if(y+s_y<320)
{
if((temp&(0x80>>(s_y))) == (0x80>>(s_y)) )
{
GUI_Point(x+s_x+n*16, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x+n*16, y+s_y,b_color) ;
}
}
}
}
}
for( s_x=0 ; s_x<16 ; s_x++ )
{
if(s_x+x<240)
{
j=n;
j=j*32+s_x+16;
temp = china_char[j] ;
//temp = china_char[n*32+s_x+16] ;
for( s_y=0 ; s_y<8 ; s_y++ )
{
if(y+s_y<320)
{
if((temp&(0x80>>(s_y))) == (0x80>>(s_y)) )
{
GUI_Point(x+s_x+n*16, y+s_y+8,color) ;
}
else
{
GUI_Point(x+s_x+n*16, y+s_y+8,b_color) ;
}
}
}
}
}
}
}
/*********************************************
画�