// Jason Rohrer // ProgressBar.cpp /** * * ProgressBar Gui element implementation * * * Created 11-6-99 * Mods: * Jason Rohrer 11-8-99 Changed to use GraphicBuffer object as screen buffer * */ #include "ProgressBar.h" ProgressBar::ProgressBar(int x, int y, int w, int h, Color bordC, Color hC, Color tipC) { startX = x; startY = y; wide = w; high = h; barWide = wide - 2*borderWide; barHigh = high - 2*borderWide; borderC = bordC; highC = hC; barTipC = tipC; imageMap = new unsigned long[high * wide]; mapYOffset = new int[high]; // precalc y offsets into 2d image map for( int y=0; yhigh-borderWide-1 || x>wide-borderWide-1 ) { imageMap[ yContrib + x ] = borderC.composite; // border } else { imageMap[ yContrib + x ] = 0xFF000000; // black inside } } } lastProgress = 0; } ProgressBar::~ProgressBar() { delete [] imageMap; delete [] mapYOffset; } void ProgressBar::setProgress(float fractionFull) { if( fractionFull < 0) fractionFull = 0; if( fractionFull > 1) fractionFull = 1; if( fractionFull < lastProgress ) { // decreasing proress, erase part of bar int deleteXStart = (int)((fractionFull) * barWide + borderWide); int deleteXEnd = (int)((lastProgress) * barWide + borderWide); for( int y=borderWide; y lastProgress) { //progress has increased int addXStart = (int)((lastProgress) * barWide + borderWide); int addXEnd = (int)((fractionFull) * barWide + borderWide); float weight = lastProgress; float deltaWeight = (fractionFull - lastProgress) / (addXEnd - addXStart); for( int x=addXStart; x