uiMenu.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "uiMenu.h"
  2. #include "app.h" //引入 getKeyValue
  3. #include "ohboard.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*(12+UI_MENU_SPACE);
  20. guiClearArea(0, y-1,UI_MENU_BAR_LEN,18,guiGetBackColor());
  21. guiShowStr(0,y,p->item[handle],fontMode, REVERSED_NO, COLOR_BLACK, 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*(12+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-2, x+UI_MENU_BAR_LEN, y+14, color);
  36. if(REVERSED_NO==rev) guiShowStr(x,y,str, fontMode, rev,guiGetBackColor(), COLOR_STATUS_BAR);
  37. else guiShowStr(x,y,str, fontMode, rev,guiGetBackColor(), COLOR_BLACK);
  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)*(12+UI_MENU_SPACE);
  46. guiClearArea(0, y-1, UI_MENU_BAR_LEN, 12+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*(12+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(UI_MENU_KEY_ESC==uiMenuGetKey() || uiPtr->ok_back){
  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. uiMenuShow(p,fontMode);
  90. }
  91. unsigned short uiMenuResponse(SUT_MENU *p){
  92. unsigned char tmp;
  93. unsigned short key=uiMenuGetKey();
  94. switch(key){
  95. case UI_MENU_KEY_UP:
  96. uiMenuShowBar(p, REVERSED_YES, FONT_MODE_12X12);
  97. if(p->handle==0) p->handle=p->itemnum-1;
  98. else p->handle --;
  99. tmp=p->page;
  100. p->page=p->handle/UI_MENU_ROW;
  101. if(tmp != p->page) uiMenuShow(p, FONT_MODE_12X12);
  102. else uiMenuShowBar(p, REVERSED_NO, FONT_MODE_12X12);
  103. break;
  104. case UI_MENU_KEY_DOWN:
  105. uiMenuShowBar(p, REVERSED_YES, FONT_MODE_12X12);
  106. p->handle ++;
  107. if(p->handle>=p->itemnum) p->handle=0;
  108. tmp=p->page;
  109. p->page=p->handle/UI_MENU_ROW;
  110. if(tmp != p->page) uiMenuShow(p, FONT_MODE_12X12);
  111. else uiMenuShowBar(p, REVERSED_NO, FONT_MODE_12X12);
  112. break;
  113. default:
  114. break;
  115. }
  116. return key;
  117. }