//@author Roland Bramm #include "ProgressBar.h" ProgressBar::ProgressBar(char bullet, int width, int maxCounter, string actionName) : fbullet(bullet), fwidth(width), fmaxCounter(maxCounter), factionName(actionName){ fprintedBulletCounter = 0; printStart(); } ProgressBar::~ProgressBar() { if(fprintedBulletCounter < getWidthofBar()){ for(int i = 0; i < (getWidthofBar() - fprintedBulletCounter) ; i++){ cout << fbullet << flush; } } cout << endl; } void ProgressBar::setBulletChar(char bullet){ fbullet = bullet; } void ProgressBar::setWidth(int width){ fwidth = width; } void ProgressBar::setMaxCounter(int maxCounter){ fmaxCounter = maxCounter; } void ProgressBar::setActionName(string actionName){ factionName = actionName; } int ProgressBar::getWidthofBar(){ int retval = 0; //Length of Action name retval = fwidth - factionName.length(); //start and end of Bar retval = retval - 2 - 1; return retval; } int ProgressBar::getBulletEvery(){ return (int)(fmaxCounter/(float)getWidthofBar()+1); } int ProgressBar::getBulletsEvery(){ return (int)(getWidthofBar()/(float)fmaxCounter); } void ProgressBar::printStart(){ cout << factionName << " ["; for(int i = 0; i < getWidthofBar(); i++){ cout << " "; } cout << "]\r"; cout << factionName << " [" << flush; } void ProgressBar::print(int iterator){ if(fwidth < fmaxCounter){ if(iterator%getBulletEvery() == 0){ cout << fbullet << flush; //cout << iterator << endl; fprintedBulletCounter++; } }else{ for(int i = 0; i < getBulletsEvery(); i++){ cout << fbullet << flush; fprintedBulletCounter++; } } }