在BREW中打造自己的GUI(6)-单选框与复选框的实现
2008-03-04 12:50
435 查看
还有一个常用的UI控件是单选框与复选框。可惜BREW也不提供,所以,只能自己做一个了。
先看一下每个选项的结构定义,我们用图片来做那个选中和未选中的显示,这样才能做出更多更美观的界面效果,所以在结构中有两个成员pCkImage和pNrImage,同时,isSelected用来记录此项是否被选中:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
typedef struct
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nItemID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR * pText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * pCkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * pNrImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const char * pszResFile;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wCkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wNrImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean isSelected;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
} TGBOption;
而整个控件的结构如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
struct _IGButton ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AEEVTBL(IGButton) * pvt;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_nRefs;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IShell *m_pIShell;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDisplay *m_pIDisplay;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IModule *m_pIModule;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean m_isActive;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect m_Rect;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 props;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR *pTitle;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEFont titleFont;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL titleColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *pBkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList *pOptionList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_Index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
同样是用 TQueueList来保存一个选项的链表,当前少不了m_Index当前项了。
需要的接口函数定义如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AEEINTERFACE(IGButton)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_IBASE(IGButton)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGButton)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetTitle) (IGButton * po, AECHAR * szText,AEEFont font,RGBVAL color);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetBkImage) (IGButton * po, IImage * img);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*AddOption) (IGButton * po, TGBOption *opt);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*IsChecked) (IGButton * po,int idx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*GetSel) (IGButton * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*GetItemCount) (IGButton * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
下面来看看实现,同样的先看HandleEvent,需要处理上下方向键,修改m_Index以改变当前项;处理SELECT键处理选中/取消选中的操作。
在Redraw函数中呢?遍历一下那个pOptionList链表,根据每个项是否选中,绘制出来即可。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGButton_Redraw(IGButton * pMe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i,j,height,h,a,b;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int xx,yy,dxx,dyy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect rec;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEImageInfo infIc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL oldColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList * p = pMe->pOptionList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
h=IDISPLAY_GetFontMetrics(pMe->m_pIDisplay,AEE_FONT_NORMAL,&a,&b);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_EraseRect(pMe->m_pIDisplay,&pMe->m_Rect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->pBkImage)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_SetDrawSize(pMe->pBkImage,pMe->m_Rect.dx,pMe->m_Rect.dy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->pBkImage,pMe->m_Rect.x,pMe->m_Rect.y);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oldColor = IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,MAKE_RGB(0,0,0));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height=pMe->m_Rect.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(p)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * img;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TGBOption * pData=(TGBOption*)p->pData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData->isSelected)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
img=pData->pCkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
img=pData->pNrImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(img)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(img,&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(img,pMe->m_Rect.x,height);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x+infIc.cx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height+(infIc.cy-h)/2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=pMe->m_Rect.x+pMe->m_Rect.dx-xx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=h;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText,-1,xx,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==pMe->m_Index)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=infIc.cx+IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText);;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=infIc.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawRect(pMe->m_pIDisplay,&rec,MAKE_RGB(0,0,250),0,IDF_RECT_FRAME);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height+=infIc.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_Update(pMe->m_pIDisplay);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return TRUE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
还有一件事,如果在程序中取到这个组件的结果呢?如果是单选就可以直接GetSel了,如果是复选则循环一下一个个判断是否选中IsChecked即可:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGButton_IsChecked(IGButton * pMe,int idx)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->props&0x01==GBTN_STYLE_CHECK)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TGBOption * pData=(TGBOption*)Queue_Get(pMe->pOptionList,idx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return pData->isSelected;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return FALSE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static int IGButton_GetSel(IGButton * pMe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if((pMe->props&0x01)==GBTN_STYLE_RADIO)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList * p=pMe->pOptionList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//int i = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(p)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TGBOption * pData=(TGBOption*)p->pData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData && pData->isSelected)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return pData->nItemID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//i+=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return -1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
OK,基本上搞定。
先看一下每个选项的结构定义,我们用图片来做那个选中和未选中的显示,这样才能做出更多更美观的界面效果,所以在结构中有两个成员pCkImage和pNrImage,同时,isSelected用来记录此项是否被选中:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
typedef struct
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nItemID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR * pText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * pCkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * pNrImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const char * pszResFile;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wCkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wNrImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean isSelected;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
} TGBOption;
而整个控件的结构如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
struct _IGButton ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AEEVTBL(IGButton) * pvt;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_nRefs;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IShell *m_pIShell;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDisplay *m_pIDisplay;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IModule *m_pIModule;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean m_isActive;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect m_Rect;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 props;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR *pTitle;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEFont titleFont;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL titleColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *pBkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList *pOptionList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_Index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
同样是用 TQueueList来保存一个选项的链表,当前少不了m_Index当前项了。
需要的接口函数定义如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AEEINTERFACE(IGButton)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_IBASE(IGButton)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGButton)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetTitle) (IGButton * po, AECHAR * szText,AEEFont font,RGBVAL color);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetBkImage) (IGButton * po, IImage * img);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*AddOption) (IGButton * po, TGBOption *opt);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*IsChecked) (IGButton * po,int idx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*GetSel) (IGButton * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*GetItemCount) (IGButton * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
下面来看看实现,同样的先看HandleEvent,需要处理上下方向键,修改m_Index以改变当前项;处理SELECT键处理选中/取消选中的操作。
在Redraw函数中呢?遍历一下那个pOptionList链表,根据每个项是否选中,绘制出来即可。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGButton_Redraw(IGButton * pMe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i,j,height,h,a,b;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int xx,yy,dxx,dyy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect rec;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEImageInfo infIc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL oldColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList * p = pMe->pOptionList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
h=IDISPLAY_GetFontMetrics(pMe->m_pIDisplay,AEE_FONT_NORMAL,&a,&b);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_EraseRect(pMe->m_pIDisplay,&pMe->m_Rect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->pBkImage)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_SetDrawSize(pMe->pBkImage,pMe->m_Rect.dx,pMe->m_Rect.dy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->pBkImage,pMe->m_Rect.x,pMe->m_Rect.y);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oldColor = IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,MAKE_RGB(0,0,0));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height=pMe->m_Rect.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(p)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * img;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TGBOption * pData=(TGBOption*)p->pData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData->isSelected)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
img=pData->pCkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
img=pData->pNrImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(img)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(img,&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(img,pMe->m_Rect.x,height);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x+infIc.cx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height+(infIc.cy-h)/2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=pMe->m_Rect.x+pMe->m_Rect.dx-xx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=h;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText,-1,xx,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==pMe->m_Index)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=infIc.cx+IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText);;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=infIc.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawRect(pMe->m_pIDisplay,&rec,MAKE_RGB(0,0,250),0,IDF_RECT_FRAME);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height+=infIc.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_Update(pMe->m_pIDisplay);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return TRUE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
还有一件事,如果在程序中取到这个组件的结果呢?如果是单选就可以直接GetSel了,如果是复选则循环一下一个个判断是否选中IsChecked即可:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGButton_IsChecked(IGButton * pMe,int idx)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->props&0x01==GBTN_STYLE_CHECK)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TGBOption * pData=(TGBOption*)Queue_Get(pMe->pOptionList,idx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return pData->isSelected;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return FALSE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static int IGButton_GetSel(IGButton * pMe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if((pMe->props&0x01)==GBTN_STYLE_RADIO)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList * p=pMe->pOptionList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//int i = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(p)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TGBOption * pData=(TGBOption*)p->pData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData && pData->isSelected)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return pData->nItemID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//i+=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return -1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
OK,基本上搞定。
相关文章推荐
- 在BREW中打造自己的GUI(7)-动态效果的实现
- 在BREW中打造自己的GUI(1)-图形化菜单的实现
- 在BREW中打造自己的GUI(5)-滚动条的实现
- 在BREW中打造自己的GUI(2)-TabPane的实现
- 在BREW中打造自己的GUI(4)-IGStatic的实现
- 在BREW中打造自己的GUI(5)-滚动条的实现
- 在BREW中打造自己的GUI(8)-IWEB的封装
- 在BREW中打造自己的GUI(3)-做一个跑马灯的效果
- 打造自己的MFC:thunk技术实现窗口类的封装
- jquery边学边练2--用ul li实现单选框和复选框功能(强化版,优化版)
- 利用jquery和css打造个性化的单选框和复选框
- 用jquery与css打造个性化的单选框和复选框
- 在ASP.NET中实现OAuth2.0(二)之打造自己的API安全策略
- 基于OgreBites::Widget 实现自己的GUI系统(1)
- 基于Ogre::Bites实现自己的GUI系统(3)
- 打造自己php的开发框架--php的MVC简单实现
- 从强化学习基本概念到Q学习的实现,打造自己的迷宫智能体
- 自己打造HTML在线编辑器的实现难点分析
- jquery边学边练1--用ul li实现单选框和复选框功能
- 如何才能学到Qt的精髓——信号槽之间的无关性,提供了绝佳的对象间通讯方式,QT的GUI全是自己的一套,并且完全开源,提供了一个绝好机会窥视gui具体实现