123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979 |
- #include "includes.h"
- extern const unsigned char g_apucLetter16[];
- extern const unsigned char g_apucCLetter16[];
- extern const unsigned char g_apucLetter24[];
- extern const unsigned char g_apucCLetter24[];
- extern const unsigned char g_apucFonts16[];
- extern const unsigned char g_apucCFonts16[];
- extern const unsigned char g_apucFonts24[];
- extern const unsigned char g_apucCFonts24[];
- extern const unsigned char g_apucFonts12[];
- extern const unsigned char g_apucLetter12[];
- SUT_HZK sutHzk16;
- SUT_HZK sutHzk12;
- unsigned char g_Palette[256*4];//调色板 顺序是BGRA 其中A未用
- u8 g_ucWarnColorId; //警告颜色
- u8 g_ucForeColorId; //画笔颜色索引
- u8 g_ucBackColorId; //背景颜色索引
- u8 g_ucSel_ColorId; //选定区域颜色索引
- u16 g_usWarnColor;//警告色
- u16 g_usForeColor;//前景色 RGB565值 需要根据颜色索引从当前调色板中获取
- u16 g_usBackColor;//背景色 RGB656值 需要根据颜色索引从当前调色板中获取
- void PaintToBuf(u16 x,u16 y,u16 width,u16 heigh,u8 *data);
- void PaintBufToLcd(u16 x,u16 y,u16 width,u16 heigh,unsigned char colorID);
- u16 RGB888toRGB565(unsigned char R,unsigned char G, unsigned char B);
- void SetPaletteByBmpFile(char *filename);
- void UpdateColor(void);
- void GuiDrawDot(u16 x,u16 y);
- void UpdateDot(unsigned char colorID);
- /***************************************************************************
- 在调色板中查找与期望颜色最接近的颜色并返回其索引
- 输入:ColorRGB 格式:0xRRGGBB 红绿蓝
- 返回:在调色板中,最接近ColorRGB的颜色索引
- 算法:对调色板内的每个色素点分别求出RGB之差的绝对值并求和,然后找出最小值所对应的色素点的索引即可
- ****************************************************************************/
- int FindColorIndex(unsigned long ColorRGB)
- {
- int i,j,k;
- int R,G,B;
- int fR,fG,fB;//计算期望RGB和调色板内每个RGB差的绝对值
- int fSum,fSumMin;
- R=(int)((ColorRGB>>16)&0xff);
- G=(int)((ColorRGB>>8)&0xff);
- B=(int)(ColorRGB&0xff);
- fSumMin=999999;
- k=0;
- for(i=0;i<256;i++){
- j=i*4;
- fB=g_Palette[j];
- fG=g_Palette[j+1];
- fR=g_Palette[j+2];
- //g_Palette[j+3]未用
-
- fB=B-fB;//B差
- if(fB<0)fB=-fB; //B差的绝对值
- fG=G-fG;//G差
- if(fG<0)fG=-fG;//G差的绝对值
-
- fR=R-fR;//R差
- if(fR<0)fR=-fR;//R差的绝对值
- //RGB差的绝对值求和
- fSum=fB+fG+fR;
- //找到RGB差的绝对值之和的最小值
- if(fSum<fSumMin){
- fSumMin=fSum;
- k=i;
- }
- }
- return k;
- }
- /***************************************************************************
- 设置前景色和背景色
- ****************************************************************************/
- void GuiSetColor(unsigned long ForeColor,unsigned long BackColor,unsigned long WarnColor,unsigned long SelColor)
- {
- //设置前景色,先在调色板找到最接近的颜色,然后作为索引保存在g_ucForeColorId中
- g_ucForeColorId=FindColorIndex(ForeColor);
- //设置背景色,先在调色板找到最接近的颜色,然后作为索引保存在g_ucBackColorId中
- g_ucBackColorId=FindColorIndex(BackColor);
- //设置警告色,先在调色板找到最接近的颜色,然后作为索引保存在g_ucBackColorId中
- g_ucWarnColorId=FindColorIndex(WarnColor);
- //设置选定颜色
- g_ucSel_ColorId=FindColorIndex(SelColor);
-
- UpdateColor();
- }
- /***************************************************************************
- 设置前景色
- ****************************************************************************/
- void GuiSetForeColor(unsigned long ForeColor)
- {
- //设置前景色,先在调色板找到最接近的颜色,然后作为索引保存在g_ucForeColorId中
- g_ucForeColorId=FindColorIndex(ForeColor);
- UpdateColor();
- }
- /***************************************************************************
- 设置背景色
- ****************************************************************************/
- void GuiSetBackColor(unsigned long BackColor)
- {
- //设置背景色,先在调色板找到最接近的颜色,然后作为索引保存在g_ucBackColorId中
- g_ucBackColorId=FindColorIndex(BackColor);
- UpdateColor();
- }
- /****************************************************************************
- 设置调色板为BMP文件中的调色板
- ****************************************************************************/
- void SetPaletteByBmpFile(char *filename)
- {
- int index;
- int FileLen;
- unsigned short type;
-
- index=GetFileIndex(filename);
- FileLen=GetFileLen(index);
- if(FileLen==0)return;//找不到文件,直接返回不处理
- //读出位图类型
- ReadFileData(index,28,2,(u8 *)&type);//读出int biBitCount ; // 每个像素所需的位数,必须是或 1,4,8 24(// 真彩色 ) 之一 (28-29 字节 )
- if(type!=0x0008)return;//非256色的BMP图,直接返回不处理。
- //读取调色板数据
- ReadFileData(index,54,1024,g_Palette);
- }
- /****************************************************************************
- RGB888toRGB565
- 将RGB888转为RGB565
- ****************************************************************************/
- u16 RGB888toRGB565(unsigned char R,unsigned char G, unsigned char B)
- {
- u8 r, g, b;
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- return( (r<<11) + (g<<5) + (b<<0) );
- }
- /*****************************************
- 从字库文件HZK16中提取某汉子的字库数据
- 输入:hiByte--汉字的高字节 loByte--汉字的低字节
- 字库文件存储在sFlash中,字库文件名为HZK16
- 输出:pHzk--提取到的字库数据,需要预留足够空间存储。如果是16*16 则应该是16*16/8=32Byte
- 返回:失败返回0 成功返回长度
- ******************************************/
- int GetHzk(u8 hiByte,u8 loByte,u8 *pHzk,u8 font)
- {
- u8 Q,W;
- u32 offset;
-
- if(hiByte<0xa0 || loByte<0xa0)return 0;
- Q=hiByte-0xa0;
- W=loByte-0xa0;
- if(!font)
- {
- offset=(94 * (Q-1) + (W-1))* 24;
- return ReadFileData(sutHzk12.FileIndex,offset,24,pHzk);
- }else
- {
- offset=(94 * (Q-1) + (W-1))* 32;
- return ReadFileData(sutHzk16.FileIndex,offset,32,pHzk);
- }
- }
- /******************************************
- *汉子库初始化
- *输入:汉字库文件名
- *输出:汉字库数据首地址存放在sHZK16中
- *返回:1--成功 0--失败,找不到文件
- *******************************************/
- int HzkInit(const char *filename)
- {
- int i;
- if(g_sutFilesList.FileCount==0)return 0;
-
- if(!strcmp(filename,"HZK16"))
- {
- memset(&sutHzk16,0,sizeof(SUT_HZK));
- i=GetFileIndex(filename);
- if(i<0)return 0;
- sutHzk16.width=16;
- sutHzk16.heigh=16;
- sutHzk16.len=(sutHzk16.width * sutHzk16.heigh)/8;
- sutHzk16.FileIndex=i;
- sutHzk16.FileLen=g_sutFilesList.FileInfo[i].FileLen;
- return 1;
- }else if(!strcmp(filename,"HZK12")){
-
- memset(&sutHzk12,0,sizeof(SUT_HZK));
- i=GetFileIndex(filename);
- if(i<0)return 0;
- sutHzk12.FileIndex=i;
- sutHzk12.FileLen=g_sutFilesList.FileInfo[i].FileLen;
- return 1;
- }
- }
- void GuiClearAll(void)
- {
- GuiFillRect(0,STATUS_BAR_HEIGH,159,STATUS_ITEM_HEIGH-1,COLOR_WARN_RED);
- PaintBufToLcd(0,STATUS_ITEM_HEIGH,LCD_WIDTH,LCD_HEIGHT,g_ucBackColorId);
-
- }
- /******************************************
- GuiInit
- 初始化GUI
- *******************************************/
- void GuiInit(void)
- {
- if(!HzkInit(HZK16_FILE_NAME))
- {
- printf("Can't find the Hzk16File(%s)!\r\n",HZK16_FILE_NAME);
- }
- if(!HzkInit(HZK12_FILE_NAME))
- {
- printf("Can't find the Hzk12File(%s)!\r\n",HZK12_FILE_NAME);
- }
- //设置默认调色板
- //GuiSetDefaultPalette();//设置系统调色板为程序代码中预设的调色板
- SetPaletteByBmpFile("allpic.bmp");//从指定BMP文件中提取调色板作为系统调色板
- //设置前景色和背景色,设置前景色和背景色前需要先设置调色板
- GuiSetColor(COLOR_DARKBLUE,COLOR_WHITE,COLOR_RED,COLOR_SEL_BULUE);
- //清空所有显示区域,即将所有显示区域设置为背景色
- //GuiClearAll();
- GuiShowBmp(0,0,"welcome.bmp");
- //GuiShowBmp(0,0,"Palace0.bmp");
- }
- /************************************************************
- GuiPainToBuf
- 将位图数据刷到显示缓冲区
- 位图数据按:每行从左到右,从上行到下行扫描
- *************************************************************/
- void PaintToBuf(u16 x,u16 y,u16 width,u16 heigh,u8 *data)
- {
- int i,j,k,t;
-
- unsigned short RGB565;
- unsigned char R,G,B;
- unsigned short r,g,b;
-
- for(j=0;j<heigh;j++){
- t=y+j;
- k=j*width;
- for(i=0;i<width;i++){ //width=40
- //UpdateDot(data[k+3*i]);
- B=data[3*i];
- G=data[3*i+1];
- R=data[3*i+2];
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- RGB565=((r<<11) + (g<<5) + (b<<0));
-
- LcdSendData(RGB565 >> 8);
- LcdSendData(RGB565 & 0xff);
-
- }
- }
- }
- /************************************************************
- PaintBufToLcd
- 将显示缓冲区的数据刷到LCD显示
- *************************************************************/
- void PaintBufToLcd(u16 x,u16 y,u16 width,u16 heigh,unsigned char colorID)
- {
- int i,j,k;
- unsigned short RGB565;
- unsigned short temp;
- if(x>=LCD_WIDTH || y>=LCD_HEIGHT)return;
- if(x+width>LCD_WIDTH)width=LCD_WIDTH-x-1;
- if(y+heigh>LCD_HEIGHT)heigh=LCD_HEIGHT-y-1;
- IWDG_ReloadCounter();//防止刷的死机
- temp=colorID*4;
-
- RGB565=RGB888toRGB565(g_Palette[temp+2],g_Palette[temp+1],g_Palette[temp]);
-
- LcdBlockWrite(x,y,x+width-1,y+heigh-1);
- for(j=0;j<heigh;j++){
- k=y+j;
- for(i=0;i<width;i++){
- LcdSendData(RGB565 >> 8);
- LcdSendData(RGB565 & 0xff);
- }
- }
- }
- // 12 *12 16*16
- void PaintCharToBuf(u16 x,u16 y,u8 hiByte,u8 loByte,u8 mode,u8 rev)
- {
- unsigned short i,j,k,m,n;
- unsigned short width,height;
- unsigned char ByteWidth,data;
- unsigned char colorH,colorL;
- unsigned char bgcolorH,bgcolorL;
- const unsigned char *l_pucFont,*l_pucLetter;
- unsigned char *p;
- unsigned char font;//字体
- unsigned char cover;//覆盖方式
- unsigned char sucHzk16[32];
- unsigned char sucHzk12[24];
-
- unsigned char lcdData;
- font=mode&0xf0;
- cover=mode&0x0f;
- //===先根据字符设置显示的宽、高、点阵数据指针等===
-
- k = 0;
- if(!hiByte) //english
- {
- if(font==0x00) //8* 12
- {
- width=8;//8
- height = 12; //12
- ByteWidth = 1;
- l_pucFont = g_apucFonts12;
- l_pucLetter = g_apucLetter12;
- }else{ //8*16
- width=8;
- height = 16;
- ByteWidth = 1;
- l_pucFont = g_apucFonts16;
- l_pucLetter = g_apucLetter16;
- }
- //
- while(*l_pucLetter)
- {
- if(loByte == *l_pucLetter)break;
- l_pucLetter ++;
- k ++;
- }
- //查找到字库的开始位置
- l_pucFont += k * ByteWidth * height;
-
- }else
- { //chinese
- if(font == 0x00)//12*16
- {
- width=16;
- height = 12;
- ByteWidth = 2;
- l_pucFont = sucHzk12;
- l_pucLetter = 0;
- k=0;
- if(sizeof(sucHzk12)!=GetHzk(hiByte,loByte,sucHzk12,font)){//从sFlash的HZK文件中读取字库数据
- //找不到字库,显示"口"
- l_pucFont=g_apucCLetter16;
- }
- }else{//16*16
- width=16;
- height = 16;
- ByteWidth = 2;
- l_pucFont = sucHzk16;
- l_pucLetter = 0;
- k=0;
- if(sizeof(sucHzk16)!=GetHzk(hiByte,loByte,sucHzk16,font)){//从sFlash的HZK16文件中读取字库数据
- //找不到字库,显示"口"
- l_pucFont=g_apucCLetter16;
- }
-
- }
- //
- }
- //====================再处理点阵数据==========
- if(y+height>LCD_HEIGHT)return;
- if(x+width>LCD_WIDTH)return;
- LcdBlockWrite(x,y,x+width-1,y+height-1);//8,12
-
- //以下直接将点阵刷到LCD,不用显存。用于测试,注意调用不要调用PaintBufToLcd,否则也刷屏了
- //根据字模在显存中画点
- for(j=0;j<height;j++){
- m=y+j;
- for(i=0;i<ByteWidth;i++){
- n=x+i*8;
- data=*l_pucFont++;
- for(k=0;k<8;k++){
- if(data & (0x80>>k)){//有点,画上前景色
- if(m<STATUS_BAR_HEIGH){ //bar 状态栏 颜色
- if(rev==0) UpdateDot(g_ucBackColorId);
- else UpdateDot(g_ucForeColorId);
- }else if(m<STATUS_ITEM_HEIGH){ //标题颜色
-
- if(rev==0) UpdateDot(g_ucBackColorId);//
- else UpdateDot(g_ucWarnColorId);
-
- }else if(m<MIDDLE_CONTENT_HEIGH){ //中间正文颜色
- if(rev==0) UpdateDot(0);//
- else UpdateDot(g_ucBackColorId);
- }else { // 下面指示文本颜色
-
- // if(rev==0) UpdateDot(g_ucForeColorId);
- // else UpdateDot(g_ucBackColorId);
- if(rev==0) UpdateDot(g_ucWarnColorId);
- else UpdateDot(g_ucBackColorId);//
-
-
- }
- }else{//无点
- if(m<STATUS_BAR_HEIGH){
- if(rev==0) UpdateDot(g_ucForeColorId);
- else UpdateDot(g_ucBackColorId);
- }else if(m<STATUS_ITEM_HEIGH){
- if(rev==0) UpdateDot(g_ucWarnColorId);
- else UpdateDot(g_ucForeColorId);
- }else if(m<MIDDLE_CONTENT_HEIGH){
- if(rev==0) UpdateDot(g_ucBackColorId);
- else UpdateDot(g_ucSel_ColorId);//需要和反色部分颜色一样
- }else {
- // if(rev==0) UpdateDot(g_ucBackColorId);
- // else UpdateDot(g_ucForeColorId);
- if(rev==0) UpdateDot(g_ucBackColorId);//
- else UpdateDot(g_ucWarnColorId);
- }
- }
- }
- }
- }
- }
- //rev 0 正常显示 否则反显
- void GuiShowStr(u16 x, u16 y,const char *string,u8 mode,u8 rev)
- {
- unsigned char width1,width2,heigh;
- unsigned char *p;
- unsigned short i;
- unsigned char font;//字体
-
- font=mode&0xf0;
- if(font == 0x00) //12*12 font
- {
- width1 = 12;
- width2 = 1;
- heigh=12;
- }
- else //16*16 font
- {
- width1 = 16;
- width2 = 1;
- heigh=16;
- }
- p = (unsigned char *)string;
- i = 0;
-
- while(*p)
- {
- if (*p > 0x9f) //chinese letter
- {
- PaintCharToBuf(x+i,y,*p, *(p+1),mode,rev);
- i += width1 ;
- p += 2;
- }
- else //english letter
- {
- PaintCharToBuf(x + i,y,0,*p,mode,rev);
- if(font==0){
- i += width2 * 8;
- }else{
-
- i += width2 * 8;
- }
- p ++;
- }
- }
- //将内容从显存刷到LCD显示
- //PaintBufToLcd(x,y,i,heigh);
- }
- //
- int WidthBytes( int nBits, int nWidth )
- {
- int nWidthBytes;
- nWidthBytes = nWidth;
- if( nBits == 1 ) nWidthBytes = ( nWidth + 7 ) / 8;
- else if( nBits == 4 ) nWidthBytes = ( nWidth + 1 ) / 2;
- else if( nBits == 16 ) nWidthBytes = nWidth * 2;
- else if( nBits == 24 ) nWidthBytes = nWidth * 3;
- else if( nBits == 32 ) nWidthBytes = nWidth * 4;
-
- while( ( nWidthBytes & 3 ) != 0 ) nWidthBytes++;
-
- return( nWidthBytes );
- }
- /************************************************************
- GuiShowBmp
- 从sFlsh中读取BMP文件并显示
- *************************************************************/
- void GuiShowBmp(u16 x,u16 y,const char * filename)
- {
- int i,w,l;
- int index;
- int FileLen;
- unsigned short type;
- unsigned int width,heigh,SizeImage,bfOffBits;
- unsigned char temp[480];//160*3
- index=GetFileIndex(filename);
- FileLen=GetFileLen(index);
- if(FileLen==0)return;//找不到文件,直接返回不处理
- //读出位图类型
- ReadFileData(index,28,2,(u8 *)&type);//读出int biBitCount ; // 每个像素所需的位数,必须是或 1,4,8 24(// 真彩色 ) 之一 (28-29 字节 )
- //if(type!=0x0008)return;//非256色的BMP图,直接返回不处理。
-
- //读出位图的宽度
- ReadFileData(index,18,4,(u8 *)&width); //int image_width ; // 位图的宽度,以像素为单位 (18-21 字节 )
- // printf("width=%u\r\n",width);
- //读出位图的高度
- ReadFileData(index,22,4,(u8 *)&heigh); //int image_heigh ; // 位图的高度,以像素为单位 (22-25 字节 )
- //printf("heigh=%u\r\n",heigh);
- if(width>LCD_WIDTH || heigh>LCD_HEIGHT)return;//超过LCD显示范围,不处理
- //读位图数据起始地址
- ReadFileData(index,10,4,(u8 *)&bfOffBits); //int bfOffBits ; // 位图数据的起始位置,以相对于位图 (10-13 字节 )
-
- //以下读位图数据放到显示缓冲区
- w=WidthBytes(24,width);//24位图
-
- l=heigh-1;//BMP扫描顺序是:从下往上,从左往右扫描,因此先从最后一行开始读数据
-
- LcdBlockWrite(x,y,x+width-1,y+heigh-1);
-
- for(i=0;i<heigh;i++){
- //printf("num===%d\r\n",bfOffBits+w*l);//*3
- ReadFileData(index,bfOffBits+w*l,w,temp);// *3 width*3
- PaintToBuf(x,y+i,width,1,temp);
- l--;
- }
- //从显示缓冲区刷到LCD显示
- //PaintBufToLcd(x,y,width,heigh);
- //恢复调色板到默认调色板
- //GuiSetDefaultPalette();
- }
- /****************************************************************************
- GuiClearRect
- 清空指定矩形区域,即将矩形区域填充背景色
- ****************************************************************************/
- void GuiClearRect(u16 x1, u16 y1, u16 x2, u16 y2)
- {
- u16 m,n;
- u16 i,j,h,w;
- if(x1>x2||y1>y2)return;
- if(x2>=LCD_WIDTH)x2=LCD_WIDTH-1;
- if(y2>=LCD_HEIGHT)y2=LCD_HEIGHT-1;
-
- w=x2-x1+1;
- h=y2-y1+1;
-
- LcdBlockWrite(x1,y1,x1+w-1,y1+h-1);
-
- for(j=0;j<h;j++){
- m=y1+j;
- for(i=0;i<w;i++){
- n=x1+i;
-
- if(m<STATUS_BAR_HEIGH){
- UpdateDot(g_ucForeColorId);
- }else if(m<STATUS_ITEM_HEIGH){
- UpdateDot(g_ucWarnColorId);
- }else {
- UpdateDot(g_ucBackColorId);
- }
- //UpdateDot(g_ucBackColorId);
- }
- }
- //PaintBufToLcd(x1,y1,w,h);
- }
- /****************************************************************************
- GuiClearRect
- 清空一个区域,填充背景色,和GuiClearRect等效,只是入口参数有区别
- ****************************************************************************/
- void GuiClearArea(u16 x, u16 y, u16 width, u16 heigh)
- {
- u16 m,n;
- u16 i,j;
- if(x>=LCD_WIDTH||y>=LCD_HEIGHT)return;
- if(x+width >=LCD_WIDTH)width=LCD_WIDTH-x-1;
- if(y+heigh >=LCD_HEIGHT)heigh=LCD_HEIGHT-y-1;
-
-
- LcdBlockWrite(x,y,x+width-1,y+heigh-1);
- for(j=0;j<heigh;j++){
- m=y+j;
- for(i=0;i<width;i++){
- n=x+i;
- UpdateDot(g_ucBackColorId);
- }
- }
- //PaintBufToLcd(x,y,width,heigh);
- }
- #ifdef USING_DRAW_WITH_COLOR_OPTION
- /****************************************************************************
- GuiFillRect
- 指定矩形区域填充前景色
- ****************************************************************************/
- void GuiFillRect(u16 x1, u16 y1, u16 x2, u16 y2,u8 colorIndex)
- {
- u16 i,j,h,w;
- u16 x,y;
- if(x1>x2||y1>y2)return;
-
- if(x1>=LCD_WIDTH || y1>=LCD_HEIGHT)return;
-
- if(x2>=LCD_WIDTH)x2=LCD_WIDTH-1;
- if(y2>=LCD_HEIGHT)y2=LCD_HEIGHT-1;
-
- w=x2-x1+1;
- h=y2-y1+1;
-
- LcdBlockWrite(x1,y1,x1+w-1,y1+h-1);
- for(j=0;j<h;j++){
- y=y1+j;
- if(y>(LCD_HEIGHT-1))y=LCD_HEIGHT-1;
-
- for(i=0;i<w;i++){
- x=x1+i;
- if(x>(LCD_WIDTH-1))x=LCD_WIDTH-1;
- {
- //g_aucLcdBuf[y][x]=g_ucForeColorId;
- switch(colorIndex)
- {
- case COLOR_SELECT_BLUE:UpdateDot(g_ucSel_ColorId);break;
- case COLOR_WARN_RED:UpdateDot(g_ucWarnColorId);break;
- case COLOR_WHITE_BACK: UpdateDot(g_usBackColor);break;
- case COLOR_DEFAULT_BLUE:
- default:UpdateDot(g_ucForeColorId);break;
- }
- }
- }
- }
- //PaintBufToLcd(x1,y1,w,h);
- }
- #else
- /****************************************************************************
- GuiFillRect
- 指定矩形区域填充前景色
- ****************************************************************************/
- void GuiFillRect(u16 x1, u16 y1, u16 x2, u16 y2)
- {
- u16 i,j,h,w;
- u16 x,y;
- if(x1>x2||y1>y2)return;
-
- if(x1>=LCD_WIDTH || y1>=LCD_HEIGHT)return;
-
- if(x2>=LCD_WIDTH)x2=LCD_WIDTH-1;
- if(y2>=LCD_HEIGHT)y2=LCD_HEIGHT-1;
-
- w=x2-x1+1;
- h=y2-y1+1;
-
- LcdBlockWrite(x1,y1,x1+w-1,y1+h-1);
- for(j=0;j<h;j++){
- y=y1+j;
- if(y>(LCD_HEIGHT-1))y=LCD_HEIGHT-1;
-
- for(i=0;i<w;i++){
- x=x1+i;
- if(x>(LCD_WIDTH-1))x=LCD_WIDTH-1;
-
- UpdateDot(g_ucForeColorId);
- }
- }
- //PaintBufToLcd(x1,y1,w,h);
- }
- #endif
- /****************************************************************************
- GuiDrawHLine
- 画水平线
- ****************************************************************************/
- void GuiDrawHLine(u16 x1, u16 x2, u16 y, u8 width)
- {
- if(width==0)return;
- if(x2<x1)return;
- width-=1;
- GuiFillRect(x1,y,x2,y+width,0);
- }
- #ifdef USING_DRAW_WITH_COLOR_OPTION//带选择填充色
- /****************************************************************************
- GuiDrawVLine
- 画垂直线
- ****************************************************************************/
- void GuiDrawVLine(u16 y1, u16 y2, u16 x, u8 width, u8 colorIndex)//为0时使用默认的蓝色
- {
- if(width==0)return;
- if(y2<y1)return;
- width-=1;
- GuiFillRect(x,y1,x+width,y2,colorIndex);
- }
- #else
- /****************************************************************************
- GuiDrawVLine
- 画垂直线
- ****************************************************************************/
- void GuiDrawVLine(u16 y1, u16 y2, u16 x, u8 width)
- {
- if(width==0)return;
- if(y2<y1)return;
- width-=1;
- GuiFillRect(x,y1,x+width,y2);
- }
- #endif
- /****************************************************************************
- GuiDrawRect
- 画矩形框,中间不填充
- ****************************************************************************/
- //GuiDrawRect(x+i,y-i,x+i,y+i,1);
- void GuiDrawRect(u16 x1, u16 y1, u16 x2, u16 y2,u8 width)
- {
- if(x1>x2||y1>y2)return;
- GuiDrawHLine(x1,x2,y1,width);
- GuiDrawHLine(x1,x2,y2,width);
- GuiDrawVLine(y1,y2,x1,width,COLOR_DEFAULT_BLUE);
- GuiDrawVLine(y1,y2,x2,width,COLOR_DEFAULT_BLUE);
-
- }
- /***************************************************************************
- 根据前景色和背景色的颜色索引g_ucForeColorId、g_ucBackColorId,从当前调色板中获取前景色和背景色g_usForeColor、g_usBackColor
- ****************************************************************************/
- void UpdateColor(void)
- {
- u16 temp,r,g,b,RGB565;
- u8 R,G,B;
- //更新前景色
- temp=g_ucForeColorId*4;//调色板每个索引对应4个字节,分别是BGRA (蓝、绿、红、透明度),目前A未用
- B=g_Palette[temp];
- G=g_Palette[temp+1];
- R=g_Palette[temp+2];
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- RGB565=((r<<11) + (g<<5) + (b<<0));
- g_usForeColor=RGB565;
- //更新背景色
- temp=g_ucBackColorId*4;//调色板每个索引对应4个字节,分别是BGRA (蓝、绿、红、透明度),目前A未用
- B=g_Palette[temp];
- G=g_Palette[temp+1];
- R=g_Palette[temp+2];
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- RGB565=((r<<11) + (g<<5) + (b<<0));
- g_usBackColor=RGB565;
- //更新警告色
- temp=g_ucWarnColorId*4;//调色板每个索引对应4个字节,分别是BGRA (蓝、绿、红、透明度),目前A未用
- B=g_Palette[temp];
- G=g_Palette[temp+1];
- R=g_Palette[temp+2];
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- RGB565=((r<<11) + (g<<5) + (b<<0));
- g_usWarnColor=RGB565;
- }
- /****************************************************************************
- GuiShowArrow
- 显示箭头,箭头尺寸16*16 ,左上角坐标x,y
- 模式mode:
- 高四位代表填充: 0x--非填充(只有边缘线条) 1x--填充
- 低四位代表方向:x1--向左 x2--向右 x3--向上 x4--向下
- ****************************************************************************/
- void GuiShowArrow(u16 x,u16 y,u16 len,u8 mode)
- {
- u16 i;
- u8 dir,fill;
- // if(x>=(LCD_WIDTH-len) || y>=(LCD_HEIGHT-len))return;
- dir=mode&0x0f;
- fill=mode&0xf0;
- switch(dir)
- {
- case 1:
- for(i = 0 ; i < len ; i ++){
- GuiDrawRect(x+i,y-i,x+i,y+i,1);
- }
-
- break;
- case 2:
- for(i = 0 ; i < len ; i ++){
- GuiDrawRect(x-i,y-i,x-i,y+i,1);
- }
-
- break;
- case 3:
- for(i = 0 ; i < len ; i ++){
- GuiDrawRect(x-i,y+i,x+i,y+i,1);
- }
-
- break;
- case 4:
- for(i = 0 ; i < len ; i ++){
- GuiDrawRect(x-i,y-i,x+i,y-i,1);
- }
- break;
- default:
- break;
- }
- }
- /************************************************************************
- ShowButton
- 显示一个按钮
- *************************************************************************/
- void ShowButton(u16 x,u16 y,const char *str)
- {
- int len;
- len=GetStrXLen((char *)str);
- GuiClearRect(x,y,x+len+8,y+20);
- GuiShowStr(x+4,y+2,str,0x01,1);
- //GuiReverseRect(x,y,(x+len+8),(y+16+4));
- }
- void ShowMessageBox(char *msg)
- {
- char buf[70];
- u16 len,x,y;
-
- y=LCD_HEIGHT/2;
- GuiClearRect(0,y-20,LCD_WIDTH-1,y+20);
- GuiDrawRect(2,y-18,LCD_WIDTH-2,y+18,1);
- StrIntercept(buf,msg,18);
- len=GetStrXLen(buf);
- x=(LCD_WIDTH-len)/2;
- GuiShowStr(x,y-8,buf,0x01,0);
- }
- //注意调用此API前需要确定调用了
- //LcdBlockWrite
- void UpdateDot(unsigned char colorID){
- unsigned short RGB565;
- unsigned char R,G,B;
- unsigned short r,g,b;
- unsigned int temp;
-
- #if 1
- temp=colorID*4;
- B=g_Palette[temp];
- G=g_Palette[temp+1];
- R=g_Palette[temp+2];
-
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
- RGB565=((r<<11) + (g<<5) + (b<<0));
-
- LcdSendData(RGB565 >> 8);
- LcdSendData(RGB565 & 0xff);
- #else
-
- R=colorID;
- G=colorID++;
- B=colorID++;
-
- r = R>>3; // 取R色的高5位
- g = G>>2; // 取G色的高6位
- b = B>>3; // 取B色的高5位
-
- RGB565=((r<<11) + (g<<5) + (b<<0));
- LcdSendData(RGB565 >> 8);
- LcdSendData(RGB565 & 0xff);
-
- #endif
-
- }
- void lcdTestFlash(){
- static char i;
- switch(i){
- case 0:GuiClearAll();break;
- case 1:GuiShowStr(2,2,"hello world",1,0);break;
- case 2:GuiShowBmp(1,20,"speaker.bmp");break;
- case 3:GuiDrawRect(1,75, 41,85,1);break;
- case 4:GuiFillRect(1,87,41,100,COLOR_BLUE);break;
- case 5:GuiClearRect(1,87,41,100);break;
- case 6:GuiFillRect(1,87,41,100,COLOR_BLUE);break;
- case 7:GuiClearArea(1,87,41,14);break;
- case 8:GuiShowArrow(10,101,8,4);break;
- case 9:ShowButton(1,107,"菜单");break;//GuiShowStr(2,110,"reversed zone",1,1);break;
- default:break;
- }
- if(++i>15) i=0;
- }
- //stack init
- //typedef struct UI_STACK{
- // char sta[4];
- // char OK_back;//确认返回
- // char top;
- // unsigned char FastUiChange;//快捷方式进入
- //}UI_STACK;
- void Init_stack(struct UI_STACK* s)
- {
- memset(s->sta,0,sizeof(s->sta));
- s->OK_back=0;
- s->top=-1;
- s->FastUiChange=0;
- }
- //push stack
- int PushUiStack(struct UI_STACK *s,int data)
- {
- if(s->top==4){
- printf("stack full\r\n");
- return 1;
- }
-
- (s->top)++;
- s->sta[s->top]=data;
- return 0;
- }
- //pull stack
- int PullUiStack(struct UI_STACK *s)
- {
- int tmp;
- if(s->top<0){
- printf("stack is empty\r\n");
- return -1;
- }else {
- tmp=(s->sta)[s->top];
- (s->top)--;
- return tmp;
- }
-
- }
|