Im setting up a progress bar as follows :
void CProgressBar::add(int ammount)
{
mProgress += ammount;
}
float CProgressBar::get()
{
float pr = (float)mProgress * 100.0f / (float)mMax;
return pr;
}
And now here is the problem.I’m trying to render a small surface although it doesn’t properly fill it because i can’t
figure out how to scale properly the value :
/*
Progress bar box has size of 128x16
|-----------|
|-----------|
*/
float progress = progressBar->get();
float scale = 4.0f; //Here i have it hardcoded although i have to make this generic
progress *= scale;
graphics->color(prgColor);
graphics->renderQd(CRect(x,y,progress,height));
So im kindly asking for some help on the matter…
You have to linearly interpolate between the width of the rectangle with 0% progress and the width of the rectangle with 100% progress. E.G:
The interpolation works as follows:
Important:
progresshas to be in the range of 0 to 1! So you might want to change theCProgressBar::get()function or divide by 100 first.Now you can just render the rectangle with the new width: