uiMenu.c 3.5 KB

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