📄 gui.c
字号:
/************************************************************
FileName: Gui.c
Author:胡贵
Version :V1.0
Date: 2007.9.13
Description:
用于GUI的一些底层代码,只是部分功能,
还需要完善
History:
<author> <time> <version > <desc>
************************************************************/
#include "includes.h"
#undef GLOBAL
#include "GUI_ZIMU.H"
#include "global_variable.h"
/****************************************************
//coordinate base 0
//byte0 byte1 ...
//DB0 DB0 ... bit0
//DB1 DB1 ... bit1
//DB2 DB2 ... bit2
//DB3 DB3 ... .
//DB4 DB4 ... .
//DB5 DB5 ... .
//DB6 DB6 ...
//DB7 DB7 ...
*****************************************************/
/*********************************************************************
Description:画点
Input:
x:x坐标
y:y坐标
Output:
Return:
Gloable:
DisBuffer[]:图形缓冲
Calls:
Called By:
Others:
Modify Record:
*********************************************************************/
void GUI_DrawPixel(UINT8 x,UINT8 y)
{
UINT16 Location_Byte;
UINT8 Location_Bit;
Location_Byte=(y/8)*X_PIXEL+x;
Location_Bit=y%8;
DisBuffer[Location_Byte]|=(0x01<<Location_Bit);
}
/*********************************************************************
Description:画水平线,实线
Input:
x0:起点x坐标
x1:终点x坐标
y:y坐标
Output:
Return:
Gloable:
DisBuffer[]:图形缓冲
Calls:
Called By:
Others:
Modify Record:
*********************************************************************/
void GUI_DrawHLine(UINT8 x0,UINT8 x1,UINT8 y)
{
// 000000XX XXXXXXXX .... XXXXXXXX XX000000 Location_Bit
// | |
// | |
// Location_Byte0 Location_Byte1
UINT16 Location_Byte0,Location_Byte1;
UINT8 Location_Bit;
UINT16 i;
//Location_Byte0=(y/8)*X_PIXEL+x0;
//Location_Byte1=(y/8)*X_PIXEL+x1;
Location_Byte0=(y/8)*(X_PIXEL)+x0;
Location_Byte1=(y/8)*(X_PIXEL)+x1;
Location_Bit=(y%8);
for(i=Location_Byte0;i<=Location_Byte1;i++)
DisBuffer[i]|=(0x01<<Location_Bit);
}
/*********************************************************************
Description:画水平线,实线,反显,用于擦出区域调用
Input:
x0:起点x坐标
x1:终点x坐标
y:y坐标
Output:
Return:
Gloable:
DisBuffer[]:图形缓冲
Calls:
Called By:
Gui_Clearall();
Others:
Modify Record:
*********************************************************************/
void GUI_DrawHLine_(UINT8 x0,UINT8 x1,UINT8 y)
{
// 000000XX XXXXXXXX .... XXXXXXXX XX000000 Location_Bit
// | |
// | |
// Location_Byte0 Location_Byte1
UINT16 Location_Byte0,Location_Byte1;
UINT8 Location_Bit;
UINT16 i;
//Location_Byte0=(y/8)*X_PIXEL+x0;
//Location_Byte1=(y/8)*X_PIXEL+x1;
Location_Byte0=(y/8)*(X_PIXEL)+x0;
Location_Byte1=(y/8)*(X_PIXEL)+x1;
Location_Bit=(y%8);
for(i=Location_Byte0;i<=Location_Byte1;i++)
{
DisBuffer[i]&=(~(0x01<<Location_Bit));
// uart0_send(DisBuffer[i]);
}
// Display();
_nop_();
}
/*********************************************************************
Description:画垂直线,实线
Input:
x0:起点x坐标
x1:终点x坐标
y:y坐标
Output:
Return:
Gloable:
DisBuffer[]:图形缓冲
Calls:
Called By:
Others:
Modify Record:
*********************************************************************/
void GUI_DrawVLine(UINT8 y0,UINT8 y1,UINT8 x)
{
//
// 0
// 0
// 0
// 0
// 0 } ----->Location_Byte0
// 0
// X -->Location_Bit0
// X
//
// X
// X
// X
// X
// X
// X
// X
// X
// .
// .
// .
// X
// X --->Location_Bit1
// 0
// 0
// 0 }------->Location_Byte1
// 0
// 0
// 0
UINT16 Location_Byte0,Location_Byte1;
UINT8 Location_Bit0,Location_Bit1,temp=0;
UINT16 i;
Location_Byte0=(y0/8)*(X_PIXEL)+x;
Location_Byte1=(y1/8)*(X_PIXEL)+x;
Location_Bit0=(y0%8);
Location_Bit1=(y1%8);
if(Location_Byte0==Location_Byte1)
{
for(i=Location_Bit0;i<=Location_Bit1;i++)
temp|=(0x01<<i);
DisBuffer[Location_Byte0]|=temp;
}
else
{
for(i=Location_Byte0+X_PIXEL;i<=Location_Byte1-X_PIXEL;i+=X_PIXEL)
DisBuffer[i]=0xff;
DisBuffer[Location_Byte0]|=(0xff<<Location_Bit0);//(0x80>>(7-Location_Bit0));
DisBuffer[Location_Byte1]|=(0xff>>(7-Location_Bit1));//~(0x80>>(7-Location_Bit1));//(0x01<<Location_Bit1);
}
}
/*********************************************************************
Description:画矩形,实线
Input:
x0:左上角x坐标
x1:右下角x坐标
y0:左上角y坐标
y1:右下角y坐标
Output:
Return:
Gloable:
DisBuffer[]:图形缓冲
Calls:
Called By:
Gui_Clearall();
Others:
Modify Record:
*********************************************************************/
void GUI_DrawRect(UINT8 x0,UINT8 x1,UINT8 y0,UINT8 y1)
{
GUI_DrawHLine(x0, x1,y0);
GUI_DrawHLine(x0, x1,y1);
GUI_DrawVLine(y0, y1, x0);
GUI_DrawVLine(y0, y1, x1);
}
/*********************************************************************
Description:获得字符字模指针(部分字符)
Input:
character:字符
Output:
Return:
指向字符字模的指针
Gloable:
hz_A:字模数组
.
.
.
Calls:
Called By:
Others:
Modify Record:
*********************************************************************/
UINT8 code* GetCharPointer(UINT8 character)
{
UINT8 code *p;
switch(character)
{
case 'A':p=hz_A;
break;
case 'P':p=hz_P;
break;
case 'S':p=hz_S;
break;
case 'I':p=hz_I;
break;
case 'D':p=hz_D;
break;
case 'H':p=hz_H;
break;
case 'O':p=hz_O;
break;
case 'V':p=hz_V;
break;
case 'R':p=hz_Run;
//Write_UART_STRING("OK1");
break;
case 'T':p=hz_Stop;
//Write_UART_STRING("OK2");
break;
case '0':p=hz_0_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '1':p=hz_1_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '2':p=hz_2_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '3':p=hz_3_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '4':p=hz_4_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '5':p=hz_5_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '6':p=hz_6_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '7':p=hz_7_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '8':p=hz_8_;//+CharacterStyle*(hz_0_-hz_0);
break;
case '9':p=hz_9_;//+CharacterStyle*(hz_0_-hz_0);
break;
default:
break;
}
return p;
}
/*********************************************************************
Description:在确定位置显示一个字符串,字符块基点在左下角
Input:
x:字符块x坐标
y:字符块y坐标
p_Char:字符串指针
Output:
Return:
Gloable:
struct GUI_RECT 矩形结构体
Number_X_Pixel:字符的X方向上的像素
Number_Y_Pixel:字符在Y方向上的像素
Calls:
Gui_CharacterStyle_Set7_4();设置字体7*4
GUI_ClearRect();清除一片区域
ZK_To_Bitmap();字模转成位图
RegionInsertInDisBuffer();往缓冲插入一片区域
Called By:
Others:
Modify Record:
*********************************************************************/
void GUI_DispChars(UINT8 *p_Char,UINT8 x,UINT8 y)
{
UINT8 i,count;
UINT8 xdata mid[72];
struct GUI_RECT rect;
count=strlen(p_Char);
// Gui_CharacterStyle_Set7_4();
GUI_ClearRect(x, x+Number_X_Pixel*count-1, y-Number_Y_Pixel+1, y);
for(i=0;i<count;i++)
{
ZK_To_Bitmap(GetCharPointer(*p_Char++), Number_Y_Pixel, Number_X_Pixel, mid);
rect.x0=x+i*Number_X_Pixel;
rect.x1=rect.x0+Number_X_Pixel-1;
rect.y0=y-Number_Y_Pixel+1;
rect.y1=y;
RegionInsertInDisBuffer(&rect, mid);
}
// Gui_CharacterStyle_Set12_6();
}
/*
void GUI_DispLine(struct Text *p_Text,UINT8 n_Disp,struct GUI_RECT *p_Rect)
{
UINT8 i,mid[144];
struct GUI_RECT rect;
GUI_ClearRect(p_Rect->x0, p_Rect->x1, p_Rect->y0, p_Rect->y1);
for(i=0;i<n_Disp;i++)
{
ZK_To_Bitmap(*(p_Text->p_Content+i), 12, 12, mid);
rect.x0=p_Rect->x0+i*12;
rect.x1=rect.x0+11;
rect.y0=p_Rect->y0;
rect.y1=p_Rect->y1;
RegionInsertInDisBuffer(&rect,mid);
PrintDisBuffer_();
}
}*/
/*********************************************************************
Description:整屏幕输出一副位图X_PIXEL*Y_PIXEL
Input:
p_BMP:位图字模指针
Output:
Return:
Gloable:
DisBuffer[]:图形缓冲
Calls:
Called By:
Others:
Modify Record:
*********************************************************************/
void GUI_DispBMP(UINT8 code *p_BMP)
{
UINT16 i;
for(i=0;i<488;i++)
DisBuffer[i]=*p_BMP++;
}
/*********************************************************************
Description:显示整数,坐标基点在左下角
Input:
dat:需要显示的整数
x:x 坐标
y:y坐标
formate:格式化方式
Output:
Return:
Gloable:
struct GUI_RECT 矩形结构体
Number_X_Pixel:字符的X方向上的像素
Number_Y_Pixel:字符在Y方向上的像素
Addr_Base:数字字模段起始地址
Addr_Deviate:数字字模偏移量,即字模字节数
Calls:
GUI_ClearRect();清除一片区域
ZK_To_Bitmap();字模转成位图
RegionInsertInDisBuffer();往缓冲插入一片区域
pow_10();求幂
Called By:
Others:
注意数值范围,目前定义的是16 bit
Modify Record:
*********************************************************************/
void GUI_DisIntData(INT16 dat,UINT8 x,UINT8 y,UINT8 *formate)
{
UINT8 xdata buf[10],BufLen,i;
UINT8 xdata mid[72];
struct GUI_RECT rect;
rect.x0=x;
rect.y0=y-Number_Y_Pixel+1;
rect.y1=y;
sprintf(buf,formate,dat);
BufLen = strlen(buf);
GUI_ClearRect(x, x+Number_X_Pixel*BufLen-1, y-Number_Y_Pixel + 1, y);
for (i = 0; i < BufLen; i++)
{
if (buf[i] == '-')
{
GUI_DrawHLine(rect.x0, rect.x0+Number_X_Pixel-1, rect.y0-Number_Y_Pixel/2);
rect.x0+=Number_X_Pixel;
}
else
{
ZK_To_Bitmap(Addr_Base + Addr_Deviate * (buf[i]-'0'), Number_Y_Pixel, Number_X_Pixel, mid);
rect.x1=rect.x0+Number_X_Pixel-1;
RegionInsertInDisBuffer(&rect, mid);
rect.x0=rect.x0+Number_X_Pixel;
}
}
}
/*********************************************************************
Description:显示整数,坐标基点在左下角
Input:
dat:需要显示的整数
x:x 坐标
y:y坐标
formate:格式化方式
Output:
Return:
Gloable:
Number_X_Pixel:字符的X方向上的像素
Number_Y_Pixel:字符在Y方向上的像素
special:特殊处理,这是一个设计的局限性,需要在下一个版本中改进
Calls:
pow_10();求幂
GUI_DisIntData();显示整数
GUI_DrawPixel();画点
Called By:
Others:
Modify Record:
*********************************************************************/
void GUI_DisFloatData(FLP32 dat,UINT8 x,UINT8 y,UINT8 *formate)
{
UINT8 xdata buf[10],BufLen,i;
UINT8 xdata mid[72];
struct GUI_RECT rect;
rect.x0=x;
rect.y0=y-Number_Y_Pixel+1;
rect.y1=y;
sprintf(buf,formate,dat);
BufLen = strlen(buf);
GUI_ClearRect(x, x+Number_X_Pixel*BufLen-1-(Number_X_Pixel - Number_Dot_Pixel), y-Number_Y_Pixel + 1, y);
for (i = 0; i < BufLen; i++)
{
if (buf[i] == '.')//only one pixel
{
GUI_DrawPixel(rect.x0,rect.y1-Number_Dot_Pixel_Y);
rect.x0+=2;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -