239 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			239 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "mywin_user_menu.h"
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
#define WIN_MENU_TYPE "WIN_MenuStruct"
 | 
						|
 | 
						|
 | 
						|
WIN_MenuStruct *WIN_CreatMenu (WIN_WindowStruct *base,
 | 
						|
			void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
 | 
						|
			int x,int y,int x_size,int y_size)
 | 
						|
{ 
 | 
						|
	//重设消息循环
 | 
						|
	if (msgLoop==0)
 | 
						|
	{
 | 
						|
		msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))MENU_DefaultMsgLoop;  
 | 
						|
	} 
 | 
						|
	
 | 
						|
	WIN_MenuStruct *ret=mymalloc (sizeof ( WIN_MenuStruct));
 | 
						|
	//调用父类的构造函数
 | 
						|
	if (ret)
 | 
						|
	{
 | 
						|
		mymemset (ret,0,sizeof ( WIN_MenuStruct));
 | 
						|
		if (0==WIN_CreatTouchEx((WIN_TouchWinStruct *)ret,base,msgLoop,x,y,x_size,y_size))
 | 
						|
		{
 | 
						|
			//创建失败
 | 
						|
			myfree (ret);
 | 
						|
			ret=0;
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			((WIN_WindowStruct *)ret)->winType=WIN_MENU_TYPE;
 | 
						|
			((WIN_WindowStruct *)ret)->color=0xaabbcc;
 | 
						|
			
 | 
						|
			ret->bar=WIN_CreatScrollbar((WIN_WindowStruct *)ret,0,20,45,x_size-40,y_size-90);
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	
 | 
						|
	return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//设置标题
 | 
						|
void MENU_SetTitle (WIN_MenuStruct *menu,char *img,char *txt)
 | 
						|
{
 | 
						|
	menu->title.img=img;
 | 
						|
	mymemcpy (menu->title.txt,txt,strlen(txt)+1);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void MENU_SetMaxItem(WIN_MenuStruct *menu,int itemNum)
 | 
						|
{
 | 
						|
	SCROLLBAR_SetItemNum(menu->bar,itemNum);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
//设置条目
 | 
						|
void MENU_AddItem (WIN_MenuStruct *menu,char *img,char *txt)
 | 
						|
{
 | 
						|
	SCROLLBAR_AddItem(menu->bar,txt,img);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int MENU_GetAllItemNum(WIN_MenuStruct *menu)
 | 
						|
{
 | 
						|
	return menu->bar->itemNum;
 | 
						|
}
 | 
						|
 | 
						|
char *MENU_GetItem(WIN_MenuStruct *menu,int index)
 | 
						|
{
 | 
						|
	if(index>=0&&index<menu->bar->itemNum)
 | 
						|
		return menu->bar->items[index].txt;
 | 
						|
	else return 0;
 | 
						|
}
 | 
						|
 | 
						|
char *MENU_GetSelectItem(WIN_MenuStruct *menu)
 | 
						|
{
 | 
						|
	return MENU_GetItem(menu,menu->bar->index);
 | 
						|
}
 | 
						|
 
 | 
						|
 | 
						|
int MENU_GetIndex(WIN_MenuStruct *menu)
 | 
						|
{
 | 
						|
	return menu->bar->index;
 | 
						|
}
 | 
						|
 | 
						|
			
 | 
						|
//显示一个item结构体,靠左显示
 | 
						|
void MENU_PaintItem (MENU_ItemStruct *item,int x,int y,int x_size,int y_size)
 | 
						|
{
 | 
						|
	
 | 
						|
	int txt_xsize=WIN_GetFontWidth()*strlen(item->txt)/2;
 | 
						|
	
 | 
						|
	int img_xsize=0;			//图标横向尺寸
 | 
						|
	int img_ysize=0;			//图标纵向尺寸
 | 
						|
	int img_x=0;		//图标起点
 | 
						|
	int img_y=0;					//图标起点
 | 
						|
	
 | 
						|
	if (item->img)
 | 
						|
	{
 | 
						|
		WIN_PicStruct *pic=WIN_GetPic(item->img);
 | 
						|
		WIN_DrawPic(pic,x,y+(y_size-pic->ysize)/2,pic->xsize,pic->ysize);
 | 
						|
		img_xsize+=pic->xsize+WIN_GetFontWidth()/2;
 | 
						|
	}
 | 
						|
	int txt_x=x+img_xsize;
 | 
						|
	if (item->txt[0])
 | 
						|
	{
 | 
						|
		WIN_DrawTxtAt (item->txt,txt_x,y+y_size/2-WIN_GetFontHight()/2);
 | 
						|
	}
 | 
						|
	
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
//默认绘制函数
 | 
						|
void MENU_DefaultPaint (WIN_MenuStruct *menu)
 | 
						|
{
 | 
						|
	
 | 
						|
	int x=0;
 | 
						|
	int y=0;
 | 
						|
	int x_size=((WIN_WindowStruct *)menu)->x_size;
 | 
						|
	int y_size=((WIN_WindowStruct *)menu)->y_size;
 | 
						|
	
 | 
						|
	WIN_PaintBackGround ((WIN_WindowStruct *)menu);
 | 
						|
	
 | 
						|
	//绘制标题
 | 
						|
	WIN_SetLcdColor (((WIN_WindowStruct *)menu)->color);
 | 
						|
	MENU_PaintItem (&menu->title,x+25,y,x_size/2,40);
 | 
						|
	
 | 
						|
	
 | 
						|
}
 | 
						|
			
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
			
 | 
						|
//默认消息处理函数
 | 
						|
void MENU_DefaultMsgLoop (WIN_MenuStruct *menu,WIN_MsgStruct *msg)
 | 
						|
{
 | 
						|
	WIN_MoveStruct *m=0;
 | 
						|
	WIN_KeyStruct *k=0;
 | 
						|
	switch (msg->msg)
 | 
						|
	{	
 | 
						|
		case WIN_MSG_PAINT:
 | 
						|
			MENU_DefaultPaint(menu);
 | 
						|
		break;
 | 
						|
		case WIN_MSG_INIT:
 | 
						|
		{
 | 
						|
			int x_size=((WIN_WindowStruct *)menu)->x_size;
 | 
						|
			int y_size=((WIN_WindowStruct *)menu)->y_size;
 | 
						|
			menu->key_back=WIN_CreatButton(((WIN_WindowStruct *)menu),0,x_size-65,y_size-30,65,30);
 | 
						|
			BUTTON_SetKeyString(menu->key_back,"返回");
 | 
						|
		}
 | 
						|
		break;
 | 
						|
		case WIN_MSG_KEY:
 | 
						|
			k=msg->data.p;
 | 
						|
			if (k->shortPress&KEY_VALUE_UP)//短按
 | 
						|
			{
 | 
						|
//				MENU_IndexSub (menu);
 | 
						|
			}
 | 
						|
			else if (k->shortPress&KEY_VALUE_DOWN)
 | 
						|
			{
 | 
						|
//				MENU_IndexAdd (menu);
 | 
						|
			}
 | 
						|
			if (k->shortPress&KEY_VALUE_HOME)
 | 
						|
			{
 | 
						|
				//返回
 | 
						|
				((WIN_WindowStruct *)menu)->deleteWindow((WIN_WindowStruct *)menu);
 | 
						|
				break;
 | 
						|
			}
 | 
						|
			if (k->shortPress)
 | 
						|
			{
 | 
						|
				WIN_SetInvalid ((WIN_WindowStruct *)menu);
 | 
						|
			}
 | 
						|
			break;//case WIN_MSG_KEY:
 | 
						|
		case WIN_MSG_MOVE:
 | 
						|
			m=msg->data.p;
 | 
						|
			switch (m->moveType)
 | 
						|
			{
 | 
						|
				case MOVE_DATA_MOVED:
 | 
						|
					{
 | 
						|
					}
 | 
						|
					break;
 | 
						|
				case MOVE_DATA_TOUCHIN:
 | 
						|
					break;
 | 
						|
				case MOVE_DATA_TOUCHOUT:
 | 
						|
					
 | 
						|
					break;
 | 
						|
				default:
 | 
						|
					break;
 | 
						|
			}
 | 
						|
			break;
 | 
						|
		case WIN_MSG_CHID:
 | 
						|
			switch (msg->data.v)
 | 
						|
			{
 | 
						|
				case CHID_DELETE:
 | 
						|
				break;
 | 
						|
				case CHID_USER:
 | 
						|
				{
 | 
						|
					if (msg->srcWin==menu->key_back)
 | 
						|
					{
 | 
						|
						if (msg->data2.v==BUTTON_PRESSED)
 | 
						|
						{
 | 
						|
							//返回
 | 
						|
							((WIN_WindowStruct *)menu)->deleteWindow((WIN_WindowStruct *)menu);
 | 
						|
						}
 | 
						|
					}
 | 
						|
					else
 | 
						|
					{
 | 
						|
					}
 | 
						|
				}
 | 
						|
				break;
 | 
						|
				default:
 | 
						|
				break;
 | 
						|
			}
 | 
						|
			break;
 | 
						|
		default:
 | 
						|
			WIN_DefaultMsgLoop((WIN_WindowStruct *)menu,msg);
 | 
						|
		break;
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 |