#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>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;ix2||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>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