gui.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. #include "gui.h"
  2. #include "app.h"
  3. #include "lcdDrv.h"
  4. #include "lsapi_fs.h"
  5. #include "log.h"
  6. #include "fonts.h"
  7. #include "ohboard.h"
  8. #include "uiEntry.h"
  9. #define COLOR_BACKGROUND COLOR_WHITE
  10. #define COLOR_FOREGROUND COLOR_BLUE
  11. unsigned int g_backColor;
  12. unsigned int g_foreColor;
  13. unsigned int guiGetBackColor(void){return g_backColor;}
  14. unsigned int guiGetForeColor(void){return g_foreColor;}
  15. static unsigned short RGB888_2_RGB565(unsigned int rgb888){
  16. unsigned short r,g,b,rgb565;
  17. b=(rgb888 >> (16+3))&0x1F;
  18. g=(rgb888 >> (8+2))&0x3f;
  19. r=(rgb888 >> (0+3))&0x1f;
  20. rgb565=((r<<11) + (g<<5) + (b<<0));
  21. return rgb565;
  22. }
  23. static void guiDrawDot(unsigned short colorData){
  24. LCD_DataWrite_ST7735(colorData >> 8);
  25. LCD_DataWrite_ST7735(colorData & 0xff);
  26. }
  27. static void guiBlockSet(unsigned short sx, unsigned short ex, unsigned short sy, unsigned short ey){
  28. LCD_CtrlWrite_ST7735(0x2a);
  29. guiDrawDot(sx);
  30. guiDrawDot(sy);
  31. LCD_CtrlWrite_ST7735(0x2B);
  32. guiDrawDot(ex);
  33. guiDrawDot(ey);
  34. LCD_CtrlWrite_ST7735(0x2C);
  35. }
  36. #define KEEP_HZK_OPENED //ê?·?±£3????t3£?a
  37. static int guiGetHzk(unsigned char hiByte, unsigned char loByte, unsigned char *pHzk, FONT_MODEENUM fontMode){
  38. unsigned char Q,W;
  39. unsigned int offset;
  40. const char hzk_12x12[]="HZK12";
  41. const char hzk_16x16[]="HZK16";
  42. char *hzk_ptr=NULL;
  43. static int fd_12=NULL,fd_16=NULL;
  44. int *fd_ptr=NULL;
  45. int fsize;
  46. if(hiByte<0xa0 || loByte<0xa0)return -1;
  47. Q=hiByte-0xa0;
  48. W=loByte-0xa0;
  49. if(FONT_MODE_12X12==fontMode){
  50. fsize = 24;
  51. hzk_ptr=(char *)hzk_12x12;
  52. fd_ptr=&fd_12;
  53. }else if(FONT_MODE_16X16==fontMode){
  54. fsize = 32;
  55. hzk_ptr=(char *)hzk_16x16;
  56. fd_ptr=&fd_16;
  57. }else return -2;
  58. offset=(94 * (Q-1) + (W-1))* fsize;
  59. //′ò?a???t
  60. if(*fd_ptr==NULL){
  61. int fd=LSAPI_FS_Open(hzk_ptr, LSAPI_FS_O_RDONLY, 0);
  62. if(fd==NULL){
  63. MSG_ERR(1, "%s open failed", hzk_ptr);
  64. return -3;
  65. }
  66. *fd_ptr=fd;
  67. }
  68. //?áè??úèY
  69. LSAPI_FS_Seek(*fd_ptr, offset, LSAPI_FS_SEEK_SET);
  70. offset=LSAPI_FS_Read(*fd_ptr, pHzk,fsize);
  71. #ifndef KEEP_HZK_OPENED
  72. LSAPI_FS_Close(*fd_ptr);
  73. *fd_ptr=NULL;
  74. #endif
  75. return offset;
  76. }
  77. static void guiShowChars(unsigned short x,unsigned short y,unsigned char hiByte, unsigned char loByte,
  78. FONT_MODEENUM fontMode,
  79. unsigned int frontColorID,//????
  80. unsigned int backColorID,//????
  81. REV_ENUM rev){//??
  82. unsigned short i,j,k,m,n,fcolor,bcolor;
  83. unsigned short width,height;
  84. unsigned char ByteWidth,data;
  85. const unsigned char *l_pucFont,*l_pucLetter;
  86. unsigned char *p;
  87. unsigned char sucHzk16[32];
  88. unsigned char sucHzk12[24];
  89. int ret;
  90. //===?¨¨?¨′?Y?á??¤?¨|¨¨????¨o?|ì??¨a??é????é|ì??¨?¨oy?Y????|쨨===
  91. k = 0;
  92. if(hiByte==0){//english
  93. if(fontMode==FONT_MODE_12X12){//8* 12
  94. width=8;//8
  95. height = 12; //12
  96. ByteWidth = 1;
  97. l_pucFont = g_apucFonts12;
  98. l_pucLetter = g_apucLetter12;
  99. }else{ //8*16
  100. width=8;
  101. height = 16;
  102. ByteWidth = 1;
  103. l_pucFont = g_apucFonts16;
  104. l_pucLetter = g_apucLetter16;
  105. }
  106. while(*l_pucLetter){
  107. if(loByte == *l_pucLetter)break;
  108. l_pucLetter ++;
  109. k ++;
  110. }
  111. //2¨|?¨°|ì??á??a|ì??a¨o?????
  112. l_pucFont += k * ByteWidth * height;
  113. }else{//chinese
  114. if(fontMode==FONT_MODE_12X12){//12*16
  115. width=16;
  116. height = 12;
  117. ByteWidth = 2;
  118. l_pucFont = sucHzk12;
  119. l_pucLetter = 0;
  120. k=0;
  121. ret=guiGetHzk(hiByte,loByte,sucHzk12,fontMode);
  122. if(sizeof(sucHzk12)!=ret){//??¨?sFlash|ì?HZK???t?D?¨¢¨¨??á??a¨oy?Y
  123. //?¨°2?|ì??á??a?ê???¨o?"?¨2"
  124. l_pucFont=g_apucCLetter16;
  125. MSG_ERR(1, "guiGetHzk12Err:%02x,%02x,%d",hiByte,loByte,ret);
  126. }
  127. }else{//16*16
  128. width=16;
  129. height = 16;
  130. ByteWidth = 2;
  131. l_pucFont = sucHzk16;
  132. l_pucLetter = 0;
  133. k=0;
  134. ret=guiGetHzk(hiByte,loByte,sucHzk16,fontMode);
  135. if(sizeof(sucHzk16)!=ret){//??¨?sFlash|ì?HZK16???t?D?¨¢¨¨??á??a¨oy?Y
  136. //?¨°2?|ì??á??a?ê???¨o?"?¨2"
  137. l_pucFont=g_apucCLetter16;
  138. MSG_ERR(1, "guiGetHzk16Err:%02x,%02x,%d",hiByte,loByte,ret);
  139. }
  140. }
  141. }
  142. //====================?¨′??|¨¤¨a|ì??¨?¨oy?Y==========
  143. if(y+height>GLCD_HEIGHT)return;
  144. if(x+width>GLCD_WIDTH)return;
  145. guiBlockSet(x,y,x+width-1,y+height-1);//8,12
  146. fcolor=RGB888_2_RGB565(frontColorID);
  147. bcolor=RGB888_2_RGB565(backColorID);
  148. //¨°?????à?¨???|ì??¨???é|ì?LCD?ê?2?¨?????????ê¨??¨?¨22a¨o??ê??á?騰a|ì??¨??2?¨°a|ì??¨??PaintBufToLcd?ê??¤??¨°¨°2??é?¨¢¨¢?
  149. //?¨′?Y?á???ê?¨2??????D?-|ì?
  150. for(j=0;j<height;j++){
  151. m=y+j;
  152. for(i=0;i<ByteWidth;i++){
  153. n=x+i*8;
  154. data=*l_pucFont++;
  155. for(k=0;k<8;k++){
  156. if(data & (0x80>>k)){//??,??frontColorID
  157. if(REVERSED_NO==rev) guiDrawDot(fcolor);
  158. else guiDrawDot(bcolor);
  159. }else{//??,??backColorID
  160. if(REVERSED_NO==rev) guiDrawDot(bcolor);
  161. else guiDrawDot(fcolor);
  162. }
  163. }
  164. }
  165. }
  166. }
  167. short guiGetStrXLen(char *str, FONT_MODEENUM fontMode){
  168. unsigned char ch;
  169. unsigned short len=0;
  170. unsigned char bsize;
  171. if(FONT_MODE_12X12==fontMode) bsize=6;
  172. else if(FONT_MODE_16X16==fontMode) bsize=8;
  173. else return 0;
  174. while ((ch=*str++)){
  175. if(ch=='M')len+=12;
  176. else if(ch>='A'&&ch<='Z')len+=8;
  177. else if(ch>='a'&&ch<='z')len+=8;
  178. else if(ch>='0'&&ch<='9')len+=8;
  179. else if(ch>=0x20&& ch<=0x60)len+=8; //¨??¨oa?á??¤?
  180. else len+=bsize;
  181. }
  182. return len;
  183. }
  184. //ò????ó?ú??ía?a·?
  185. void guiShowStr(unsigned short x, unsigned short y,const char *string, FONT_MODEENUM fontMode,
  186. REV_ENUM rev, //????
  187. unsigned int frontColorID,//???
  188. unsigned int backColorID){//???
  189. unsigned char width1,width2,heigh;
  190. unsigned char *p;
  191. unsigned short i;
  192. //fontMode=FONT_MODE_12X12;// BND 文件系统大小不够
  193. if(fontMode == FONT_MODE_12X12){
  194. width1 = 12;
  195. width2 = 1;
  196. heigh=12;
  197. }else if(fontMode == FONT_MODE_16X16){
  198. width1 = 16;
  199. width2 = 1;
  200. heigh=16;
  201. }else return;
  202. p = (unsigned char *)string;
  203. i = 0;
  204. while(*p){
  205. if (*p > 0x9f){//chinese letter
  206. guiShowChars(x+i,y,*p, *(p+1),fontMode,frontColorID,backColorID,rev);
  207. i += width1 ;
  208. p += 2;
  209. }else{//english letter
  210. guiShowChars(x + i,y,0,*p,fontMode,frontColorID,backColorID,rev);
  211. if(fontMode==0) i += width2 * 8;
  212. else i += width2 * 8;
  213. p ++;
  214. }
  215. }
  216. }
  217. void guiShowButton(unsigned short x, unsigned short y,const char *str, FONT_MODEENUM fontMode,unsigned int buttonColorID, unsigned int strColorID){
  218. int heigh,len;
  219. if(FONT_MODE_12X12==fontMode) heigh=12+4;
  220. else if(FONT_MODE_16X16==fontMode) heigh=16+4;
  221. else return;
  222. len=guiGetStrXLen((char *)str, fontMode);
  223. guiFillRect(x,y,x+len+8,y+heigh,buttonColorID);
  224. guiShowStr(x+4, y+1, str, fontMode,REVERSED_NO,strColorID,buttonColorID);
  225. }
  226. void guiFillRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2,unsigned int colorData){
  227. unsigned short x=x2,y=y2,w,h,i,m,k,j,data;
  228. if(x1>x2 || y1>y2) return;
  229. if(x1>=GLCD_WIDTH || y1>=GLCD_HEIGHT) return;
  230. if(x>GLCD_WIDTH) x=GLCD_WIDTH;
  231. if(y>GLCD_HEIGHT) y=GLCD_HEIGHT;
  232. w=x-x1+1;
  233. h=y-y1+1;
  234. data=RGB888_2_RGB565(colorData);
  235. guiBlockSet(x1,y1,x,y);
  236. for(i=0;i<h;i++){
  237. m=y1+i;
  238. for(j=0;j<w;j++){
  239. k=x1+j;
  240. guiDrawDot(data);
  241. }
  242. }
  243. }
  244. void guiClearRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned int colorData){
  245. guiFillRect(x1,y1,x2,y2,colorData);
  246. }
  247. //??????
  248. void guiDrawHLine(unsigned short x1, unsigned short x2, unsigned short y, unsigned short ysize, unsigned int colorID){
  249. if(ysize==0) return;
  250. if(x2<x1) return;
  251. guiFillRect(x1,y,x2,y+ysize-1,colorID);
  252. }
  253. //′1?±??
  254. void guiDrawVLine(unsigned short y1, unsigned short y2, unsigned short x, unsigned short xsize, unsigned int colorID){
  255. if(xsize==0) return;
  256. if(y2<y1) return;
  257. guiFillRect(x,y1,x+xsize-1,y2,colorID);
  258. }
  259. void guiDrawRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2,unsigned char width, unsigned int colorID){
  260. if(x1>x2||y1>y2) return;
  261. guiDrawHLine(x1,x2,y1,width,colorID);
  262. guiDrawHLine(x1,x2,y2,width,colorID);
  263. guiDrawVLine(y1,y2,x1,width,colorID);
  264. guiDrawVLine(y1,y2+width-1,x2,width,colorID);
  265. }
  266. //óé·??ò?aμ?(x,y)?aê??-
  267. void guiDrawArrow(unsigned short x, unsigned short y,unsigned short len, ARROW_ENUM direction, unsigned int colorID){
  268. unsigned short i;
  269. switch(direction){
  270. case ARROW_LEFT:
  271. for(i=0;i<len;i++) guiDrawRect(x+i,y-i,x+i,y+i,1,colorID);
  272. break;
  273. case ARROW_RIGHT:
  274. for(i=0;i<len;i++) guiDrawRect(x-i,y-i,x-i,y+i,1,colorID);
  275. break;
  276. case ARROW_UP:
  277. for(i=0;i<len;i++) guiDrawRect(x-i,y+i,x+i,y+i,1,colorID);
  278. break;
  279. case ARROW_DOWN:
  280. for(i=0;i<len;i++) guiDrawRect(x-i,y-i,x+i,y-i,1,colorID);
  281. break;
  282. }
  283. }
  284. static void guiFillBmpBuf(unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned char *bmpBuf){
  285. int i,j,k,t;
  286. unsigned short RGB565,r,g,b;
  287. unsigned char R,G,B;
  288. for(j=0;j<height;j++){
  289. t=y+j;
  290. k=j*width;
  291. for(i=0;i<width;i++){
  292. R=bmpBuf[3*i];
  293. G=bmpBuf[3*i+1];
  294. B=bmpBuf[3*i+2];
  295. r=R>>3;
  296. g=G>>2;
  297. b=B>>3;
  298. RGB565=((r<<11)+(g<<5)+(b<<0));
  299. guiDrawDot(RGB565);
  300. }
  301. }
  302. }
  303. void guiShowBmp(unsigned short x, unsigned short y, char *bmp){
  304. int fd,l,w,i;
  305. unsigned short type;
  306. unsigned int width,height,bfOffBits;
  307. unsigned char tbuf[GLCD_WIDTH*4];
  308. fd=LSAPI_FS_Open(bmp, LSAPI_FS_O_RDONLY,0);
  309. if(fd<0){
  310. MSG_ERR(1, "%s open failed", bmp);
  311. return;
  312. }
  313. //?áè????tààDí
  314. LSAPI_FS_Seek(fd, 0x1c, LSAPI_FS_SEEK_SET);
  315. LSAPI_FS_Read(fd, (unsigned char *)&type, 2);
  316. if(type != 0x0018){
  317. MSG_ERR(1, "%s is not 24bits bmp",bmp);
  318. LSAPI_FS_Close(fd);
  319. return;
  320. }
  321. //?áè?í????í?è
  322. LSAPI_FS_Seek(fd, 0x12, LSAPI_FS_SEEK_SET);
  323. LSAPI_FS_Read(fd, (unsigned char *)&width, 4);
  324. //?áè?í??????è
  325. LSAPI_FS_Seek(fd, 0x16, LSAPI_FS_SEEK_SET);
  326. LSAPI_FS_Read(fd, (unsigned char *)&height, 4);
  327. //?D??3?′?
  328. if(width>GLCD_WIDTH || height>GLCD_HEIGHT){
  329. MSG_ERR(1, "%s size overflow",bmp);
  330. LSAPI_FS_Close(fd);
  331. return;
  332. }
  333. //?á3?êy?Y?eê?μ??·
  334. LSAPI_FS_Seek(fd, 0x0a, LSAPI_FS_SEEK_SET);
  335. LSAPI_FS_Read(fd, (unsigned char *)&bfOffBits, 4);
  336. l=width%4;
  337. w=width*3+l;
  338. l=height-1;
  339. guiBlockSet(x,y,x+width-1,y+height-1);
  340. for(i=0;i<height;i++){
  341. LSAPI_FS_Seek(fd, bfOffBits+l*w, LSAPI_FS_SEEK_SET);
  342. LSAPI_FS_Read(fd, tbuf, w);
  343. guiFillBmpBuf(x,y+i,width,1,tbuf);
  344. l--;
  345. }
  346. LSAPI_FS_Close(fd);
  347. }
  348. /*?ó?D??ê?*/
  349. void guiShowCaption(unsigned short xType, const char *str, unsigned short y, unsigned int frontColorID, unsigned int backColorID, FONT_MODEENUM fontMode){
  350. int len,sy;
  351. unsigned short x;
  352. len=guiGetStrXLen((char *)str,fontMode);
  353. if(xType==0) x=(GLCD_WIDTH-len)/2;
  354. else x=xType;
  355. guiShowStr(x, y, str, fontMode, REVERSED_NO, frontColorID, backColorID);
  356. }
  357. void guiClearArea(unsigned short x, unsigned short y, unsigned short width, unsigned short height,unsigned int colorID){
  358. guiFillRect(x,y,x+width,y+height,colorID);
  359. }
  360. void guiInit(void){
  361. g_backColor=COLOR_BACKGROUND;
  362. g_foreColor=COLOR_FOREGROUND;
  363. guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());
  364. // SetMessageConfi();
  365. if(sutApp.account.tnet==5)guishow_png(15,14,"welcome5G.png");//开机图片
  366. else guishow_png(15,14,"welcome.png");//开机图片
  367. //CTL_LCD_BL(1);//清屏后打开,否则会看到关机前的画面
  368. lcdBackLightApi(1);//清屏后打开,否则会看到关机前的画面
  369. }
  370. void guiClearAll(unsigned int colorID){//只清第二,三区
  371. guiFillRect(0, UI_STATUS_ITEM_Y, GLCD_WIDTH-1, UI_CONTENT_SHOW_Y-1, guiGetForeColor());//清除第二区
  372. guiFillRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,GLCD_HEIGHT-1,colorID);
  373. }
  374. void guiShowMessageBox(char *msg){
  375. char buf[70];
  376. short len,x,y;
  377. y=GLCD_HEIGHT/2;
  378. guiClearRect(0,y-20,GLCD_WIDTH-1,y+20,guiGetBackColor());
  379. guiDrawRect(2,y-18,GLCD_WIDTH-3,y+18,1,COLOR_BLACK);
  380. StrIntercept(buf,msg,18);
  381. #ifdef USE_12X12_FONT_ONLY
  382. len=guiGetStrXLen(buf,FONT_MODE_12X12);
  383. x=(GLCD_WIDTH-len)/2;
  384. guiShowStr(x,y-6,buf,FONT_MODE_12X12,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  385. #else
  386. len=guiGetStrXLen(buf,FONT_MODE_16X16);
  387. x=(GLCD_WIDTH-len)/2;
  388. guiShowStr(x,y-8,buf,FONT_MODE_16X16,REVERSED_NO,COLOR_BLACK,guiGetBackColor());
  389. #endif
  390. }
  391. /*
  392. x1,x2:显示的起点坐标
  393. multiple:放大倍数
  394. data:QRCODE数据缓存
  395. size:QRCODE图片大小,长=宽
  396. */
  397. void guiDrawQRimage(unsigned short x1, unsigned short y1,unsigned char multiple,unsigned char **data, int size){
  398. unsigned short x=x1+size,y=y1+size,w,h,i,j,ww,kk;
  399. unsigned short startx, starty,endx,endy;
  400. unsigned char tmp;
  401. if(multiple<=0) tmp=1;
  402. else tmp=multiple;
  403. if(x1>=GLCD_WIDTH || y1>=GLCD_HEIGHT) return;
  404. if(x>GLCD_WIDTH) x=GLCD_WIDTH;
  405. if(y>GLCD_HEIGHT) y=GLCD_HEIGHT;
  406. w=x-x1+1;
  407. h=y-y1+1;
  408. unsigned short blackdata=RGB888_2_RGB565(COLOR_BLACK);
  409. unsigned short whitedata=RGB888_2_RGB565(COLOR_WHITE);
  410. unsigned short filldata;
  411. if(tmp==1) guiBlockSet(x1,y1,x,y);
  412. else kk=tmp+1;
  413. for(i=0;i<w;i++){
  414. startx=x1+i*tmp;
  415. for(j=0;j<h;j++){
  416. starty=y1+j*tmp;
  417. if(data[i][j]==0) filldata=whitedata;
  418. else filldata=blackdata;
  419. if(tmp==1) guiDrawDot(filldata);
  420. else{
  421. endx=startx+tmp;endy=starty+tmp;
  422. guiBlockSet(startx,starty,endx,endy);
  423. for(ww=0;ww<(kk*kk);ww++) guiDrawDot(filldata);
  424. }
  425. }
  426. }
  427. }
  428. //888
  429. void guiDrawPngImage(unsigned char x, unsigned char y,unsigned char width,unsigned char height,char*bmpBuf)
  430. {
  431. int i,j;
  432. unsigned short RGB565,r,g,b;
  433. unsigned char R,G,B;
  434. guiBlockSet(x,y,x+width-1,y+height-1);
  435. for(j=0;j<height;j++){
  436. for(i=0;i<width;i++){
  437. R=bmpBuf[3*j*width+3*i+0];
  438. G=bmpBuf[3*j*width+3*i+1];
  439. B=bmpBuf[3*j*width+3*i+2];
  440. b=R>>3;
  441. g=G>>2;
  442. r=B>>3;
  443. RGB565=((r<<11)+(g<<5)+(b<<0));
  444. guiDrawDot(RGB565);
  445. }
  446. }
  447. }
  448. //00 af 00af
  449. int guishow_png(unsigned short x,unsigned short y,char* filename)
  450. {
  451. unsigned error;
  452. unsigned char*image;
  453. size_t width, height;
  454. error = lodepng_decode24_file(&image, &width, &height, filename);
  455. if(error) MSG_INFO(1,"decoder error %u: %s\n", error, lodepng_error_text(error));
  456. if(sutUIstatus.Status!=UIS_MENU_LOCATION_SEL)guiDrawPngImage(x,y,width,height,image);
  457. else {
  458. MSG_INFO(1,"width==%d,height==%d",width,height);
  459. height= GLCD_HEIGHT-UI_CONTENT_SHOW_Y;//瀹為檯 鏄剧ず澶у皬
  460. guiDrawPngImage(x,y,width,height,image);
  461. }
  462. // * use image here * /
  463. free(image);
  464. return 0;
  465. }
  466. /***************************涓荤晫闈㈡粴鍔ㄦ樉绀�**********************************/
  467. /*
  468. #define MOVING_ITME_NUM 3 //鏄剧ず涓夋潯椤圭洰
  469. #define MAX_ROW_BYTE (128+1+2) //鏈€澶氭樉绀�20涓�瓧鑺傦紝10涓�腑鏂�
  470. #define MAX_SHOW_BYTE 12 //鏈€澶氫竴娆℃€ф樉绀�10涓�瓧鑺�
  471. */
  472. void leftMoveStr(char *name, unsigned short len){
  473. char temp[3];
  474. unsigned char move=1;
  475. unsigned short i;
  476. if(name[0] > 0x80) move=2;
  477. for(i=0;i<move;i++) temp[i]=name[i];
  478. for(i=0;i<len-move;i++) name[i]=name[i+move];
  479. for(i=0;i<move;i++) name[i+len-move]=temp[i];
  480. }
  481. void getRealShow(char *des, char *src,int maxsize)
  482. {//??猫?脳??脿12+1??脳??煤??锚?
  483. int i,j,cpsize=maxsize-1;
  484. for(i=0;i<cpsize;i++){
  485. if(src[i]>0x80){
  486. if(i+2>cpsize){//瑁呬笉涓嬩簡锛屽仠姝�
  487. break;
  488. }
  489. des[i]=src[i];
  490. des[i+1]=src[i+1];
  491. i++;
  492. }else des[i]=src[i];
  493. }
  494. des[i]=0;
  495. }
  496. void guiLefItem(unsigned int x,int y,unsigned int frontColorID, unsigned int backColorID, FONT_MODEENUM fontMode,char *str){
  497. #define LIST_MAX_ROW_BYTE (128+1+2)
  498. #define LIST_MAX_SHOW_BYTE 26
  499. static char item[LIST_MAX_ROW_BYTE]={0};
  500. static unsigned short sum;
  501. unsigned short tsum;
  502. int len,i;
  503. char showMax[LIST_MAX_ROW_BYTE];
  504. static unsigned int cnt=0xffff;
  505. if(++cnt<500/APP_SUB_DIV_TIME) return;
  506. cnt=0;
  507. if(*str==0)return;
  508. snprintf(showMax, sizeof(showMax), "%s ",str);
  509. len=strlen(showMax);
  510. tsum=0;
  511. for(i=0;i<len;i++) tsum += showMax[i];
  512. if(len>LIST_MAX_SHOW_BYTE){
  513. if(sum != tsum){
  514. sum=tsum;
  515. memcpy(item, showMax, LIST_MAX_ROW_BYTE);
  516. }else leftMoveStr(item, strlen(item));
  517. getRealShow(showMax, item,LIST_MAX_SHOW_BYTE);
  518. guiFillRect(x,y ,GLCD_WIDTH-1,y+12,backColorID);
  519. guiShowStr(x,y, showMax, fontMode, REVERSED_NO,frontColorID, backColorID);
  520. }else {
  521. if(sum != tsum){
  522. sum=tsum;
  523. guiFillRect(x,y ,GLCD_WIDTH-1,y+12,backColorID);
  524. guiShowStr(x,y, showMax, fontMode, REVERSED_NO,frontColorID, backColorID);
  525. }
  526. }
  527. }
  528. //////////////////////////////////////测试接口///////////////////////////////////
  529. void guiTest(void){
  530. //return;
  531. //char testbuf[5]={0xB2,0xE2,0xCA,0xD4,0x00};
  532. //??ê?DD??
  533. guiDrawHLine(1, GLCD_WIDTH-2, 1, 1, guiGetForeColor());
  534. //??ê?áD??
  535. guiDrawVLine(3, GLCD_HEIGHT-2, 1, 1, guiGetForeColor());
  536. //??ê???D???D?
  537. guiDrawRect(3,3,3+10,3+10,1,guiGetForeColor());
  538. //??ê?êμD???D?
  539. guiFillRect(15, 3, 15+10, 3+10,guiGetForeColor());
  540. //??ê??yí·
  541. guiDrawArrow(50, 3,10, ARROW_UP, guiGetForeColor());
  542. guiDrawArrow(70, 3+10,10, ARROW_DOWN, guiGetForeColor());
  543. guiDrawArrow(90, 3+8,10, ARROW_LEFT, guiGetForeColor());
  544. guiDrawArrow(110, 3+8,10, ARROW_RIGHT, guiGetForeColor());
  545. //??ê?12X12×?·?′?
  546. guiShowStr(3, 30,"123测试45中,国AW", FONT_MODE_12X12, REVERSED_NO,guiGetForeColor(),guiGetBackColor());
  547. //??ê?16X16×?·?′?
  548. guiShowStr(3, 50,"123测试45你。好AW", FONT_MODE_16X16, REVERSED_NO,guiGetForeColor(),guiGetBackColor());
  549. //??ê?í???
  550. guiShowBmp(3, 80, "Palace2.bmp");
  551. //??ê?°′?ü
  552. guiShowButton(100, 80,"B12", FONT_MODE_12X12,guiGetForeColor(), guiGetBackColor());
  553. }