📄 menu.cpp
字号:
#include "Menu.h"
#include <stringloader.h>
//#include "GGBallEnv.h"
CMenu::CMenu(const TRect& aRect ):CBaseControl(aRect)
{
iCurrentIndex=0;
iMenuItemHeight=0;
Hide();
}
CMenu::~CMenu()
{
TInt count=iArray.Count();
for (TInt i=0;i<count;i++)
{
delete iArray[i].iText;
}
iArray.Close();
}
CMenu* CMenu::NewL( const TRect& aRect )
{
CMenu* self=CMenu::NewLC(aRect);
CleanupStack::Pop();
return self;
}
CMenu* CMenu::NewLC( const TRect& aRect )
{
CMenu* self=new(ELeave)CMenu(aRect);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CMenu::ConstructL()
{
}
void CMenu::Draw(CBitmapContext& aGc) const
{
//画背景
CBaseControl::Draw(aGc);
//画菜单项
if (Visible())
{
DrawMenuItems(aGc);
}
}
void CMenu::AddCmdL( TInt aResourceId,TFunction aFun )
{
CmdNode item;
item.iFun=aFun;
item.iText=StringLoader::LoadL(aResourceId);
iArray.Append(item);
iRect.iTl.iY-=iMenuItemHeight;
}
void CMenu::DrawMenuItems( CBitmapContext& aGc ) const
{
TInt count=iArray.Count();
for (TInt i=0;i<count;i++)
{
TRect rect(iRect.iTl.iX,iRect.iTl.iY+iMenuItemHeight*i,
iRect.iBr.iX,iRect.iTl.iY+iMenuItemHeight*(i+1));
if (iCurrentIndex==i)
{
CGraphicsTool::DrawRect(aGc,rect,TRgb(113,92,185),ETrue);
}
CGraphicsTool::DrawText(aGc,iFont,*iArray[i].iText,rect,CGraphicsContext
::ELeft,5);
}
}
void CMenu::Next()
{
TInt count=iArray.Count();
iCurrentIndex++;
if (iCurrentIndex>=count)
{
iCurrentIndex=0;
}
}
void CMenu::Pre()
{
iCurrentIndex--;
if (iCurrentIndex<0)
{
TInt count=iArray.Count();
iCurrentIndex=count-1;
}
}
TFunction CMenu::CurrentFunction()
{
TInt count=iArray.Count();
if (count>0 && iCurrentIndex>=0 && iCurrentIndex<=count-1)
{
return iArray[iCurrentIndex].iFun;
}
return EFun_None;
}
void CMenu::SetMenuItemHeight( TInt aHeight )
{
iMenuItemHeight=aHeight;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -