123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /********************************************************************************
- * File Name: Menu.c
- * Function Describe: Menu 控件
- * Relate Module: GUI.c
- * Writer: Shliangwen
- * Date: 2016-1-8
- *******************************************************************************/
- #include "Includes.h"
- /******************************************************************
- 返回串str在LCD显示所占的x坐标长度
- *******************************************************************/
- int GetStrXLen(char *str)
- {
- unsigned char ch;
- unsigned short len;
- len=0;
- while ((ch=*str++)){
- if(ch=='M')len+=16;
- else len+=8;
- if(len>LCD_WIDTH-1){//191
- len=LCD_WIDTH-1;
- break;
- }
- }
- return (unsigned char )len;
- }
- /*************************************************************************
- *居中显示
- ***************************************************************************/
- void ShowCaption(const char *str,unsigned char y)
- {
- char buf[30];
- int len;
- len=GetStrXLen((char *)str);
- GuiShowStr((LCD_WIDTH-len)/2,y,str,0x01);
- }
- /*************************************************************************
- MenuInit
- ***************************************************************************/
- void MenuInit(struct SUT_MENU *p,const char **item)
- {
- unsigned char i,ch;
- //calculate menu item number
- p->item = item;
- i = 0;
- for(;;)
- {
- ch=p->item[i][0];
- if(ch==0)break;
- i ++;
- }
- i=i-1;
- p->itemnum = i+1;
- p->pgaenum=i/MENU_ROW;
- if(p->pgaenum%MENU_ROW)p->pgaenum+=1;
- //
- p->page = 0;
- p->handle = 0;
-
- MenuShow(p);
-
- }
- /********************************************************************************
- * Function:MenuShowItem
- * display menu item
- *******************************************************************************/
- void MenuShowItem(struct SUT_MENU *p,unsigned char handle)
- {
- unsigned char y,hand;
- hand=handle % MENU_ROW;
- y=MENU_TOPY+hand*(16+MENU_SPACE);
- GuiClearArea((LCD_WIDTH-MENU_BAR_LEN)/2,y-1,MENU_BAR_LEN,18);
- ShowCaption(p->item[handle],y);
- }
- /********************************************************************************
- * Function:MenuShowBar
- * display a bar
- *******************************************************************************/
- void MenuShowBar(struct SUT_MENU *p)
- {
- unsigned char x,y,h,handle;
- char *str;
-
- x=(LCD_WIDTH-MENU_BAR_LEN)/2;
- handle=p->handle%MENU_ROW;
- y=MENU_TOPY+handle*(16+MENU_SPACE);
-
- GuiReverseRect(x,y-1,MENU_BAR_LEN,18);
- }
- /********************************************************************************
- * Function:MenuShow
- * display menu
- *******************************************************************************/
- void MenuShow(struct SUT_MENU *p)
- {
- unsigned char i,j;
- u16 x,y;
-
- j=p->page*MENU_ROW;
-
- for(i = j ; i <j+MENU_ROW ; i ++)
- {
- if(i >= p->itemnum){
- y=MENU_TOPY+(i % MENU_ROW)*(16+MENU_SPACE);
- GuiClearArea((LCD_WIDTH-MENU_BAR_LEN)/2,y-1,MENU_BAR_LEN,18);
- }else{
- MenuShowItem(p,i);
- }
-
- }
- MenuShowBar(p);
- //显示箭头
- x=MENU_BAR_LEN+(LCD_WIDTH-MENU_BAR_LEN)/2;
- if(p->page>0){
- GuiShowArrow(x+10,MENU_TOPY,8,3);//向上箭头
- }else{
- GuiClearArea(x,MENU_TOPY,18,8);
- }
-
- y=MENU_TOPY+MENU_ROW*(16+MENU_SPACE);
- if(p->page<(p->pgaenum-1)){
- GuiShowArrow(x+10,y,8,4);//向下箭头
- }else{
- GuiClearArea(x,y-8,18,8);
- }
- }
- /********************************************************************************
- * Function:MenuResponse
- *******************************************************************************/
- unsigned long MenuResponse(struct SUT_MENU *p)
- {
- unsigned char temp;
- switch(g_ulKeyValue)
- {
- case KEY_PANEL_UP:
- MenuShowBar(p);
- if(p->handle==0)p->handle=(p->itemnum-1);
- else p->handle --;
- temp=p->page;
- p->page=p->handle/MENU_ROW;
- if(temp!=p->page)MenuShow(p);
- else MenuShowBar(p);
- break;
- case KEY_PANEL_DOWN:
- MenuShowBar(p);
- p->handle ++;
- if(p->handle>=p-> itemnum)p->handle=0;
- temp = p->page;
- p->page=p->handle/MENU_ROW;
- if(temp!=p->page)MenuShow(p);
- else MenuShowBar(p);
-
- break;
-
- // case KEY_PANEL_OK:
- // return MENU_KEY_ENTER;
- //
- // case KEY_PANEL_EXIT:
- // return MENU_KEY_BACK;
- //
- default:
- return g_ulKeyValue;
- break;
- }
- return 0;
- }
- /********************************************************************************
- * Function:MenuGetHandle
- * get menu 's handle
- *******************************************************************************/
- unsigned char MenuGetHandle(struct SUT_MENU *p)
- {
- unsigned char handle;
- handle = p->handle;
- /*
- for(i = 0 ; i <= p->handle ; i ++)
- {
- if(p->item[i][0] == 0)handle --;
- }
- */
- return handle;
- }
|