📄 newsrolltext.cpp
字号:
#include "NewsRollText.h"
#define SCROLL_INTERVAL 20000
CNewsRollText::CNewsRollText()
:iNewsBackgroundColor(KRgbWhite)
{
}
CNewsRollText::~CNewsRollText()
{
if(iNewsText)
{
delete iNewsText;
iNewsText = NULL;
}
iNewsPeriodicTimer->Cancel();
if(iNewsPeriodicTimer)
{
delete iNewsPeriodicTimer;
iNewsPeriodicTimer = NULL;
}
}
//*//*/设置文本内容
void CNewsRollText::NewsSetTextL(const TDesC& aText)
{
if(iNewsText)
{
delete iNewsText;
iNewsText = NULL;
}
iNewsText = aText.AllocL();
CEikLabel::SetTextL(aText);
}
//实现文本滚动
TBool CNewsRollText::IsNeedScroll()
{
if(iNewsText==NULL)
return EFalse;
if(iNewsStarPoint.iX > -iNewsLabelSize.iWidth)
return ETrue;
return EFalse;
}
void CNewsRollText::Start()
{
if(iNewsPeriodicTimer==NULL && IsNeedScroll())
{
iNewsPeriodicTimer = CPeriodic::NewL(EPriorityNormal);
iNewsPeriodicTimer->Start(0,SCROLL_INTERVAL,TCallBack(Tick,this));
}
}
TInt CNewsRollText::Tick(TAny* p)
{
CNewsRollText* pThis = (CNewsRollText*)p;
pThis->DoScroll();
return 0;
}
void CNewsRollText::DoScroll()
{
//切割
if(IsNeedScroll())
{
iNewsStarPoint.iX -= 2;
}
else
{
//重置
iNewsStarPoint.iX = Rect().Size().iWidth;
}
CEikLabel::SetExtent(iNewsStarPoint, iNewsLabelSize);
DrawDeferred();
}
//绘制控件背景
void CNewsRollText::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.SetBrushColor( iNewsBackgroundColor);
gc.DrawRect( aRect );
gc.SetBrushStyle( CGraphicsContext::ENullBrush );
CEikLabel::Draw(aRect);
}
void CNewsRollText::NewsSetBackgroundColor(TRgb aColor)
{
iNewsBackgroundColor = aColor;
}
void CNewsRollText::NewsSetExtent(const TPoint &aPosition, const TSize &aSize)
{
iNewsStarPoint = aPosition;
iNewsLabelSize = aSize;
CEikLabel::SetExtent(iNewsStarPoint, iNewsLabelSize);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -