gui.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #include "gui.h"
  2. #include "lcdDrv.h"
  3. #include "lsapi_fs.h"
  4. #include "log.h"
  5. #include "fonts.h"
  6. #include "board.h"
  7. #include "uiEntry.h"
  8. #include "app.h"
  9. #include "math.h"
  10. #if 0
  11. #define COLOR_BACKGROUND COLOR_BLACK
  12. #define COLOR_FOREGROUND COLOR_WHITE
  13. #else
  14. #define COLOR_BACKGROUND COLOR_WHITE
  15. #define COLOR_FOREGROUND COLOR_BLACK
  16. #endif
  17. unsigned int g_backColor;
  18. unsigned int g_foreColor;
  19. unsigned int guiGetBackColor(void){return g_backColor;}
  20. unsigned int guiGetForeColor(void){return g_foreColor;}
  21. static unsigned short RGB888_2_RGB565(unsigned int rgb888){
  22. unsigned short r,g,b,rgb565;
  23. b=(rgb888 >> (16+3))&0x1F;
  24. g=(rgb888 >> (8+2))&0x3f;
  25. r=(rgb888 >> (0+3))&0x1f;
  26. rgb565=((r<<11) + (g<<5) + (b<<0));
  27. return rgb565;
  28. }
  29. static void guiDrawDot(unsigned short colorData){
  30. LCD_DataWrite_ST7735(colorData >> 8);
  31. LCD_DataWrite_ST7735(colorData & 0xff);
  32. }
  33. static void guiBlockSet(unsigned short sx, unsigned short ex, unsigned short sy, unsigned short ey){
  34. LCD_CtrlWrite_ST7735(0x2a);
  35. guiDrawDot(sx);
  36. guiDrawDot(sy);
  37. LCD_CtrlWrite_ST7735(0x2B);
  38. guiDrawDot(ex);
  39. guiDrawDot(ey);
  40. LCD_CtrlWrite_ST7735(0x2C);
  41. }
  42. #define KEEP_HZK_OPENED //ê?·?±£3????t3£?a
  43. #define HZK_FENGQU 72*3*1024
  44. #define HZK_FENGQU_02 72*3*1024*2
  45. #define HZK32_FENQU_BLOCK 262144
  46. static int guiGetHzk(unsigned char hiByte, unsigned char loByte, unsigned char *pHzk, FONT_MODEENUM fontMode){
  47. unsigned char Q,W;
  48. unsigned int offset;
  49. const char hzk_16x16[]="HZK16";
  50. const char hzk_24x24_1[]="/ext/prepack/HZK24_1";
  51. const char hzk_24x24_2[]="/ext/prepack/HZK24_2";
  52. const char hzk_24x24_3[]="/ext/prepack/HZK24_3";
  53. char *hzk_ptr=NULL;
  54. static int fd_12=NULL,fd_16=NULL,fd_24_1=NULL,fd_24_2=NULL,fd_24_3=NULL;
  55. static int fd_32_1=NULL,fd_32_2=NULL,fd_32_3=NULL,fd_32_4=NULL;
  56. int *fd_ptr=NULL;
  57. int fsize;
  58. char temp=0;
  59. static char buf[30]={0};
  60. if(hiByte<0xa0 || loByte<0xa0) return -1;
  61. Q=hiByte-0xa0;
  62. W=loByte-0xa0;
  63. if(FONT_MODE_16X16==fontMode)fsize = 32;
  64. else if(FONT_MODE_24X24==fontMode)fsize=72;
  65. else if(FONT_MODE_32X32==fontMode)fsize=128;
  66. offset=(94 * (Q-1) + (W-1))* fsize;
  67. if(FONT_MODE_16X16==fontMode){
  68. hzk_ptr=(char *)hzk_16x16;
  69. fd_ptr=&fd_16;
  70. }else if(FONT_MODE_24X24==fontMode){
  71. if(offset<=HZK_FENGQU){
  72. hzk_ptr=(char *)hzk_24x24_1;
  73. fd_ptr=&fd_24_1;
  74. }else if(offset>HZK_FENGQU&&offset<HZK_FENGQU_02){
  75. offset-=HZK_FENGQU;
  76. hzk_ptr=(char *)hzk_24x24_2;
  77. fd_ptr=&fd_24_2;
  78. }else {
  79. offset-=HZK_FENGQU_02;
  80. hzk_ptr=(char *)hzk_24x24_3;
  81. fd_ptr=&fd_24_3;
  82. }
  83. }else if(FONT_MODE_32X32==fontMode){
  84. temp=offset/HZK32_FENQU_BLOCK;
  85. snprintf(buf, sizeof(buf),"/ext/prepack/HZK32_%d",temp+1);
  86. hzk_ptr=buf;
  87. //MSG_INFO(1,"%s",buf);
  88. offset-=HZK32_FENQU_BLOCK*temp;
  89. switch(temp){
  90. case 0 :
  91. fd_ptr=&fd_32_1;
  92. break;
  93. case 1 :
  94. fd_ptr=&fd_32_2;
  95. break;
  96. case 2 :
  97. fd_ptr=&fd_32_3;
  98. break;
  99. case 3 :
  100. fd_ptr=&fd_32_4;
  101. break;
  102. default:
  103. fd_ptr=&fd_32_4;
  104. break;
  105. }
  106. }else return -2;
  107. if(*fd_ptr==NULL){
  108. int fd=LSAPI_FS_Open(hzk_ptr, LSAPI_FS_O_RDONLY, 0);
  109. if(fd==NULL){
  110. MSG_ERR(1, "%s open failed", hzk_ptr);
  111. return -3;
  112. }
  113. *fd_ptr=fd;
  114. }
  115. LSAPI_FS_Seek(*fd_ptr, offset, LSAPI_FS_SEEK_SET);
  116. offset=LSAPI_FS_Read(*fd_ptr, pHzk,fsize);
  117. #ifndef KEEP_HZK_OPENED
  118. LSAPI_FS_Close(*fd_ptr);
  119. *fd_ptr=NULL;
  120. #endif
  121. return offset;
  122. }
  123. static int fd_12_ext=NULL,fd_16_ext=NULL;
  124. static int extFileSize_1212=-1;
  125. static int extFileSize_1616=-1;
  126. bool fontExtLock=false;
  127. void extFontFileCtl(unsigned char fontType,bool ctl){
  128. int *fd_ext;
  129. if(ctl==true) fontExtLock=false;
  130. else{
  131. fontExtLock=true;
  132. if(fontType==12) fd_ext=&fd_12_ext;
  133. else if(fontType==16) fd_ext=&fd_16_ext;
  134. else{
  135. fontExtLock=false;
  136. return;
  137. }
  138. if(*fd_ext != NULL){
  139. LSAPI_FS_Close(*fd_ext);
  140. *fd_ext=NULL;
  141. }
  142. }
  143. }
  144. static int guiGetExtHzk(unsigned char hiByte, unsigned char loByte, unsigned char *pHzk, FONT_MODEENUM fontMode){
  145. unsigned char Q,W;
  146. int offset,i;
  147. char *hzk_ptr=NULL;
  148. int *fd_ptr=NULL;
  149. int *fsize,rsize;
  150. LSAPI_FS_Stat_info_t pBuf;
  151. unsigned char tmp[2+32];
  152. if(fontExtLock==true) return -1;
  153. if(FONT_MODE_16X16==fontMode){
  154. rsize = 24+2;
  155. hzk_ptr=HZK_12_NEW_FILE;
  156. fd_ptr=&fd_12_ext;
  157. fsize=&extFileSize_1212;
  158. }else if(FONT_MODE_16X16==fontMode){
  159. rsize = 32+2;
  160. hzk_ptr=HZK_16_NEW_FILE;
  161. fd_ptr=&fd_16_ext;
  162. fsize=&extFileSize_1616;
  163. }else return -2;
  164. //′ò?a???t
  165. if(*fd_ptr==NULL){
  166. int fd=LSAPI_FS_Open(hzk_ptr, LSAPI_FS_O_RDONLY, 0);
  167. if(fd==NULL){
  168. MSG_ERR(1, "%s open failed", hzk_ptr);
  169. return -3;
  170. }
  171. *fd_ptr=fd;
  172. }
  173. //get file size
  174. if(*fsize<1){
  175. memset(&pBuf,0,sizeof(pBuf));
  176. LSAPI_FS_Fstat(*fd_ptr,&pBuf);
  177. *fsize=pBuf.st_size;
  178. if(*fsize<0){
  179. offset=-4;
  180. goto F_END;
  181. }
  182. }
  183. LSAPI_FS_Seek(*fd_ptr, 0, LSAPI_FS_SEEK_SET);
  184. //check size
  185. if(1!=LSAPI_FS_Read(*fd_ptr, tmp,1)){
  186. offset=-5;
  187. goto F_END;
  188. }
  189. if(FONT_MODE_16X16==fontMode && tmp[0]!=12){
  190. offset=-6;
  191. goto F_END;
  192. }else if(FONT_MODE_16X16==fontMode && tmp[0]!=16){
  193. offset=-7;
  194. goto F_END;
  195. }
  196. for(;;){
  197. offset=LSAPI_FS_Read(*fd_ptr, tmp,rsize);
  198. if(offset != rsize){
  199. offset=-8;
  200. goto F_END;
  201. }
  202. if(tmp[0]==hiByte && tmp[1]==loByte){
  203. offset=rsize-2;
  204. memcpy(pHzk, tmp+2, offset);
  205. goto F_END;
  206. }
  207. }
  208. offset=-9;
  209. F_END:
  210. #ifndef KEEP_HZK_OPENED
  211. LSAPI_FS_Close(*fd_ptr);
  212. *fd_ptr=NULL;
  213. #endif
  214. return offset;
  215. }
  216. static void guiShowChars(unsigned short x,unsigned short y,unsigned char hiByte, unsigned char loByte,
  217. FONT_MODEENUM fontMode,
  218. unsigned int frontColorID,//????
  219. unsigned int backColorID,//????
  220. REV_ENUM rev){//??
  221. unsigned short i,j,k,m,n,fcolor,bcolor;
  222. unsigned short width,height;
  223. unsigned char ByteWidth,data;
  224. const unsigned char *l_pucFont,*l_pucLetter;
  225. unsigned char *p;
  226. unsigned char sucHzk16[32];
  227. unsigned char sucHzk24[72];
  228. unsigned char sucHzk32[128];
  229. int ret;
  230. k = 0;
  231. if(hiByte==0){//english
  232. if(fontMode==FONT_MODE_16X16){//8* 12
  233. width=8;
  234. height = 16;
  235. ByteWidth = 1;
  236. l_pucFont = g_apucFonts16;
  237. l_pucLetter = g_apucLetter16;
  238. }else if(fontMode==FONT_MODE_24X24){ //8*16
  239. width=16;//8 hyl
  240. height = 24;
  241. ByteWidth = 2;
  242. l_pucFont = g_apucFonts24;
  243. l_pucLetter = g_apucLetter24;
  244. }else if(fontMode==FONT_MODE_32X32){
  245. width=16;//8 hyl
  246. height = 32;
  247. ByteWidth = 2;
  248. l_pucFont = g_apucFonts32;
  249. l_pucLetter = g_apucLetter32;
  250. }
  251. while(*l_pucLetter){
  252. if(loByte == *l_pucLetter)break;
  253. l_pucLetter ++;
  254. k ++;
  255. }
  256. //2¨|?¨°|ì??á??a|ì??a¨o?????
  257. l_pucFont += k * ByteWidth * height;
  258. }else{//chinese
  259. if(fontMode==FONT_MODE_16X16){//12*16
  260. width=16;
  261. height = 16;
  262. ByteWidth = 2;
  263. l_pucFont = sucHzk16;
  264. l_pucLetter = 0;
  265. k=0;
  266. ret=guiGetHzk(hiByte,loByte,sucHzk16,fontMode);
  267. if(sizeof(sucHzk16)!=ret){//??¨?sFlash|ì?HZK16???t?D?¨¢¨¨??á??a¨oy?Y
  268. //?¨°2?|ì??á??a?ê???¨o?"?¨2"
  269. l_pucFont=g_apucCLetter16;
  270. MSG_ERR(1, "guiGetHzk16Err:%02x,%02x,%d",hiByte,loByte,ret);
  271. }
  272. }else if(fontMode==FONT_MODE_32X32){
  273. width=32;
  274. height = 32;
  275. ByteWidth = 4;
  276. l_pucFont = sucHzk32;
  277. l_pucLetter = 0;
  278. k=0;
  279. ret=guiGetHzk(hiByte,loByte,sucHzk32,fontMode);
  280. if(sizeof(sucHzk32)!=ret){//??¨?sFlash|ì?HZK16???t?D?¨¢¨¨??á??a¨oy?Y
  281. //?¨°2?|ì??á??a?ê???¨o?"?¨2"
  282. l_pucFont=g_apucCLetter16;
  283. MSG_ERR(1, "guiGetHzk32Err:%02x,%02x,%d",hiByte,loByte,ret);
  284. }
  285. }else if(fontMode==FONT_MODE_24X24){
  286. width=24;
  287. height = 24;
  288. ByteWidth = 3;
  289. l_pucFont = sucHzk24;
  290. l_pucLetter = 0;
  291. k=0;
  292. ret=guiGetHzk(hiByte,loByte,sucHzk24,fontMode);
  293. if(sizeof(sucHzk24)!=ret){//??¨?sFlash|ì?HZK16???t?D?¨¢¨¨??á??a¨oy?Y
  294. //?¨°2?|ì??á??a?ê???¨o?"?¨2"
  295. l_pucFont=g_apucCLetter16;
  296. MSG_ERR(1, "guiGetHzk24Err:%02x,%02x,%d",hiByte,loByte,ret);
  297. }
  298. }
  299. }
  300. //====================?¨′??|¨¤¨a|ì??¨?¨oy?Y==========
  301. if(y+height>GLCD_HEIGHT)return;
  302. if(x+width>GLCD_WIDTH)return;
  303. guiBlockSet(x,y,x+width-1,y+height-1);//
  304. fcolor=RGB888_2_RGB565(frontColorID);
  305. bcolor=RGB888_2_RGB565(backColorID);
  306. //¨°?????à?¨???|ì??¨???é|ì?LCD?ê?2?¨?????????ê¨??¨?¨22a¨o??ê??á?騰a|ì??¨??2?¨°a|ì??¨??PaintBufToLcd?ê??¤??¨°¨°2??é?¨¢¨¢?
  307. //?¨′?Y?á???ê?¨2??????D?-|ì?
  308. for(j=0;j<height;j++){
  309. m=y+j;
  310. for(i=0;i<ByteWidth;i++){
  311. n=x+i*8;
  312. data=*l_pucFont++;
  313. for(k=0;k<8;k++){
  314. if(data & (0x80>>k)){//??,??frontColorID
  315. if(REVERSED_NO==rev) guiDrawDot(fcolor);
  316. else guiDrawDot(bcolor);
  317. }else{//??,??backColorID
  318. if(REVERSED_NO==rev) guiDrawDot(bcolor);
  319. else guiDrawDot(fcolor);
  320. }
  321. }
  322. }
  323. }
  324. }
  325. short guiGetStrXLen(char *str, FONT_MODEENUM fontMode){
  326. unsigned char ch;
  327. unsigned short len=0;
  328. unsigned char bsize;
  329. bsize=16;
  330. while ((ch=*str++)){
  331. if(ch=='M')len+=16;
  332. else if(ch>='A'&&ch<='Z')len+=16;
  333. else if(ch>='a'&&ch<='z')len+=16;
  334. else if(ch>='0'&&ch<='9')len+=16;
  335. else if(ch>=0x20&& ch<=0x60)len+=16; //¨??¨oa?á??¤?
  336. else len+=bsize;
  337. }
  338. return len;
  339. }
  340. //ò????ó?ú??ía?a·?
  341. void guiShowStr(unsigned short x, unsigned short y,const char *string, FONT_MODEENUM fontMode,
  342. REV_ENUM rev, //????
  343. unsigned int frontColorID,//???
  344. unsigned int backColorID){//???
  345. unsigned char width1,width2,heigh;
  346. unsigned char *p;
  347. unsigned short i;
  348. if(fontMode==FONT_MODE_72X72){
  349. fontMode=FONT_MODE_24X24;
  350. }else{
  351. fontMode=FONT_MODE_32X32;
  352. }
  353. if(fontMode == FONT_MODE_16X16){
  354. width1 = 16;
  355. width2 = 1;
  356. heigh=16;
  357. }else if(fontMode == FONT_MODE_24X24){
  358. width1 = 24;
  359. width2 = 2;//1
  360. heigh=24;
  361. } else if(fontMode == FONT_MODE_32X32){
  362. width1 = 32;
  363. width2 = 2;
  364. heigh=32;
  365. }else return;
  366. p = (unsigned char *)string;
  367. i = 0;
  368. while(*p){
  369. if (*p > 0x80){//chinese letter
  370. guiShowChars(x+i,y,*p, *(p+1),fontMode,frontColorID,backColorID,rev);
  371. i += width1 ;
  372. p += 2;
  373. }else{//english letter
  374. guiShowChars(x + i,y,0,*p,fontMode,frontColorID,backColorID,rev);
  375. if(fontMode==FONT_MODE_16X16) i += width2 * 8;
  376. //else if(fontMode==FONT_MODE_32X32) i+=20;
  377. else i += width2 * 8;
  378. p ++;
  379. }
  380. }
  381. }
  382. void guiShowButton(unsigned short x, unsigned short y,const char *str, FONT_MODEENUM fontMode,unsigned int buttonColorID, unsigned int strColorID){
  383. int heigh,len;
  384. if(FONT_MODE_16X16==fontMode) heigh=12+4;
  385. else if(FONT_MODE_24X24==fontMode) heigh=16+4;
  386. else return;
  387. len=guiGetStrXLen((char *)str, fontMode);
  388. guiFillRect(x,y,x+len+8,y+heigh,buttonColorID);
  389. guiShowStr(x+4, y+1, str, fontMode,REVERSED_NO,strColorID,buttonColorID);
  390. }
  391. void guiFillRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2,unsigned int colorData){
  392. unsigned short x=x2,y=y2,w,h,i,m,k,j,data;
  393. if(x1>x2 || y1>y2) return;
  394. if(x1>=GLCD_WIDTH || y1>=GLCD_HEIGHT) return;
  395. if(x>GLCD_WIDTH) x=GLCD_WIDTH;
  396. if(y>GLCD_HEIGHT) y=GLCD_HEIGHT;
  397. w=x-x1+1;
  398. h=y-y1+1;
  399. data=RGB888_2_RGB565(colorData);
  400. guiBlockSet(x1,y1,x,y);
  401. for(i=0;i<h;i++){
  402. m=y1+i;
  403. for(j=0;j<w;j++){
  404. k=x1+j;
  405. guiDrawDot(data);
  406. }
  407. }
  408. }
  409. void guiClearRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned int colorData){
  410. guiFillRect(x1,y1,x2,y2,colorData);
  411. }
  412. //??????
  413. void guiDrawHLine(unsigned short x1, unsigned short x2, unsigned short y, unsigned short ysize, unsigned int colorID){
  414. if(ysize==0) return;
  415. if(x2<x1) return;
  416. guiFillRect(x1,y,x2,y+ysize-1,colorID);
  417. }
  418. //′1?±??
  419. void guiDrawVLine(unsigned short y1, unsigned short y2, unsigned short x, unsigned short xsize, unsigned int colorID){
  420. if(xsize==0) return;
  421. if(y2<y1) return;
  422. guiFillRect(x,y1,x+xsize-1,y2,colorID);
  423. }
  424. void guiDrawRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2,unsigned char width, unsigned int colorID){
  425. if(x1>x2||y1>y2) return;
  426. guiDrawHLine(x1,x2,y1,width,colorID);
  427. guiDrawHLine(x1,x2,y2,width,colorID);
  428. guiDrawVLine(y1,y2,x1,width,colorID);
  429. guiDrawVLine(y1,y2+width-1,x2,width,colorID);
  430. }
  431. //óé·??ò?aμ?(x,y)?aê??-
  432. void guiDrawArrow(unsigned short x, unsigned short y,unsigned short len, ARROW_ENUM direction, unsigned int colorID){
  433. unsigned short i;
  434. switch(direction){
  435. case ARROW_LEFT:
  436. for(i=0;i<len;i++) guiDrawRect(x+i,y-i,x+i,y+i,1,colorID);
  437. break;
  438. case ARROW_RIGHT:
  439. for(i=0;i<len;i++) guiDrawRect(x-i,y-i,x-i,y+i,1,colorID);
  440. break;
  441. case ARROW_UP:
  442. for(i=0;i<len;i++) guiDrawRect(x-i,y+i,x+i,y+i,1,colorID);
  443. break;
  444. case ARROW_DOWN:
  445. for(i=0;i<len;i++) guiDrawRect(x-i,y-i,x+i,y-i,1,colorID);
  446. break;
  447. }
  448. }
  449. static void guiFillBmpBuf(unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned char *bmpBuf){
  450. int i,j,k,t;
  451. unsigned short RGB565,r,g,b;
  452. unsigned char R,G,B;
  453. for(j=0;j<height;j++){
  454. t=y+j;
  455. k=j*width;
  456. for(i=0;i<width;i++){
  457. R=bmpBuf[3*i];
  458. G=bmpBuf[3*i+1];
  459. B=bmpBuf[3*i+2];
  460. r=R>>3;
  461. g=G>>2;
  462. b=B>>3;
  463. RGB565=((r<<11)+(g<<5)+(b<<0));
  464. guiDrawDot(RGB565);
  465. }
  466. }
  467. }
  468. void guiShowBmp(unsigned short x, unsigned short y, char *bmp){
  469. int fd,l,w,i;
  470. unsigned short type;
  471. unsigned int width,height,bfOffBits;
  472. unsigned char tbuf[GLCD_WIDTH*4];
  473. fd=LSAPI_FS_Open(bmp, LSAPI_FS_O_RDONLY,0);
  474. if(fd<0){
  475. MSG_ERR(1, "%s open failed", bmp);
  476. return;
  477. }
  478. //?áè????tààDí
  479. LSAPI_FS_Seek(fd, 0x1c, LSAPI_FS_SEEK_SET);
  480. LSAPI_FS_Read(fd, (unsigned char *)&type, 2);
  481. if(type != 0x0018){
  482. MSG_ERR(1, "%s is not 24bits bmp",bmp);
  483. LSAPI_FS_Close(fd);
  484. return;
  485. }
  486. //?áè?í????í?è
  487. LSAPI_FS_Seek(fd, 0x12, LSAPI_FS_SEEK_SET);
  488. LSAPI_FS_Read(fd, (unsigned char *)&width, 4);
  489. //?áè?í??????è
  490. LSAPI_FS_Seek(fd, 0x16, LSAPI_FS_SEEK_SET);
  491. LSAPI_FS_Read(fd, (unsigned char *)&height, 4);
  492. //?D??3?′?
  493. if(width>GLCD_WIDTH || height>GLCD_HEIGHT){
  494. MSG_ERR(1, "%s size overflow",bmp);
  495. LSAPI_FS_Close(fd);
  496. return;
  497. }
  498. //?á3?êy?Y?eê?μ??·
  499. LSAPI_FS_Seek(fd, 0x0a, LSAPI_FS_SEEK_SET);
  500. LSAPI_FS_Read(fd, (unsigned char *)&bfOffBits, 4);
  501. l=width%4;
  502. w=width*3+l;
  503. l=height-1;
  504. guiBlockSet(x,y,x+width-1,y+height-1);//-1
  505. for(i=0;i<height;i++){
  506. LSAPI_FS_Seek(fd, bfOffBits+l*w, LSAPI_FS_SEEK_SET);
  507. LSAPI_FS_Read(fd, tbuf, w);
  508. guiFillBmpBuf(x,y+i,width,1,tbuf);
  509. l--;
  510. }
  511. LSAPI_FS_Close(fd);
  512. }
  513. /*?ó?D??ê?*/
  514. void guiShowCaption(unsigned short xType, const char *str, unsigned short y, unsigned int frontColorID, unsigned int backColorID, FONT_MODEENUM fontMode){
  515. int len,sy;
  516. unsigned short x;
  517. len=guiGetStrXLen((char *)str,fontMode);
  518. if(xType==0) x=(GLCD_WIDTH-len)/2;
  519. else x=xType;
  520. guiShowStr(x, y, str, fontMode, REVERSED_NO, frontColorID, backColorID);
  521. }
  522. void guiShowLefCaption(unsigned short xType, const char *str, unsigned short y, unsigned int frontColorID, unsigned int backColorID, FONT_MODEENUM fontMode){
  523. int len,sy;
  524. unsigned short x;
  525. if(strlen(str)>15){
  526. guiLefItem(0,UI_GROUP_SHOW_Y,frontColorID,backColorID,fontMode,str,1);
  527. }else{
  528. len=guiGetStrXLen((char *)str,fontMode);
  529. if(xType==0) x=(GLCD_WIDTH-len)/2;
  530. else x=xType;
  531. guiShowStr(x, y, str, fontMode, REVERSED_NO, frontColorID, backColorID);
  532. }
  533. }
  534. void guiClearArea(unsigned short x, unsigned short y, unsigned short width, unsigned short height,unsigned int colorID){
  535. guiFillRect(x,y,x+width,y+height,colorID);
  536. }
  537. void guiInit(void){
  538. g_backColor=COLOR_FOREGROUND;
  539. g_foreColor=COLOR_BACKGROUND;
  540. guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());
  541. if(sutApp.UserInfo.tnet==5) guiShowBmp(0,0,"/ext/prepack/welcome5.bmp");//开机图片
  542. else guiShowBmp(0,0,"/ext/prepack/welcome.bmp");//开机图片
  543. //LSAPI_OSI_ThreadSleep(2000);
  544. lcdBackLightApi(1);//清屏后打开,否则会看到关机前的画面
  545. }
  546. void guiClearAll(unsigned int colorID){//只清第二,三区
  547. guiFillRect(0, UI_STATUS_ITEM_Y, GLCD_WIDTH-1, UI_CONTENT_SHOW_Y-1, guiGetBackColor());//清除第二区
  548. guiFillRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_LOCATION_SHOW_Y-1,colorID);
  549. }
  550. void guiShowMessageBox(char *msg){
  551. char buf[70];
  552. short len,x,y;
  553. y=GLCD_HEIGHT/2;
  554. guiClearRect(0,y-20,GLCD_WIDTH-1,y+BAR_HIGHT,guiGetBackColor()); //COLOR_RED
  555. guiDrawRect(2,y-18,GLCD_WIDTH-3,y+BAR_HIGHT,1,COLOR_SEL_BAR);
  556. StrIntercept(buf,msg,18);
  557. len=guiGetStrXLen(buf,FONT_MODE_16X16);
  558. x=(GLCD_WIDTH-len)/2;
  559. guiShowStr(x,y-8,buf,FONT_MODE_16X16,REVERSED_NO,COLOR_RED,guiGetBackColor());
  560. }
  561. void guiShowLocationPoint(signed short x1,signed short y1,signed short zerox2,signed short zeroy2,short angle, unsigned int colorID){
  562. signed short x=0,y=0;
  563. double r=0;
  564. static double tempangle=0;
  565. tempangle=rad(30);
  566. MSG_INFO(1,"tempangle===%lf",tempangle);
  567. #if 0
  568. /*
  569. //r=zeroy2-y1;//75
  570. r=75;
  571. x=r*cos(tempangle)+zerox2;
  572. y=r*sin(tempangle)+zeroy2;
  573. */
  574. x=(x1-zerox2)*cos(tempangle)-(y1-zeroy2)*sin(tempangle)+zerox2;
  575. y=(y1-zeroy2)*cos(tempangle)+(x1-zerox2)*sin(tempangle)+zeroy2;
  576. //120+ 75
  577. //157 +
  578. MSG_INFO(1,"X==%d,Y===%d,zerox2==%d,zeroy2==%d,r===%lf",x,y,zerox2,zeroy2,sin(tempangle));
  579. guiFillRect(x,y,x+5,y+5,colorID);
  580. #endif
  581. }
  582. //////////////////////////////////////测试接口///////////////////////////////////
  583. void guiTest(void){
  584. //return;
  585. //char testbuf[5]={0xB2,0xE2,0xCA,0xD4,0x00};
  586. //??ê?DD??
  587. guiDrawHLine(1, GLCD_WIDTH-2, 1, 1, guiGetForeColor());
  588. //??ê?áD??
  589. guiDrawVLine(3, GLCD_HEIGHT-2, 1, 1, guiGetForeColor());
  590. //??ê???D???D?
  591. guiDrawRect(3,3,3+10,3+10,1,guiGetForeColor());
  592. //??ê?êμD???D?
  593. guiFillRect(15, 3, 15+10, 3+10,guiGetForeColor());
  594. //??ê??yí·
  595. guiDrawArrow(50, 3,10, ARROW_UP, guiGetForeColor());
  596. guiDrawArrow(70, 3+10,10, ARROW_DOWN, guiGetForeColor());
  597. guiDrawArrow(90, 3+8,10, ARROW_LEFT, guiGetForeColor());
  598. guiDrawArrow(110, 3+8,10, ARROW_RIGHT, guiGetForeColor());
  599. //??ê?12X12×?·?′?
  600. guiShowStr(3, 30,"123测试45中,国AW", FONT_MODE_16X16, REVERSED_NO,guiGetForeColor(),guiGetBackColor());
  601. //??ê?16X16×?·?′?
  602. guiShowStr(3, 50,"123测试45你。好AW", FONT_MODE_16X16, REVERSED_NO,guiGetForeColor(),guiGetBackColor());
  603. //??ê?í???
  604. guiShowBmp(3, 80, "Palace2.bmp");
  605. //??ê?°′?ü
  606. guiShowButton(100, 80,"B12", FONT_MODE_16X16,guiGetForeColor(), guiGetBackColor());
  607. }