123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #include "uiMenu.h"
- #include "app.h" //引入 getKeyValue
- #include "board.h"//引入 MKEY_VALUE_ESC
- #include "gui.h" //引入 FONT_MODEENUM
- #include "uiEntry.h" //引入 UI_STACKDEF
- #define UI_MENU_KEY_ESC MKEY_VALUE_ESC //返回按键
- #define UI_MENU_KEY_UP MKEY_VALUE_UP
- #define UI_MENU_KEY_DOWN MKEY_VALUE_DOWN
- static unsigned short uiMenuGetKey(void){
- return getKeyValue();
- }
- static UI_STACKDEF *uiMenuGetStack(void){
- return getStackStruct();
- }
- static void uiMenuShowItem(SUT_MENU *p, unsigned char handle, FONT_MODEENUM fontMode){
- unsigned char y,hand;
- hand=handle%UI_MENU_ROW;
- y=UI_MENU_TOPY+hand*(12+UI_MENU_SPACE);
- guiClearArea(0, y-1,UI_MENU_BAR_LEN,18,guiGetBackColor());
- guiShowStr(0,y,p->item[handle],fontMode, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- }
- static void uiMenuShowBar(SUT_MENU *p, REV_ENUM rev, FONT_MODEENUM fontMode){
- unsigned char x,y,handle;
- char *str;
- short len;
- unsigned int color;
-
- x=0;
- handle=p->handle%UI_MENU_ROW;
- y=UI_MENU_TOPY+handle*(12+UI_MENU_SPACE);
- str=(char *)p->item[p->handle];
- len=guiGetStrXLen(str, fontMode);
- if(REVERSED_NO==rev) color=COLOR_STATUS_BAR;
- else color=guiGetBackColor();
- guiFillRect(x, y-2, x+UI_MENU_BAR_LEN, y+14, color);
- if(REVERSED_NO==rev) guiShowStr(x,y,str, fontMode, rev,guiGetBackColor(), COLOR_STATUS_BAR);
- else guiShowStr(x,y,str, fontMode, rev,guiGetBackColor(), COLOR_BLACK);
- }
- static void uiMenuShow(SUT_MENU *p, FONT_MODEENUM fontMode){
- unsigned char i,j;
- unsigned short x,y;
- j=p->page*UI_MENU_ROW;
- for(i=j;i<j+UI_MENU_ROW;i++){
- if(i>=p->itemnum){
- y=UI_MENU_TOPY+(i%UI_MENU_ROW)*(12+UI_MENU_SPACE);
- guiClearArea(0, y-1, UI_MENU_BAR_LEN, 12+UI_MENU_SPACE,guiGetBackColor());
- }else uiMenuShowItem(p,i, fontMode);
- }
- uiMenuShowBar(p,REVERSED_NO,fontMode);
- //show arrow
- x=UI_MENU_BAR_LEN+(GLCD_WIDTH-UI_MENU_BAR_LEN)/2-2;
- if(p->page>0) guiDrawArrow(GLCD_WIDTH-5, UI_MENU_TOPY, 8, ARROW_UP, COLOR_STATUS_BAR);
- else guiClearArea(x, UI_MENU_TOPY, 18,8+10,guiGetBackColor());
- y=UI_MENU_TOPY+UI_MENU_ROW*(12+UI_MENU_SPACE);
- if(p->page<(p->pagenum-1)) guiDrawArrow(GLCD_WIDTH-5, y-2,8, ARROW_DOWN, COLOR_STATUS_BAR);
- else guiClearArea(x,y-8-2,19,8,guiGetBackColor());
- }
- void uiMenuInit(SUT_MENU *p, const char **item, FONT_MODEENUM fontMode,bool status){
- unsigned char i,ch,index;
- UI_STACKDEF *uiPtr=uiMenuGetStack();
- p->item=item;
- i=0;
- for(;;){
- ch=p->item[i][0];
- if(ch==0) break;
- i++;
- }
- i--;
- p->itemnum = i+1;
- p->pagenum=i/UI_MENU_ROW;
- if(p->pagenum%UI_MENU_ROW) p->pagenum ++;
- if(UI_MENU_KEY_ESC==uiMenuGetKey() || uiPtr->ok_back){
- if(status==true){
- index=uiPullStack();
- if(index>9){
- p->page=2;
- p->handle=index;
- }else if(index>4){
- p->page=1;
- p->handle=index;
- }else{
- p->page=0;
- p->handle=index;
- }
- uiPtr->ok_back=0;
- }else{
- p->page=0;
- p->handle=0;
- }
- }else{
- p->page=0;
- p->handle=0;
- }
- uiMenuShow(p,fontMode);
- }
- unsigned short uiMenuResponse(SUT_MENU *p){
- unsigned char tmp;
- unsigned short key=uiMenuGetKey();
- switch(key){
- case UI_MENU_KEY_UP:
- uiMenuShowBar(p, REVERSED_YES, FONT_MODE_12X12);
- if(p->handle==0) p->handle=p->itemnum-1;
- else p->handle --;
- tmp=p->page;
- p->page=p->handle/UI_MENU_ROW;
- if(tmp != p->page) uiMenuShow(p, FONT_MODE_12X12);
- else uiMenuShowBar(p, REVERSED_NO, FONT_MODE_12X12);
- break;
- case UI_MENU_KEY_DOWN:
- uiMenuShowBar(p, REVERSED_YES, FONT_MODE_12X12);
- p->handle ++;
- if(p->handle>=p->itemnum) p->handle=0;
- tmp=p->page;
- p->page=p->handle/UI_MENU_ROW;
- if(tmp != p->page) uiMenuShow(p, FONT_MODE_12X12);
- else uiMenuShowBar(p, REVERSED_NO, FONT_MODE_12X12);
- break;
- default:
- break;
- }
- return key;
- }
|