uiMenu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "uiMenu.h"
  2. #include "app.h" //引入 getKeyValue
  3. #include "board.h"//引入 MKEY_VALUE_ESC
  4. #include "gui.h" //引入 FONT_MODEENUM
  5. #include "uiEntry.h" //引入 UI_STACKDEF
  6. #define UI_MENU_KEY_ESC MKEY_VALUE_ESC //返回按键
  7. #define UI_MENU_KEY_UP MKEY_VALUE_UP
  8. #define UI_MENU_KEY_DOWN MKEY_VALUE_DOWN
  9. static unsigned short uiMenuGetKey(void){
  10. return getKeyValue();
  11. }
  12. static UI_STACKDEF *uiMenuGetStack(void){
  13. return getStackStruct();
  14. }
  15. static void uiMenuShowItem(SUT_MENU *p, unsigned char handle, FONT_MODEENUM fontMode){
  16. unsigned char y,hand;
  17. hand=handle%UI_MENU_ROW;
  18. y=UI_MENU_TOPY+hand*(12+UI_MENU_SPACE);
  19. guiClearArea(0, y-1,UI_MENU_BAR_LEN,18,guiGetBackColor());
  20. guiShowStr(0,y,p->item[handle],fontMode, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  21. }
  22. static void uiMenuShowBar(SUT_MENU *p, REV_ENUM rev, FONT_MODEENUM fontMode){
  23. unsigned char x,y,handle;
  24. char *str;
  25. short len;
  26. unsigned int color;
  27. x=0;
  28. handle=p->handle%UI_MENU_ROW;
  29. y=UI_MENU_TOPY+handle*(12+UI_MENU_SPACE);
  30. str=(char *)p->item[p->handle];
  31. len=guiGetStrXLen(str, fontMode);
  32. if(REVERSED_NO==rev) color=COLOR_STATUS_BAR;
  33. else color=guiGetBackColor();
  34. guiFillRect(x, y-2, x+UI_MENU_BAR_LEN, y+14, color);
  35. if(REVERSED_NO==rev) guiShowStr(x,y,str, fontMode, rev,guiGetBackColor(), COLOR_STATUS_BAR);
  36. else guiShowStr(x,y,str, fontMode, rev,guiGetBackColor(), COLOR_BLACK);
  37. }
  38. static void uiMenuShow(SUT_MENU *p, FONT_MODEENUM fontMode){
  39. unsigned char i,j;
  40. unsigned short x,y;
  41. j=p->page*UI_MENU_ROW;
  42. for(i=j;i<j+UI_MENU_ROW;i++){
  43. if(i>=p->itemnum){
  44. y=UI_MENU_TOPY+(i%UI_MENU_ROW)*(12+UI_MENU_SPACE);
  45. guiClearArea(0, y-1, UI_MENU_BAR_LEN, 12+UI_MENU_SPACE,guiGetBackColor());
  46. }else uiMenuShowItem(p,i, fontMode);
  47. }
  48. uiMenuShowBar(p,REVERSED_NO,fontMode);
  49. //show arrow
  50. x=UI_MENU_BAR_LEN+(GLCD_WIDTH-UI_MENU_BAR_LEN)/2-2;
  51. if(p->page>0) guiDrawArrow(GLCD_WIDTH-5, UI_MENU_TOPY, 8, ARROW_UP, COLOR_STATUS_BAR);
  52. else guiClearArea(x, UI_MENU_TOPY, 18,8+10,guiGetBackColor());
  53. y=UI_MENU_TOPY+UI_MENU_ROW*(12+UI_MENU_SPACE);
  54. if(p->page<(p->pagenum-1)) guiDrawArrow(GLCD_WIDTH-5, y-2,8, ARROW_DOWN, COLOR_STATUS_BAR);
  55. else guiClearArea(x,y-8-2,19,8,guiGetBackColor());
  56. }
  57. void uiMenuInit(SUT_MENU *p, const char **item, FONT_MODEENUM fontMode,bool status){
  58. unsigned char i,ch,index;
  59. UI_STACKDEF *uiPtr=uiMenuGetStack();
  60. p->item=item;
  61. i=0;
  62. for(;;){
  63. ch=p->item[i][0];
  64. if(ch==0) break;
  65. i++;
  66. }
  67. i--;
  68. p->itemnum = i+1;
  69. p->pagenum=i/UI_MENU_ROW;
  70. if(p->pagenum%UI_MENU_ROW) p->pagenum ++;
  71. if(UI_MENU_KEY_ESC==uiMenuGetKey() || uiPtr->ok_back){
  72. if(status==true){
  73. index=uiPullStack();
  74. if(index>9){
  75. p->page=2;
  76. p->handle=index;
  77. }else if(index>4){
  78. p->page=1;
  79. p->handle=index;
  80. }else{
  81. p->page=0;
  82. p->handle=index;
  83. }
  84. uiPtr->ok_back=0;
  85. }else{
  86. p->page=0;
  87. p->handle=0;
  88. }
  89. }else{
  90. p->page=0;
  91. p->handle=0;
  92. }
  93. uiMenuShow(p,fontMode);
  94. }
  95. unsigned short uiMenuResponse(SUT_MENU *p){
  96. unsigned char tmp;
  97. unsigned short key=uiMenuGetKey();
  98. switch(key){
  99. case UI_MENU_KEY_UP:
  100. uiMenuShowBar(p, REVERSED_YES, FONT_MODE_12X12);
  101. if(p->handle==0) p->handle=p->itemnum-1;
  102. else p->handle --;
  103. tmp=p->page;
  104. p->page=p->handle/UI_MENU_ROW;
  105. if(tmp != p->page) uiMenuShow(p, FONT_MODE_12X12);
  106. else uiMenuShowBar(p, REVERSED_NO, FONT_MODE_12X12);
  107. break;
  108. case UI_MENU_KEY_DOWN:
  109. uiMenuShowBar(p, REVERSED_YES, FONT_MODE_12X12);
  110. p->handle ++;
  111. if(p->handle>=p->itemnum) p->handle=0;
  112. tmp=p->page;
  113. p->page=p->handle/UI_MENU_ROW;
  114. if(tmp != p->page) uiMenuShow(p, FONT_MODE_12X12);
  115. else uiMenuShowBar(p, REVERSED_NO, FONT_MODE_12X12);
  116. break;
  117. default:
  118. break;
  119. }
  120. return key;
  121. }