在BREW中打造自己的GUI(4)-IGStatic的实现
2008-03-04 12:18
519 查看
BREW中的IStatic可以方便地显示一个文本,但是它没有背景不能滚动,其实并不方便,所以我们也自己做一个吧。
首先,同样是定义它的数据结构如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
struct _IGStatic ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AEEVTBL(IGStatic) * 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)
int cntLines; //一屏可显示的行数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nTopLine; //当前显示的首行
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nScrollTop; //滚动的首行
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nScrollBtm; //滚动的末行
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nLineHeight; //行高
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *pImage; //背景图
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL color; //文字颜色
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEFont font; //文字字体
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int lineCount; //总行数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nNext; //当前
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR **ppLines; //分行保存的字串内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGScrollBar * pScBar;
![](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/ExpandedBlockEnd.gif)
};
除了背景图、文字颜色字体以外,我们主要考虑是的如何实现文本的分行?如何实现文本的上下滚动?所以,在这里增加了几个辅助变量来处理行数。
需要额外增加的接口函数并不多,就是设置一个文本和图片罢了:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AEEINTERFACE(IGStatic)
![](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(IGStatic)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGStatic)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetText) (IGStatic * po, AECHAR * szText,AEEFont font,RGBVAL color);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetImage) (IGStatic * po, IImage * img);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
实现的关键在于一是文本的分行处理,在setText的时候,我们需要完成这件事,计算文本的长度,循环切割它判断是否可以在当前的mRect范围内显示,直到可以的话,则将这段文本作为一行放入ppLines中:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGStatic_SetText(IGStatic * pMe, AECHAR * szText,AEEFont font,RGBVAL color)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR sch;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR * p;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int k,len;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->nNext=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->color=color;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->font=font;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->nLineHeight=IDISPLAY_GetFontMetrics (pMe->m_pIDisplay, pMe->font,NULL,NULL);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->cntLines=(pMe->m_Rect.dy-MARGIN*2)/pMe->nLineHeight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=szText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
do
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
k=WSTRLEN(p);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(k>0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
len=IDISPLAY_MeasureText(pMe->m_pIDisplay,pMe->font,p);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(len>pMe->m_Rect.dx-MARGIN*2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
k--;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sch=p[k];p[k]=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
len=IDISPLAY_MeasureText(pMe->m_pIDisplay,pMe->font,p);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p[k]=sch;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->ppLines=(AECHAR**)REALLOC(pMe->ppLines,sizeof(AECHAR*)*(pMe->nNext+1));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_AppendLine(pMe,p,k);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p+=k;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}while(k>0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->lineCount=pMe->nNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->pScBar)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGSCROLLBAR_SetRange(pMe->pScBar,0,pMe->lineCount);
![](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)
}
在正确地分行以后,剩下的事情就好做了,在HandleEvent时处理一下当前行,实现上下滚动。在Redraw时根据当前行、当前页的首行、每页可显示行数就可以正确地显示文本了。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGStatic_Redraw(IGStatic * 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->m_isActive)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL oc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i=0,j=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nMax = (pMe->lineCount-pMe->nTopLine<pMe->cntLines)?pMe->lineCount-pMe->nTopLine:pMe->cntLines;
![](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->pImage)
![](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->pImage,pMe->m_Rect.dx,pMe->m_Rect.dy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->pImage,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)
if(pMe->props&0x02)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawRect(pMe->m_pIDisplay,&pMe->m_Rect,MAKE_RGB(0,0,0),-1,IDF_RECT_FRAME);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oc=IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,pMe->color);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for ( i=0,j=pMe->nTopLine; i<nMax; i++,j++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_DrawLine(pMe,j,i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->pScBar && pMe->props&0x01)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGSCROLLBAR_SetPosition(pMe->pScBar,pMe->nTopLine,pMe->cntLines);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGSCROLLBAR_Redraw(pMe->pScBar);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.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,oc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](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)
}
你可能会注意到这里我们还有一个控件IGScrollBar,是我们自定义的滚动条组件。
首先,同样是定义它的数据结构如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
struct _IGStatic ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AEEVTBL(IGStatic) * 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)
int cntLines; //一屏可显示的行数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nTopLine; //当前显示的首行
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nScrollTop; //滚动的首行
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nScrollBtm; //滚动的末行
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nLineHeight; //行高
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *pImage; //背景图
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL color; //文字颜色
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEFont font; //文字字体
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int lineCount; //总行数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nNext; //当前
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR **ppLines; //分行保存的字串内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGScrollBar * pScBar;
![](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/ExpandedBlockEnd.gif)
};
除了背景图、文字颜色字体以外,我们主要考虑是的如何实现文本的分行?如何实现文本的上下滚动?所以,在这里增加了几个辅助变量来处理行数。
需要额外增加的接口函数并不多,就是设置一个文本和图片罢了:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AEEINTERFACE(IGStatic)
![](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(IGStatic)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGStatic)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetText) (IGStatic * po, AECHAR * szText,AEEFont font,RGBVAL color);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetImage) (IGStatic * po, IImage * img);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
实现的关键在于一是文本的分行处理,在setText的时候,我们需要完成这件事,计算文本的长度,循环切割它判断是否可以在当前的mRect范围内显示,直到可以的话,则将这段文本作为一行放入ppLines中:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGStatic_SetText(IGStatic * pMe, AECHAR * szText,AEEFont font,RGBVAL color)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR sch;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AECHAR * p;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int k,len;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->nNext=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->color=color;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->font=font;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->nLineHeight=IDISPLAY_GetFontMetrics (pMe->m_pIDisplay, pMe->font,NULL,NULL);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->cntLines=(pMe->m_Rect.dy-MARGIN*2)/pMe->nLineHeight;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=szText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
do
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
k=WSTRLEN(p);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(k>0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
len=IDISPLAY_MeasureText(pMe->m_pIDisplay,pMe->font,p);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(len>pMe->m_Rect.dx-MARGIN*2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
k--;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sch=p[k];p[k]=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
len=IDISPLAY_MeasureText(pMe->m_pIDisplay,pMe->font,p);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p[k]=sch;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->ppLines=(AECHAR**)REALLOC(pMe->ppLines,sizeof(AECHAR*)*(pMe->nNext+1));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_AppendLine(pMe,p,k);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p+=k;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}while(k>0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->lineCount=pMe->nNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->pScBar)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGSCROLLBAR_SetRange(pMe->pScBar,0,pMe->lineCount);
![](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)
}
在正确地分行以后,剩下的事情就好做了,在HandleEvent时处理一下当前行,实现上下滚动。在Redraw时根据当前行、当前页的首行、每页可显示行数就可以正确地显示文本了。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGStatic_Redraw(IGStatic * 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->m_isActive)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL oc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i=0,j=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nMax = (pMe->lineCount-pMe->nTopLine<pMe->cntLines)?pMe->lineCount-pMe->nTopLine:pMe->cntLines;
![](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->pImage)
![](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->pImage,pMe->m_Rect.dx,pMe->m_Rect.dy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->pImage,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)
if(pMe->props&0x02)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawRect(pMe->m_pIDisplay,&pMe->m_Rect,MAKE_RGB(0,0,0),-1,IDF_RECT_FRAME);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oc=IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,pMe->color);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for ( i=0,j=pMe->nTopLine; i<nMax; i++,j++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_DrawLine(pMe,j,i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->pScBar && pMe->props&0x01)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGSCROLLBAR_SetPosition(pMe->pScBar,pMe->nTopLine,pMe->cntLines);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IGSCROLLBAR_Redraw(pMe->pScBar);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.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,oc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](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)
}
你可能会注意到这里我们还有一个控件IGScrollBar,是我们自定义的滚动条组件。
相关文章推荐
- 在BREW中打造自己的GUI(1)-图形化菜单的实现
- 在BREW中打造自己的GUI(5)-滚动条的实现
- 在BREW中打造自己的GUI(2)-TabPane的实现
- 在BREW中打造自己的GUI(5)-滚动条的实现
- 在BREW中打造自己的GUI(6)-单选框与复选框的实现
- 在BREW中打造自己的GUI(7)-动态效果的实现
- 在BREW中打造自己的GUI(8)-IWEB的封装
- 在BREW中打造自己的GUI(3)-做一个跑马灯的效果
- Android 打造自己的个性化应用(二):应用程序内置资源实现换肤功能
- 打造自己的专属Linux(二):使用脚本实现自动化建立小Linux与命令移植
- 打造自己的MFC:thunk技术实现窗口类的封装
- 基于OgreBites::Widget 实现自己的GUI系统(1)
- 基于Ogre::Bites实现自己的GUI系统(3)
- 打造自己php的开发框架--php的MVC简单实现
- 一个树控件类的实现---打造自己的树控件
- 打造自己的GUI专版命令行程序
- Android 打造自己的个性化应用(二):应用程序内置资源实现换肤功能
- Python最短代码实现人脸识别,打造自己专用人脸识别!
- 从强化学习基本概念到Q学习的实现,打造自己的迷宫智能体
- Android 打造自己的个性化应用(四):仿墨迹天气实现-->自定义扩展名的zip格式的皮肤