From: Keith F. <ven...@us...> - 2002-11-09 03:22:23
|
Update of /cvsroot/planeshift/planeshift/src/client/gui In directory usw-pr-cvs1:/tmp/cvs-serv29835 Modified Files: psdcredits.h psdcredits.cpp Log Message: Committing res's submitted enhancements to the credits window. Appearing text now "fades in" when it shows up instead of just popping. Also the text is nicely wordwrapped. Thanks res! Index: psdcredits.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/psdcredits.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** psdcredits.h 6 Sep 2002 23:42:16 -0000 1.4 --- psdcredits.h 9 Nov 2002 03:22:19 -0000 1.5 *************** *** 50,65 **** protected: ! //to count trhe time csTicks initialTime; //this is what position to start from when displaying the text int startPos; int pixelAt; //growing array ! CS_TYPEDEF_GROWING_ARRAY (CreditArray, char*); ! CreditArray credits; }; --- 50,85 ---- protected: ! //to count the time csTicks initialTime; + /// This is the big buffer of credit text. + csString mainstring; + + // scroll credits up 1 pixel every n ms + csTicks scrollRate; + + // Y position of first line + int textYofs; + + // number of lines displayed + int numLines; + + // height of the font + int textHeight; + //this is what position to start from when displaying the text int startPos; + // the font used + csRef<iFont> font; + int pixelAt; //growing array ! CS_TYPEDEF_GROWING_ARRAY (creditLines, csString*); ! CS_TYPEDEF_GROWING_ARRAY (creditStyles, int); ! creditLines credits; ! creditStyles styles; }; *************** *** 67,70 **** --- 87,91 ---- #endif // PS_CREDITS_H + Index: psdcredits.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/psdcredits.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** psdcredits.cpp 20 Oct 2002 05:15:50 -0000 1.9 --- psdcredits.cpp 9 Nov 2002 03:22:19 -0000 1.10 *************** *** 28,33 **** --- 28,35 ---- #include <ivideo/graph2d.h> #include <iutil/objreg.h> + #include <csutil/util.h> #include <iutil/vfs.h> #include <cssys/sysfunc.h> + #include <qint.h> // PS include *************** *** 39,46 **** #include "iclient/isoundmngr.h" //------------------------------------------------------------------- bool psdCredits::Initialize() { - float ratiox = (float)width / 640.0f; float ratioy = (float)height / 480.0f; --- 41,55 ---- #include "iclient/isoundmngr.h" + const int textArea_X1 = 150; + const int textArea_Y1 = 150; + const int textArea_X2 = 490; + const int textArea_Y2 = 350; + + // how long does it take for a single line to travel one line up? (ms) + const int lineTravelTime = 1000; + //------------------------------------------------------------------- bool psdCredits::Initialize() { float ratiox = (float)width / 640.0f; float ratioy = (float)height / 480.0f; *************** *** 84,127 **** } */ csRef<iVFS> vfs = CS_QUERY_REGISTRY (dmanager->GetObjectRegistry(), iVFS); ! if(!vfs) return false; csRef<iFile> file = vfs->Open("this/docs/credit.txt",'r'); ! if(!file) return false; ! char *name = new char[53]; ! int count =0; ! while(! file->AtEOF() ) { ! char dat[1]; ! file->Read(dat,1); ! name[count++] = dat[0]; ! if(dat[0] == '\r' || dat[0] == '\t') { ! name[count-1] = ' '; } ! if(!(count < 52)) ! { ! name[count] = '\0'; ! credits.Push(name); ! name = new char[53]; ! count =0; ! } ! else if(dat[0] == '\n') { ! name[count-1] = '\0'; ! credits.Push(name); ! name = new char[53]; ! count =0; } } - initialTime = csGetTicks(); - startPos =0; - pixelAt =0; return true; } --- 93,173 ---- } */ + font = dmanager->GetDefaultFont(); csRef<iVFS> vfs = CS_QUERY_REGISTRY (dmanager->GetObjectRegistry(), iVFS); ! if (!vfs) ! return false; csRef<iFile> file = vfs->Open("this/docs/credit.txt",'r'); ! if (!file) ! return false; ! // read the raw, unformatted lines from the credits, split into words. ! char buf[512]; ! size_t readsize; ! ! do { ! readsize = file->Read(buf, 512); ! mainstring.Append(buf, readsize); ! } while (readsize == 512); ! int cur=0; ! const char *dat = mainstring.GetData(); ! ! while (cur<mainstring.Length() ) ! { ! if (mainstring.GetAt(cur) == '@') { ! styles.Push(1); ! cur++; // skip formatting character ! } ! else if (mainstring.GetAt(cur) == '&') ! { ! styles.Push(2); ! cur++; // skip formatting character } + else + styles.Push(0); ! size_t len = strcspn (dat+cur, "\n"); ! unsigned int maxlen = font->GetLength(dat+cur, RX(textArea_X2 - textArea_X1) ); ! ! // only break line after words ! if (maxlen < len) { ! len = maxlen; ! ! // go back to last complete word ! while (!isspace(*(dat+cur+len))) ! { ! if (--len == 0) ! { ! len=maxlen + 1; ! break; ! } ! } } + if (cur+len < mainstring.Length()) + mainstring[cur+len] = 0; + csString *newstr = new csString(dat+cur); + credits.Push(newstr); + cur += len+1; } + int w; + font->GetMaxSize (w, textHeight); + + int textAreaHeight = RY(textArea_Y2 - textArea_Y1); + numLines = textAreaHeight / textHeight; + textYofs = RY(textArea_Y1) + (textAreaHeight - numLines * textHeight) / 2; + + scrollRate = lineTravelTime / textHeight; + + startPos = -numLines + 1; + pixelAt = 0; + + initialTime = csGetTicks(); return true; } *************** *** 143,152 **** float ratioy = (float)height / 480.0f; ! if( csGetTicks() - initialTime >= 150 ) { initialTime = csGetTicks(); ! if( pixelAt++ == 10 ) { ! pixelAt =0; startPos++; } --- 189,198 ---- float ratioy = (float)height / 480.0f; ! if( csGetTicks() - initialTime >= scrollRate ) { initialTime = csGetTicks(); ! if( pixelAt++ == textHeight ) { ! pixelAt = 0; startPos++; } *************** *** 163,188 **** else { ! for( int i =0; i < 20 && i+startPos < credits.Length(); i++ ) { ! int c = -1; ! int offset = 0; ! if( credits[i+startPos][0] == '@' ) ! { ! c = GetDialogManager()->GetG2D()->FindRGB(255,50,50); ! offset =1; ! } ! else if( credits[i+startPos][0] == '&' ) ! { ! c = GetDialogManager()->GetG2D()->FindRGB(50,50,255); ! offset =1; ! } ! else ! { ! c = GetDialogManager()->GetG2D()->FindRGB(0,0,0); ! offset = 0; ! } ! g2d->Write(GetDialogManager()->GetDefaultFont(), ! RX(150), RY(150+i*10-pixelAt) , c, -1, credits[i+startPos]+offset); } } --- 209,269 ---- else { ! for( int i = 0; i < numLines && i+startPos < credits.Length(); i++ ) { ! const float cbgR = 187.0f; ! const float cbgG = 186.0f; ! const float cbgB = 181.0f; ! int c = -1; ! int cR, cG, cB; ! ! if (i+startPos >= 0) ! { ! csString* line = credits.Get(i+startPos); ! ! if (styles[i+startPos] == 1) ! { ! cR = 255; ! cG = 50; ! cB = 50; ! } ! else if (styles[i+startPos] == 2) ! { ! cR = 50; ! cG = 50; ! cB = 255; ! } ! else ! { ! cR = 0; ! cG = 0; ! cB = 0; ! } ! ! if (i == 0) ! { ! float ratio = (float)pixelAt / (float)textHeight; ! ! cR = QInt ((float)cR * (1-ratio) + cbgR * ratio); ! cG = QInt ((float)cG * (1-ratio) + cbgG * ratio); ! cB = QInt ((float)cB * (1-ratio) + cbgB * ratio); ! } ! else if (i == numLines - 1) ! { ! float ratio = (float)pixelAt / (float)textHeight; ! ! cR = QInt ((float)cR * ratio + cbgR * (1-ratio)); ! cG = QInt ((float)cG * ratio + cbgG * (1-ratio)); ! cB = QInt ((float)cB * ratio + cbgB * (1-ratio)); ! } ! ! c = GetDialogManager()->GetG2D()->FindRGB(cR, cG, cB); ! ! g2d->Write(font, ! RX(textArea_X1), ! textYofs+i*textHeight-pixelAt, ! c, -1, ! line->GetData() ); ! } } } *************** *** 191,196 **** psdCredits::~ psdCredits() { ! for( int i=0; i < credits.Length(); i++) ! delete[] credits[i]; } - --- 272,278 ---- psdCredits::~ psdCredits() { ! for( int i = 0; i < credits.Length(); i++) ! { ! delete credits[i]; ! } } |