Friday, August 17, 2007

How to create a progress bar

/*********************/// Clear a progress bar/*******************************/

static void ProgressBarClear(UInt16 unTop,UInt16 unLeft,UInt16 unWidth)
{
Rect.topLeft.x=unLeft;
Rect.topLeft.y=unTop;
Rect.extent.x=unWidth;
Rect.extent.y=12;
WinEraseRectangle(&Rect,0);
}

/*************************/// Draw a progress bar /****************************/

static void ProgressBarInit(UInt16 unTop,UInt16 unLeft,UInt16 unWidth)
{
ProgressBarClear(unTop,unLeft,unWidth);
Rect.topLeft.x=unLeft+1;
Rect.topLeft.y=unTop+1;
Rect.extent.x=unWidth-2;
Rect.extent.y=10;
newRgb.r=0x00;
newRgb.g=0x00;
newRgb.b=0x00;
WinSetForeColorRGB(&newRgb,&prevRgb);
WinDrawRectangleFrame(rectangleFrame,&Rect);
}

/***********************************/// ProgressBar
// Use example: Init with:ProgressBarInit(17,2,123);
// Call several time: ProgressBar(17,2,123,unIx,200);
// Clear with: ProgressBarClear(17,2,123);
/***************************************/

static void ProgressBar(UInt16 unTop,UInt16 unLeft,UInt16 unWidth,UInt32 unValue,UInt32 unMaxValue)
{
UInt32 ulTemp=0;
if(unMaxValue)
ulTemp=(unWidth-2)*unValue/unMaxValue;
if(ulTemp>(unWidth-2))
ulTemp=(unWidth-2);
Rect.topLeft.x=unLeft+1;
Rect.topLeft.y=unTop+1;
Rect.extent.x=ulTemp;
Rect.extent.y=10;
newRgb.r=0x00;
newRgb.g=0x00;
newRgb.b=0xFF;
WinSetForeColorRGB(&newRgb,&prevRgb);
WinDrawRectangle(&Rect,0);
}

No comments: