123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- #include "gui.h"
- #include "lcdDrv.h"
- #include "nwy_file.h"
- #include "log.h"
- #include "fonts.h"
- #include "board.h"
- #include "uiEntry.h"
- #define COLOR_BACKGROUND COLOR_WHITE
- #define COLOR_FOREGROUND COLOR_BLUE
- unsigned int g_backColor;
- unsigned int g_foreColor;
- unsigned int guiGetBackColor(void){return g_backColor;}
- unsigned int guiGetForeColor(void){return g_foreColor;}
- static unsigned short RGB888_2_RGB565(unsigned int rgb888){
- unsigned short r,g,b,rgb565;
-
- b=(rgb888 >> (16+3))&0x1F;
- g=(rgb888 >> (8+2))&0x3f;
- r=(rgb888 >> (0+3))&0x1f;
-
- rgb565=((r<<11) + (g<<5) + (b<<0));
- return rgb565;
- }
- static void guiDrawDot(unsigned short colorData){
- LCD_DataWrite_ST7735(colorData >> 8);
- LCD_DataWrite_ST7735(colorData & 0xff);
- }
- static void guiBlockSet(unsigned short sx, unsigned short ex, unsigned short sy, unsigned short ey){
- LCD_CtrlWrite_ST7735(0x2a);
- guiDrawDot(sx);
- guiDrawDot(sy);
-
- LCD_CtrlWrite_ST7735(0x2B);
- guiDrawDot(ex);
- guiDrawDot(ey);
- LCD_CtrlWrite_ST7735(0x2C);
- }
- #define KEEP_HZK_OPENED //ê?·?±£3????t3£?a
- static int guiGetHzk(unsigned char hiByte, unsigned char loByte, unsigned char *pHzk, FONT_MODEENUM fontMode){
- unsigned char Q,W;
- unsigned int offset;
- const char hzk_12x12[]="HZK12";
- const char hzk_16x16[]="HZK16";
- char *hzk_ptr=NULL;
- static int fd_12=NULL,fd_16=NULL;
- int *fd_ptr=NULL;
- int fsize;
- if(hiByte<0xa0 || loByte<0xa0) return -1;
- Q=hiByte-0xa0;
- W=loByte-0xa0;
- if(FONT_MODE_12X12==fontMode){
- fsize = 24;
- hzk_ptr=(char *)hzk_12x12;
- fd_ptr=&fd_12;
- }else if(FONT_MODE_16X16==fontMode){
- fsize = 32;
- hzk_ptr=(char *)hzk_16x16;
- fd_ptr=&fd_16;
- }else return -2;
- offset=(94 * (Q-1) + (W-1))* fsize;
- //′ò?a???t
- if(*fd_ptr==NULL){
- int fd=nwy_sdk_fopen(hzk_ptr, NWY_RDONLY);
- if(fd==NULL){
- MSG_ERR(1, "%s open failed", hzk_ptr);
- return -3;
- }
- *fd_ptr=fd;
- }
- //?áè??úèY
- nwy_sdk_fseek(*fd_ptr, offset, NWY_SEEK_SET);
- offset=nwy_sdk_fread(*fd_ptr, pHzk,fsize);
- #ifndef KEEP_HZK_OPENED
- nwy_sdk_fclose(*fd_ptr);
- *fd_ptr=NULL;
- #endif
- return offset;
- }
- static void guiShowChars(unsigned short x,unsigned short y,unsigned char hiByte, unsigned char loByte,
- FONT_MODEENUM fontMode,
- unsigned int frontColorID,//????
- unsigned int backColorID,//????
- REV_ENUM rev){//??
- unsigned short i,j,k,m,n,fcolor,bcolor;
- unsigned short width,height;
- unsigned char ByteWidth,data;
- const unsigned char *l_pucFont,*l_pucLetter;
- unsigned char *p;
- unsigned char sucHzk16[32];
- unsigned char sucHzk12[24];
- int ret;
- //===?¨¨?¨′?Y?á??¤?¨|¨¨????¨o?|ì??¨a??é????é|ì??¨?¨oy?Y????|쨨===
-
- k = 0;
- if(hiByte==0){//english
- if(fontMode==FONT_MODE_12X12){//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 ++;
- }
- //2¨|?¨°|ì??á??a|ì??a¨o?????
- l_pucFont += k * ByteWidth * height;
- }else{//chinese
- if(fontMode==FONT_MODE_12X12){//12*16
- width=16;
- height = 12;
- ByteWidth = 2;
- l_pucFont = sucHzk12;
- l_pucLetter = 0;
- k=0;
- ret=guiGetHzk(hiByte,loByte,sucHzk12,fontMode);
- if(sizeof(sucHzk12)!=ret){//??¨?sFlash|ì?HZK???t?D?¨¢¨¨??á??a¨oy?Y
- //?¨°2?|ì??á??a?ê???¨o?"?¨2"
- l_pucFont=g_apucCLetter16;
- MSG_ERR(1, "guiGetHzk12Err:%02x,%02x,%d",hiByte,loByte,ret);
- }
- }else{//16*16
- width=16;
- height = 16;
- ByteWidth = 2;
- l_pucFont = sucHzk16;
- l_pucLetter = 0;
- k=0;
- ret=guiGetHzk(hiByte,loByte,sucHzk16,fontMode);
- if(sizeof(sucHzk16)!=ret){//??¨?sFlash|ì?HZK16???t?D?¨¢¨¨??á??a¨oy?Y
- //?¨°2?|ì??á??a?ê???¨o?"?¨2"
- l_pucFont=g_apucCLetter16;
- MSG_ERR(1, "guiGetHzk16Err:%02x,%02x,%d",hiByte,loByte,ret);
- }
- }
- }
- //====================?¨′??|¨¤¨a|ì??¨?¨oy?Y==========
- if(y+height>GLCD_HEIGHT)return;
- if(x+width>GLCD_WIDTH)return;
- guiBlockSet(x,y,x+width-1,y+height-1);//8,12
- fcolor=RGB888_2_RGB565(frontColorID);
- bcolor=RGB888_2_RGB565(backColorID);
- //¨°?????à?¨???|ì??¨???é|ì?LCD?ê?2?¨?????????ê¨??¨?¨22a¨o??ê??á?騰a|ì??¨??2?¨°a|ì??¨??PaintBufToLcd?ê??¤??¨°¨°2??é?¨¢¨¢?
- //?¨′?Y?á???ê?¨2??????D?-|ì?
- 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)){//??,??frontColorID
- if(REVERSED_NO==rev) guiDrawDot(fcolor);
- else guiDrawDot(bcolor);
- }else{//??,??backColorID
- if(REVERSED_NO==rev) guiDrawDot(bcolor);
- else guiDrawDot(fcolor);
- }
- }
- }
- }
- }
- short guiGetStrXLen(char *str, FONT_MODEENUM fontMode){
- unsigned char ch;
- unsigned short len=0;
- unsigned char bsize;
-
- if(FONT_MODE_12X12==fontMode) bsize=6;
- else if(FONT_MODE_16X16==fontMode) bsize=8;
- else return 0;
- while ((ch=*str++)){
- if(ch=='M')len+=12;
- else if(ch>='A'&&ch<='Z')len+=8;
- else if(ch>='a'&&ch<='z')len+=8;
- else if(ch>='0'&&ch<='9')len+=8;
- else if(ch>=0x20&& ch<=0x60)len+=8; //¨??¨oa?á??¤?
- else len+=bsize;
- }
- return len;
- }
- //ò????ó?ú??ía?a·?
- void guiShowStr(unsigned short x, unsigned short y,const char *string, FONT_MODEENUM fontMode,
- REV_ENUM rev, //????
- unsigned int frontColorID,//???
- unsigned int backColorID){//???
- unsigned char width1,width2,heigh;
- unsigned char *p;
- unsigned short i;
-
- if(fontMode == FONT_MODE_12X12){
- width1 = 12;
- width2 = 1;
- heigh=12;
- }else if(fontMode == FONT_MODE_16X16){
- width1 = 16;
- width2 = 1;
- heigh=16;
- }else return;
- p = (unsigned char *)string;
- i = 0;
-
- while(*p){
- if (*p > 0x9f){//chinese letter
- guiShowChars(x+i,y,*p, *(p+1),fontMode,frontColorID,backColorID,rev);
- i += width1 ;
- p += 2;
- }else{//english letter
- guiShowChars(x + i,y,0,*p,fontMode,frontColorID,backColorID,rev);
- if(fontMode==0) i += width2 * 8;
- else i += width2 * 8;
- p ++;
- }
- }
- }
- void guiShowButton(unsigned short x, unsigned short y,const char *str, FONT_MODEENUM fontMode,unsigned int buttonColorID, unsigned int strColorID){
- int heigh,len;
-
- if(FONT_MODE_12X12==fontMode) heigh=12+4;
- else if(FONT_MODE_16X16==fontMode) heigh=16+4;
- else return;
- len=guiGetStrXLen((char *)str, fontMode);
- guiFillRect(x,y,x+len+8,y+heigh,buttonColorID);
- guiShowStr(x+4, y+1, str, fontMode,REVERSED_NO,strColorID,buttonColorID);
- }
- void guiFillRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2,unsigned int colorData){
- unsigned short x=x2,y=y2,w,h,i,m,k,j,data;
- if(x1>x2 || y1>y2) return;
- if(x1>=GLCD_WIDTH || y1>=GLCD_HEIGHT) return;
- if(x>GLCD_WIDTH) x=GLCD_WIDTH;
- if(y>GLCD_HEIGHT) y=GLCD_HEIGHT;
- w=x-x1+1;
- h=y-y1+1;
- data=RGB888_2_RGB565(colorData);
- guiBlockSet(x1,y1,x,y);
- for(i=0;i<h;i++){
- m=y1+i;
- for(j=0;j<w;j++){
- k=x1+j;
- guiDrawDot(data);
- }
- }
- }
- void guiClearRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned int colorData){
- guiFillRect(x1,y1,x2,y2,colorData);
- }
- //??????
- void guiDrawHLine(unsigned short x1, unsigned short x2, unsigned short y, unsigned short ysize, unsigned int colorID){
- if(ysize==0) return;
- if(x2<x1) return;
- guiFillRect(x1,y,x2,y+ysize-1,colorID);
- }
- //′1?±??
- void guiDrawVLine(unsigned short y1, unsigned short y2, unsigned short x, unsigned short xsize, unsigned int colorID){
- if(xsize==0) return;
- if(y2<y1) return;
- guiFillRect(x,y1,x+xsize-1,y2,colorID);
- }
- void guiDrawRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2,unsigned char width, unsigned int colorID){
- if(x1>x2||y1>y2) return;
- guiDrawHLine(x1,x2,y1,width,colorID);
- guiDrawHLine(x1,x2,y2,width,colorID);
- guiDrawVLine(y1,y2,x1,width,colorID);
- guiDrawVLine(y1,y2+width-1,x2,width,colorID);
- }
- //óé·??ò?aμ?(x,y)?aê??-
- void guiDrawArrow(unsigned short x, unsigned short y,unsigned short len, ARROW_ENUM direction, unsigned int colorID){
- unsigned short i;
- switch(direction){
- case ARROW_LEFT:
- for(i=0;i<len;i++) guiDrawRect(x+i,y-i,x+i,y+i,1,colorID);
- break;
- case ARROW_RIGHT:
- for(i=0;i<len;i++) guiDrawRect(x-i,y-i,x-i,y+i,1,colorID);
- break;
- case ARROW_UP:
- for(i=0;i<len;i++) guiDrawRect(x-i,y+i,x+i,y+i,1,colorID);
- break;
- case ARROW_DOWN:
- for(i=0;i<len;i++) guiDrawRect(x-i,y-i,x+i,y-i,1,colorID);
- break;
- }
- }
- static void guiFillBmpBuf(unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned char *bmpBuf){
- int i,j,k,t;
- unsigned short RGB565,r,g,b;
- unsigned char R,G,B;
- for(j=0;j<height;j++){
- t=y+j;
- k=j*width;
- for(i=0;i<width;i++){
- R=bmpBuf[3*i];
- G=bmpBuf[3*i+1];
- B=bmpBuf[3*i+2];
- r=R>>3;
- g=G>>2;
- b=B>>3;
- RGB565=((r<<11)+(g<<5)+(b<<0));
- guiDrawDot(RGB565);
- }
- }
- }
- void guiShowBmp(unsigned short x, unsigned short y, char *bmp){
- int fd,l,w,i;
- unsigned short type;
- unsigned int width,height,bfOffBits;
- unsigned char tbuf[GLCD_WIDTH*4];
- fd=nwy_sdk_fopen(bmp, NWY_RDONLY);
- if(fd<0){
- MSG_ERR(1, "%s open failed", bmp);
- return;
- }
- //?áè????tààDí
- nwy_sdk_fseek(fd, 0x1c, NWY_SEEK_SET);
- nwy_sdk_fread(fd, (unsigned char *)&type, 2);
- if(type != 0x0018){
- MSG_ERR(1, "%s is not 24bits bmp",bmp);
- nwy_sdk_fclose(fd);
- return;
- }
- //?áè?í????í?è
- nwy_sdk_fseek(fd, 0x12, NWY_SEEK_SET);
- nwy_sdk_fread(fd, (unsigned char *)&width, 4);
- //?áè?í??????è
- nwy_sdk_fseek(fd, 0x16, NWY_SEEK_SET);
- nwy_sdk_fread(fd, (unsigned char *)&height, 4);
- //?D??3?′?
- if(width>GLCD_WIDTH || height>GLCD_HEIGHT){
- MSG_ERR(1, "%s size overflow",bmp);
- nwy_sdk_fclose(fd);
- return;
- }
- //?á3?êy?Y?eê?μ??·
- nwy_sdk_fseek(fd, 0x0a, NWY_SEEK_SET);
- nwy_sdk_fread(fd, (unsigned char *)&bfOffBits, 4);
- l=width%4;
- w=width*3+l;
- l=height-1;
- guiBlockSet(x,y,x+width-1,y+height-1);
- for(i=0;i<height;i++){
- nwy_sdk_fseek(fd, bfOffBits+l*w, NWY_SEEK_SET);
- nwy_sdk_fread(fd, tbuf, w);
- guiFillBmpBuf(x,y+i,width,1,tbuf);
- l--;
- }
-
- nwy_sdk_fclose(fd);
- }
- /*?ó?D??ê?*/
- void guiShowCaption(unsigned short xType, const char *str, unsigned short y, unsigned int frontColorID, unsigned int backColorID, FONT_MODEENUM fontMode){
- int len,sy;
- unsigned short x;
- if(xType==0){
- len=guiGetStrXLen((char *)str,fontMode);
- x=(GLCD_WIDTH-len)/2;
- }else x=xType;
- guiShowStr(x, y, str, fontMode, REVERSED_NO, frontColorID, backColorID);
- }
- void guiClearArea(unsigned short x, unsigned short y, unsigned short width, unsigned short height,unsigned int colorID){
- guiFillRect(x,y,x+width,y+height,colorID);
- }
- void guiInit(void){
- g_backColor=COLOR_BACKGROUND;
- g_foreColor=COLOR_FOREGROUND;
- guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());
-
- SetMessageConfi();
- guiShowBmp(0,0,"welcome.bmp");//开机图片
- CTL_LCD_BL(1);//清屏后打开,否则会看到关机前的画面
- }
- void guiClearAll(unsigned int colorID){//只清第二,三区
- guiFillRect(0, UI_STATUS_ITEM_Y, GLCD_WIDTH-1, UI_CONTENT_SHOW_Y-1, guiGetForeColor());//清除第二区
- guiFillRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,GLCD_HEIGHT-1,colorID);
- }
- void guiShowMessageBox(char *msg){
- char buf[70];
- short len,x,y;
- y=GLCD_HEIGHT/2;
- guiClearRect(0,y-20,GLCD_WIDTH-1,y+20,guiGetBackColor());
- guiDrawRect(2,y-18,GLCD_WIDTH-3,y+18,1,COLOR_BLACK);
- StrIntercept(buf,msg,18);
- len=guiGetStrXLen(buf,FONT_MODE_16X16);
- x=(GLCD_WIDTH-len)/2;
- guiShowStr(x,y-8,buf,FONT_MODE_16X16,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
- }
- void guiShowTwoMessage(char *msg1, char *msg2){
- char buf[70];
- short len, x, y;
- y=GLCD_HEIGHT/2;
- guiClearRect(0,y-20,GLCD_WIDTH-1,y+20,guiGetBackColor());
- guiDrawRect(1,y-19,GLCD_WIDTH-2,y+19,1,COLOR_BLACK);
-
- StrIntercept(buf,msg1,18);
- len=guiGetStrXLen(buf,FONT_MODE_16X16);
- x=(GLCD_WIDTH-len)/2;
- guiShowStr(x,y-18,buf,FONT_MODE_16X16,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
-
- StrIntercept(buf,msg2,18);
- len=guiGetStrXLen(buf,FONT_MODE_16X16);
- x=(GLCD_WIDTH-len)/2;
- guiShowStr(x,y+2,buf,FONT_MODE_16X16,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
- }
- //////////////////////////////////////测试接口///////////////////////////////////
- void guiTest(void){
- return;
- //char testbuf[5]={0xB2,0xE2,0xCA,0xD4,0x00};
- //??ê?DD??
- guiDrawHLine(1, GLCD_WIDTH-2, 1, 1, guiGetForeColor());
- //??ê?áD??
- guiDrawVLine(3, GLCD_HEIGHT-2, 1, 1, guiGetForeColor());
- //??ê???D???D?
- guiDrawRect(3,3,3+10,3+10,1,guiGetForeColor());
- //??ê?êμD???D?
- guiFillRect(15, 3, 15+10, 3+10,guiGetForeColor());
- //??ê??yí·
- guiDrawArrow(50, 3,10, ARROW_UP, guiGetForeColor());
- guiDrawArrow(70, 3+10,10, ARROW_DOWN, guiGetForeColor());
- guiDrawArrow(90, 3+8,10, ARROW_LEFT, guiGetForeColor());
- guiDrawArrow(110, 3+8,10, ARROW_RIGHT, guiGetForeColor());
- //??ê?12X12×?·?′?
- guiShowStr(3, 30,"123测试45中,国AW", FONT_MODE_12X12, REVERSED_NO,guiGetForeColor(),guiGetBackColor());
- //??ê?16X16×?·?′?
- guiShowStr(3, 50,"123测试45你。好AW", FONT_MODE_16X16, REVERSED_NO,guiGetForeColor(),guiGetBackColor());
- //??ê?í???
- guiShowBmp(3, 80, "Palace2.bmp");
- //??ê?°′?ü
- guiShowButton(100, 80,"B12", FONT_MODE_12X12,guiGetForeColor(), guiGetBackColor());
- }
|