首 页 | 新 闻 | Symbian | Windows Mobile| J2ME | 下载中心 | 游戏策划 | 购书指南 | 移动开发视频教程
您现在的位置: 开发视界 >> 专家专栏 >> 李勇飞 >> 文章正文
Making TimeLine Control
作者:Li Yongf…    文章来源:www.symbianer.com    更新时间:2006-8-4 11:30:30

Making TimeLine Control

The timelnie in puzzle games, lifetime in fighting games, that is a very normol element.
The following article will tell you how to make a timeline control step by step in S60.
Author Website: http://www.symbianer.com

The keywords of artile: window, custom control, time, periodic.

Frist, you need reffer to tow articles
I.Symbian OS: Creating Custom Controls
you can download here>>

II.Periodic timer active object.
Developer Library >> API Reference >> C++ API reference >> Timers and Timing Services >> CPeriodic

1. Class Declaration:
Code:
class CMyTimerContainer : public CCoeControl
{
 public:
   
    void ConstructL(TInt aSecond ,TPoint aPoint, TSize aSize); // Initialize Seconds, Position, Size Of Timeline Control
    ~CMyTimerContainer();
    void Draw(const TRect& aRect) const;

    static TInt Start__(TAny* aObject);    
    void Start_();
private: //data

  CPeriodic* iPeriodic;
  TInt iLeft; //Left times
  TInt iTotal;//Total times
  TPoint iPoint; //control position,
  TSize iSize; //Control size
}
2. Periodic Functions:
Code:
TInt CMyTimerContainer::Start__(TAny* aObject)
{
  ((CMyTimerContainer*)aObject)->Start_(); // cast, and call non-static function
    return 1;
}

void CMyTimerContainer::Start_()
{
  iLeft--;
  if(iLeft==0)
  {
    DrawNow();
    iPeriodic->Cancel();
    return;
  }
  DrawNow();
}
3. Draw Funciton
Code:
void CMyTimerContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();

    /*Draw BackGround*************************/
    gc.SetBrushColor( KRgbBlack );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect(aRect);

    /*Drar Timeline*************************/
     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
     gc.SetBrushColor( KRgbRed );
     gc.SetPenStyle( CGraphicsContext::ENullPen );
     gc.DrawRect( TRect(TSize(iLeft*Size().iWidth/iTotal,iSize.iHeight)) );
    }


4. Construct Function

Code:
void CMyTimerContainer::ConstructL(TInt aSecond ,TPoint aPoint, TSize aSize)
    {
    CreateWindowL();
    iTotal = aSecond;
    iLeft = iTotal;
    iPoint = aPoint;
    iSize = aSize;
    iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle);
    iPeriodic->Start(0/*8000000*/, 1000000/*35714*/, TCallBack(Start__, this));
    SetExtent(aPoint,aSize);
    ActivateL();
    }


5. How To Use The Timeline Custom Control

Code:
a.Add Custom Control in XXXContainer.h
   private: //data
     CMyTimerContainer* iTimer;

b,Initialize Seconds, Position, Size Of Timeline Control
void CXXXXContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    iTimer =  new (ELeave) CMyTimerContainer;
    iTimer->ConstructL( 60/*init seconds*/,TPoint(0,100),TSize(176,15),this);

    SetRect(aRect);
    ActivateL();
    }
You can reffer to the codes of article to modify your codes. Welcome to comment here.
Download Source Codes>> 

English Version: http://www.symbianer.com/post/custom-control-timeline-en.html
Chinese Version: http://www.symbianer.com/post/custom-control-timeline.html

Mail: N-office@163.com
Website: http://www.symbianer.com

相关文章:
Symbian中的iScanCode和iCode
Symbian中所体现的软件编程艺术
时间条控件制作简明教程[中文版]
关于摄像头的一个API帮助文档RCameraServ类
Symbian sdk帮助-类TRealFormat
Symbian sdk帮助-类TDes8
Symbian sdk帮助-类Constants
Symbian sdk帮助-类CBitmapAnimClientData