/*========================================================================= This TProgressBar class expands on Mr. Perez's upload TPROGB.ZIP. This alternative lets you include the class definition without having to modify it for each main process. The dialog box that contructs TProgressBar will be responsible for updating it. See the example in EXAMPLE.CPP. You'll also find instructions on how to include the source in your TV.LIB and simply #define Uses_TProgressBar before #include . By: Barnaby W. Falls CIS: 70662,1523 -------------------------------------------------------------------------*/ #include #include #define Uses_string #define Uses_TProgressBar #define Uses_TView #define Uses_TRect #define Uses_TGroup #define Uses_TDrawBuffer #define Uses_TStreamableClass #define Uses_opstream #define Uses_ipstream #define Uses_TPalette #include #include "tprogbar.h" __link( RView ) /* Registration object */ TStreamableClass RProgressBar( TProgressBar::name, TProgressBar::build, __DELTA(TProgressBar) ); #define cpProgressBar "\x04" /* ³ ÀÄÄ Progress Bar Attrib Pair cpProgressBar maps to TProgram::appPalette's index 4 which is, by default, used for the ScrollBar Page. cpProgressBar represents the normal progress bar color. In the constructor the foreground and background attributes are swapped to form the highlight color. Thus the highlight will always be the inverse of the bar color. */ const char * const TProgressBar::name = "TProgressBar"; TProgressBar::TProgressBar(const TRect& bounds, unsigned long aTotal, char abackChar) : TView(bounds) { backChar = abackChar; total = aTotal; numOffset = (size.x/2)-3; bar = new char[size.x+1]; memset(bar,backChar,size.x); bar[size.x] = '\0'; charValue = (double)100/(double)size.x; progress = curPercent = curWidth = 0; } TProgressBar::~TProgressBar(){ delete bar; } void TProgressBar::draw() { char string[4]; sprintf(string,"%d",curPercent); string[3] = '\0'; if(curPercent<10) { string[2] = string[0]; string[1] = string[0] = ' '; } else if(curPercent<100 && curPercent>9) { string[2] = string[1]; string[1] = string[0]; string[0] = ' '; } TDrawBuffer nbuf; uchar colorNormal, colorHiLite; colorNormal = getColor(1); uchar fore = colorNormal >>4; // >>4 is same as /16 colorHiLite = fore+((colorNormal-(fore<<4))<<4); // <<4 is same as *16 nbuf.moveChar(0,backChar,colorNormal,size.x); nbuf.moveStr(numOffset,string,colorNormal); nbuf.moveStr(numOffset+3," %",colorNormal); unsigned i; for(i=0;i> backChar >> total >> progress >> dispLen >> curPercent >> curWidth >> numOffset >> charValue; return this; } TStreamable *TProgressBar::build() { return new TProgressBar( streamableInit ); }