rTextField Class Reference

#include <rFont.h>

Collaboration diagram for rTextField:

Collaboration graph
[legend]

List of all members.

Public Types

enum  ColorMode { COLOR_IGNORE, COLOR_USE, COLOR_SHOW }

Public Member Functions

 rTextField (REAL Left, REAL Top, REAL Cheight, sr_fontClass Type)
virtual ~rTextField ()
REAL GetCHeight () const
void SetTop (REAL t)
void SetLeft (REAL l)
REAL GetTop () const
REAL GetLeft () const
void SetWidth (float w)
float GetWidth () const
void SetIndent (int i)
int GetIndent () const
void SetCursor (int c, int p)
void ResetColor ()
void EnableLineWrap ()
rTextFieldStringOutput (const char *c, ColorMode colorMode=COLOR_USE)
int Lines ()
rTextFieldSetColor (tColor const &color)
 Sets current color.
tColor const & GetColor (void) const
 Gets current color.
rTextField const & GetColor (tColor &color) const
 Gets current color.

Static Public Member Functions

static void SetDefaultColor (tColor const &defaultColor)
 Sets default color.
static tColor const & GetDefaultColor (void)
 Gets default color.
static void GetDefaultColor (tColor &defaultColor)
 Gets default color.
static void SetBlendColor (tColor const &blendColor)
 Sets color all other colors are multiplied with.
static tColor const & GetBlendColor (void)
 Gets color all other colors are multiplied with.
static void GetBlendColor (tColor &blendColor)
 Gets color all other colors are multiplied with.
static float GetTextLength (tString const &str, float height, bool stripColors=false, bool useNewline=true, float *resultingHeight=0)
 Predict the dimenstions of a string.

Private Member Functions

void FlushLine (int len, bool newline=true)
void FlushLine (bool newline=true)
void WriteChar (unsigned char c)
 writes a single character as it is, no automatic newline breaking

Private Attributes

tString buffer
float width
int parIndent
REAL left
REAL top
REAL cheight
int x
int y
int realx
float nextx
float currentWidth
bool multiline
FTFont * font
sr_fontClass type
tColor color_
 current color
int cursor
int cursorPos
REAL cursor_x
REAL cursor_y

Static Private Attributes

static tColor defaultColor_
 default color
static tColor blendColor_
 color all other colors are multiplied with


Detailed Description

Definition at line 71 of file rFont.h.


Member Enumeration Documentation

enum rTextField::ColorMode

Enumerator:
COLOR_IGNORE 
COLOR_USE 
COLOR_SHOW 

Definition at line 157 of file rFont.h.

00157                    {
00158         COLOR_IGNORE,   // ignore color codes, printing everything verbatim
00159         COLOR_USE,      // normal mode: hide color codes and use them
00160         COLOR_SHOW      // use color codes, but print them as well
00161     };


Constructor & Destructor Documentation

rTextField::rTextField ( REAL  Left,
REAL  Top,
REAL  Cheight,
sr_fontClass  Type 
)

Definition at line 364 of file rFont.cpp.

References cheight, color_, cursor_x, cursor_y, defaultColor_, REAL, sr_screenHeight, and width.

00366         :parIndent(0),
00367 left(Left),top(Top),cheight(Cheight),x(0),y(0),realx(0),nextx(Left),currentWidth(0),multiline(false),type(Type),cursor(0),cursorPos(0){
00368     if (cheight*sr_screenHeight<18)
00369     {
00370         cheight=18/REAL(sr_screenHeight);
00371     }
00372 
00373     color_ = defaultColor_;
00374 
00375     width = 1.-Left;
00376 
00377     /*
00378     top=(int(top*sr_screenHeight)+.5)/REAL(sr_screenHeight);
00379     left=(int(left*sr_screenWidth)+.5)/REAL(sr_screenWidth);
00380     */
00381 
00382     cursor_x = -100;
00383     cursor_y = -100;
00384 }

rTextField::~rTextField (  )  [virtual]

Definition at line 387 of file rFont.cpp.

References BeginLines(), cheight, cursor, cursor_x, cursor_y, FlushLine(), RenderEnd(), and sr_glOut.

00387                        {
00388     FlushLine();
00389 
00390 #ifndef DEDICATED
00391     if (cursor && sr_glOut){
00392         if (cursor==2)
00393             glColor4f(1,1,1,.5);
00394         else
00395             glColor3f(1,1,0);
00396 
00397         //    glDisable(GL_TEXTURE);
00398         glDisable(GL_TEXTURE_2D);
00399 
00400         BeginLines();
00401         glVertex2f(cursor_x,cursor_y);
00402         glVertex2f(cursor_x,cursor_y-cheight);
00403         RenderEnd();
00404     }
00405 #endif
00406 }

Here is the call graph for this function:


Member Function Documentation

void rTextField::FlushLine ( int  len,
bool  newline = true 
) [private]

Definition at line 415 of file rFont.cpp.

References a, tColor::a_, b, tColor::b_, rFontContainer::BBox(), BeginQuads(), blendColor_, buffer, cheight, color_, cursor_x, cursor_y, cursorPos, tColor::g_, rFontContainer::GetWidth(), left, nextx, tColor::r_, REAL, realx, rFontContainer::Render(), RenderEnd(), sr_alphaBlend, sr_glOut, sr_minG, sr_minTotal, tString::SubStr(), top, x, and y.

Referenced by FlushLine(), ResetColor(), StringOutput(), WriteChar(), and ~rTextField().

00415                                               {
00416 #ifndef DEDICATED
00417     float realTop = top-y*cheight;
00418     tString str(buffer.SubStr(realx, len));
00419     realx += len;
00420     if (len >= cursorPos && cursorPos >= 0) {
00421         cursor_y=realTop;
00422         cursor_x=nextx+sr_Font.GetWidth(str.SubStr(0, cursorPos), cheight);
00423     }
00424     cursorPos -= len+1;
00425     float thisx = nextx+sr_Font.GetWidth(str, cheight);
00426 
00427     REAL r = color_.r_;
00428     REAL g = color_.g_;
00429     REAL b = color_.b_;
00430     REAL a = color_.a_;
00431 
00432     if (sr_glOut)
00433     {
00434         // render bright background
00435         if ( r < sr_minR && g < sr_minG && b < sr_minG || r+g+b < sr_minTotal )
00436         {
00437             if ( sr_alphaBlend && !str.empty() )
00438             {
00439 
00440                 glDisable(GL_TEXTURE_2D);
00441 
00442                 glColor4f( blendColor_.r_, blendColor_.g_, blendColor_.b_, a * blendColor_.a_ );
00443 
00444                 float l,t,r,b;
00445 
00446                 sr_Font.BBox(str, cheight, tCoord(nextx, realTop-cheight), l, b, r, t);
00447 
00448                 //sr_ResetRenderState(true);
00449 
00450                 BeginQuads();
00451 
00452                 glVertex2f(   l, b);
00453 
00454                 glVertex2f(   r, b);
00455 
00456                 glVertex2f(   r ,t);
00457 
00458                 glVertex2f(   l, t);
00459                 RenderEnd();
00460             }
00461             else
00462             {
00463                 if ( r < .5 ) r = .5;
00464                 if ( g < .5 ) g = .5;
00465                 if ( b < .5 ) b = .5;
00466             }
00467         }
00468 
00469         glColor4f(r * blendColor_.r_,g * blendColor_.g_,b * blendColor_.b_,a * blendColor_.a_);
00470     }
00471 
00472     //F->Render(buffer[realx],l,t,l+cwidth,t-cheight);
00473     glRasterPos2f(nextx, realTop-cheight);
00474     sr_Font.Render(str, cheight, tCoord(nextx, realTop-cheight));
00475     nextx = thisx;
00476 
00477 #endif
00478     /*
00479     for(i=0;i<buffer.Len()-len;i++)
00480       buffer[i]=buffer[i+len];
00481 
00482     buffer.SetLen(buffer.Len()-len);
00483     */
00484 
00485     if (newline){
00486         y++;
00487         realx=x=0;
00488         nextx=left;
00489     }
00490     else
00491     {
00492         //      realx = 0;
00493         //      buffer.SetLen(0);
00494     }
00495     //    x+=len;
00496 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rTextField::FlushLine ( bool  newline = true  )  [private]

Definition at line 498 of file rFont.cpp.

References buffer, FlushLine(), realx, and tString::Size().

00498                                       {
00499     FlushLine(buffer.Size()-realx,newline);
00500 }

Here is the call graph for this function:

REAL rTextField::GetCHeight (  )  const [inline]

Definition at line 105 of file rFont.h.

References cheight.

00105                             {
00106         return cheight;
00107     }

void rTextField::SetTop ( REAL  t  )  [inline]

Definition at line 109 of file rFont.h.

References top.

00109                         {
00110         top = t;
00111     }

void rTextField::SetLeft ( REAL  l  )  [inline]

Definition at line 113 of file rFont.h.

References top.

00113                           {
00114         top = l;
00115     }

REAL rTextField::GetTop (  )  const [inline]

Definition at line 117 of file rFont.h.

References top.

00117                        {
00118         return top;
00119     }

REAL rTextField::GetLeft (  )  const [inline]

Definition at line 121 of file rFont.h.

References left.

00121                         {
00122         return left;
00123     }

void rTextField::SetWidth ( float  w  )  [inline]

Definition at line 125 of file rFont.h.

References width.

Referenced by DisplayText(), uMenu::OnEnter(), and rConsole::Render().

00125                           {
00126         width=w;
00127     }

Here is the caller graph for this function:

float rTextField::GetWidth (  )  const [inline]

Definition at line 129 of file rFont.h.

References width.

00129                            {
00130         return width;
00131     }

void rTextField::SetIndent ( int  i  )  [inline]

Definition at line 133 of file rFont.h.

References parIndent.

Referenced by DisplayText(), rConsole::Render(), and welcome().

00133                          {
00134         parIndent=i;
00135     }

Here is the caller graph for this function:

int rTextField::GetIndent (  )  const [inline]

Definition at line 137 of file rFont.h.

References parIndent.

00137                           {
00138         return parIndent;
00139     }

void rTextField::SetCursor ( int  c,
int  p 
) [inline]

Definition at line 141 of file rFont.h.

References cursor, and cursorPos.

Referenced by DisplayText().

00141                                {
00142         cursor=c;
00143         cursorPos=p;
00144     }

Here is the caller graph for this function:

void rTextField::ResetColor (  )  [inline]

Definition at line 146 of file rFont.h.

References color_, defaultColor_, and FlushLine().

Referenced by rConsole::Render().

00146                      {
00147         FlushLine(false);
00148         color_ = defaultColor_;
00149     }

Here is the call graph for this function:

Here is the caller graph for this function:

void rTextField::EnableLineWrap (  )  [inline]

Definition at line 151 of file rFont.h.

References multiline.

Referenced by uMenu::Message(), uMenu::OnEnter(), rConsole::Render(), and gServerMenuItem::RenderBackground().

00151                           {
00152         multiline = true;
00153     }

Here is the caller graph for this function:

rTextField & rTextField::StringOutput ( const char *  c,
ColorMode  colorMode = COLOR_USE 
)

Definition at line 576 of file rFont.cpp.

References tColor::b_, cheight, color_, COLOR_IGNORE, COLOR_USE, CTR(), currentWidth, cursorPos, defaultColor_, FlushLine(), tColor::g_, rFontContainer::GetWidth(), hex_to_int(), isblank(), multiline, parIndent, tColor::r_, width, and WriteChar().

Referenced by DisplayText(), and operator<<().

00577 {
00578 #ifndef DEDICATED
00579     //float currentWidth = nextx - left;
00580     float const &maxWidth = width;
00581     bool lastIsNewline = true;
00582     bool trouble = false; // Do we have a word that won't fit on a line?
00583     static tString spaces;
00584     // run through string
00585     while (*c!='\0')
00586     {
00587         if (trouble && !(*c=='0' && strlen(c)>=8 && c[1]=='x' && colorMode != COLOR_IGNORE)) {
00588             tString str;
00589             str << *c;
00590             currentWidth += sr_Font.GetWidth(str, cheight);
00591             if(isspace(*c)) {
00592                 trouble = false;
00593             } else if ( currentWidth >= maxWidth) {
00594                 WriteChar('\n');
00595                 spaces.clear();
00596                 for ( int i = parIndent-1; i >= 0; --i )
00597                 {
00598                     WriteChar(' ');
00599                     spaces << ' ';
00600                     cursorPos++;
00601                 }
00602                 currentWidth = sr_Font.GetWidth(spaces, cheight);
00603             }
00604         }
00605         // break line if next space character is too far away
00606         if ( !trouble && multiline && (isblank(*c) || lastIsNewline) )
00607         {
00608             lastIsNewline = false;
00609             // count number of nonblank characters following
00610             char const * nextSpace = c+1;
00611             int wordLen = 0;
00612             while ( *nextSpace != '\0' && *nextSpace != '\n' && !isblank(*nextSpace) )
00613             {
00614                 if (*nextSpace=='0' && strlen(nextSpace)>=8 && nextSpace[1]=='x' && colorMode != COLOR_IGNORE )
00615                 {
00616                     // skip color code
00617                     nextSpace += 8;
00618                 }
00619                 else
00620                 {
00621                     // count letter
00622                     nextSpace++;
00623                     wordLen++;
00624                 }
00625             }
00626             tString str(c, nextSpace);
00627             str = tColoredString::RemoveColors(str.c_str());
00628             float wordWidth = sr_Font.GetWidth(str, cheight);
00629 
00630             currentWidth += wordWidth;
00631             if ( currentWidth >= maxWidth)
00632             {
00633                 WriteChar('\n');
00634                 c++;
00635 
00636                 spaces.clear();
00637                 for ( int i = parIndent-1; i >= 0; --i )
00638                 {
00639                     WriteChar(' ');
00640                     spaces << ' ';
00641                     cursorPos++;
00642                 }
00643                 float spaceWidth = sr_Font.GetWidth(spaces, cheight);
00644 
00645                 if (wordWidth >= maxWidth) {
00646                     trouble = true;
00647                     currentWidth = spaceWidth;
00648                 } else {
00649                     currentWidth = wordWidth + spaceWidth;
00650                 }
00651                 continue;
00652             }
00653         }
00654         if ( *c == '\n' ) {
00655             lastIsNewline = true;
00656             currentWidth = 0.;
00657             cursorPos += 1;
00658         }
00659 
00661         //if ( x >= width )
00662         //{
00663         //    WriteChar('\n');
00664         //    currentWidth = 0.;
00665         //}
00666 
00667         // detect presence of color code
00668         if (*c=='0' && strlen(c)>=8 && c[1]=='x' && colorMode != COLOR_IGNORE )
00669         {
00670             tColor color;
00671             bool use = false;
00672 
00673             if ( 0 ==strncmp(c,"0xRESETT",8) )
00674             {
00675                 // color reset to default requested
00676                 color = defaultColor_;
00677                 use = true;
00678             }
00679             else
00680             {
00681                 // found! extract colors
00682                 cursorPos-=8;
00683                 color.r_=CTR(hex_to_int(c[2])*16+hex_to_int(c[3]));
00684                 color.g_=CTR(hex_to_int(c[4])*16+hex_to_int(c[5]));
00685                 color.b_=CTR(hex_to_int(c[6])*16+hex_to_int(c[7]));
00686                 use = true;
00687             }
00688 
00689             // advance
00690             if ( colorMode == COLOR_USE )
00691             {
00692                 c+=8;
00693             }
00694             else
00695             {
00696                 // write color code out
00697                 cursorPos+=8;
00698                 for(int i=7; i>=0;--i)
00699                     WriteChar(*(c++));
00700             }
00701 
00702             // apply color
00703             if ( use )
00704             {
00705                 FlushLine(false);
00706                 cursorPos++;
00707                 color_ = color;
00708             }
00709         }
00710         else
00711             // normal operation: add char
00712             WriteChar(*(c++));
00713     }
00714 #endif
00715     return *this;
00716 }

Here is the call graph for this function:

Here is the caller graph for this function:

int rTextField::Lines (  )  [inline]

Definition at line 165 of file rFont.h.

References y.

Referenced by rConsole::Render().

00165                {
00166         return y;
00167     }

Here is the caller graph for this function:

rTextField & rTextField::SetColor ( tColor const &  color  )  [inline]

Sets current color.

Parameters:
color current color to set
Returns:
A reference to this to allow chaining

Definition at line 237 of file rFont.h.

References color_.

00238 {
00239     this->color_ = color;
00240     return *this;
00241 }

tColor const & rTextField::GetColor ( void   )  const [inline]

Gets current color.

Returns:
current color

Definition at line 204 of file rFont.h.

References color_.

00205 {
00206     return this->color_;
00207 }

rTextField const & rTextField::GetColor ( tColor color  )  const [inline]

Gets current color.

Parameters:
color current color to fill
Returns:
A reference to this to allow chaining

Definition at line 220 of file rFont.h.

References color_.

00221 {
00222     color = this->color_;
00223     return *this;
00224 }

void rTextField::SetDefaultColor ( tColor const &  defaultColor  )  [static]

Sets default color.

Parameters:
defaultColor default color to set

Definition at line 783 of file rFont.cpp.

References blendColor_, and defaultColor_.

Referenced by uMenu::Message(), uMenu::OnEnter(), rConsole::Render(), gBrowserMenuItem::RenderBackground(), gServerMenuItem::RenderBackground(), and uMenuItem::SetColor().

00784 {
00785     defaultColor_ = defaultColor;
00786     blendColor_ = tColor();
00787 }

Here is the caller graph for this function:

tColor const & rTextField::GetDefaultColor ( void   )  [static]

Gets default color.

Returns:
default color

Definition at line 753 of file rFont.cpp.

References defaultColor_.

00754 {
00755     return defaultColor_;
00756 }

void rTextField::GetDefaultColor ( tColor defaultColor  )  [static]

Gets default color.

Parameters:
defaultColor default color to fill

Definition at line 768 of file rFont.cpp.

References defaultColor_.

00769 {
00770     defaultColor = defaultColor_;
00771 }

void rTextField::SetBlendColor ( tColor const &  blendColor  )  [static]

Sets color all other colors are multiplied with.

Parameters:
blendColor color all other colors are multiplied with to set

Definition at line 829 of file rFont.cpp.

References blendColor_.

Referenced by uMenu::Message(), uMenu::OnEnter(), and uMenuItem::SetColor().

00830 {
00831     blendColor_ = blendColor;
00832 }

Here is the caller graph for this function:

tColor const & rTextField::GetBlendColor ( void   )  [static]

Gets color all other colors are multiplied with.

Returns:
color all other colors are multiplied with

Definition at line 799 of file rFont.cpp.

References blendColor_.

00800 {
00801     return blendColor_;
00802 }

void rTextField::GetBlendColor ( tColor blendColor  )  [static]

Gets color all other colors are multiplied with.

Parameters:
blendColor color all other colors are multiplied with to fill

Definition at line 814 of file rFont.cpp.

References blendColor_.

00815 {
00816     blendColor = blendColor_;
00817 }

float rTextField::GetTextLength ( tString const &  str,
float  height,
bool  stripColors = false,
bool  useNewline = true,
float *  resultingHeight = 0 
) [static]

Predict the dimenstions of a string.

Parameters:
str the string to be used
height the height of one character
stripColors should colors be recognized?
useNewline should newlines be recognized (and the longest line be found)?
resultingHeight address to store the number of lines (height times the number of newlines+1)
Returns:
the width of the string if it was printed

Definition at line 844 of file rFont.cpp.

References rFontContainer::GetWidth(), and height.

Referenced by uMenuItem::DisplayText(), DisplayText(), and cWidget::Label::Render().

00844                                                                                                                             {
00845     if(stripColors) {
00846         return sr_Font.GetWidth(tColoredString::RemoveColors(str.c_str()), height); //TODO: Implement all the rest!
00847     }
00848     return sr_Font.GetWidth(str, height); //TODO: Implement all the rest!
00849 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rTextField::WriteChar ( unsigned char  c  )  [inline, private]

writes a single character as it is, no automatic newline breaking

Definition at line 502 of file rFont.cpp.

References buffer, tString::Clear(), FlushLine(), and x.

Referenced by StringOutput().

00503 {
00504     switch (c){
00505     case('\n'):
00506                     FlushLine();
00507         buffer.Clear();
00508         break;
00509     default:
00510         buffer += c;
00511         x++;
00512         break;
00513     }
00514 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tString rTextField::buffer [private]

Definition at line 72 of file rFont.h.

Referenced by FlushLine(), and WriteChar().

float rTextField::width [private]

Definition at line 73 of file rFont.h.

Referenced by DisplayText(), GetWidth(), rTextField(), SetWidth(), and StringOutput().

int rTextField::parIndent [private]

Definition at line 74 of file rFont.h.

Referenced by GetIndent(), SetIndent(), and StringOutput().

REAL rTextField::left [private]

Definition at line 75 of file rFont.h.

Referenced by FlushLine(), and GetLeft().

REAL rTextField::top [private]

Definition at line 75 of file rFont.h.

Referenced by FlushLine(), GetTop(), SetLeft(), and SetTop().

REAL rTextField::cheight [private]

Definition at line 76 of file rFont.h.

Referenced by FlushLine(), GetCHeight(), rTextField(), StringOutput(), and ~rTextField().

int rTextField::x [private]

Definition at line 78 of file rFont.h.

Referenced by FlushLine(), and WriteChar().

int rTextField::y [private]

Definition at line 78 of file rFont.h.

Referenced by FlushLine(), and Lines().

int rTextField::realx [private]

Definition at line 78 of file rFont.h.

Referenced by FlushLine().

float rTextField::nextx [private]

Definition at line 79 of file rFont.h.

Referenced by FlushLine().

float rTextField::currentWidth [private]

Definition at line 80 of file rFont.h.

Referenced by StringOutput().

bool rTextField::multiline [private]

Definition at line 81 of file rFont.h.

Referenced by EnableLineWrap(), and StringOutput().

FTFont* rTextField::font [private]

Definition at line 82 of file rFont.h.

sr_fontClass rTextField::type [private]

Definition at line 83 of file rFont.h.

tColor rTextField::color_ [private]

current color

Definition at line 85 of file rFont.h.

Referenced by FlushLine(), GetColor(), ResetColor(), rTextField(), SetColor(), and StringOutput().

tColor rTextField::defaultColor_ [static, private]

default color

Definition at line 86 of file rFont.h.

Referenced by GetDefaultColor(), ResetColor(), rTextField(), SetDefaultColor(), and StringOutput().

tColor rTextField::blendColor_ [static, private]

color all other colors are multiplied with

Definition at line 87 of file rFont.h.

Referenced by FlushLine(), GetBlendColor(), SetBlendColor(), and SetDefaultColor().

int rTextField::cursor [private]

Definition at line 89 of file rFont.h.

Referenced by SetCursor(), and ~rTextField().

int rTextField::cursorPos [private]

Definition at line 90 of file rFont.h.

Referenced by FlushLine(), SetCursor(), and StringOutput().

REAL rTextField::cursor_x [private]

Definition at line 92 of file rFont.h.

Referenced by FlushLine(), rTextField(), and ~rTextField().

REAL rTextField::cursor_y [private]

Definition at line 92 of file rFont.h.

Referenced by FlushLine(), rTextField(), and ~rTextField().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:54:18 2008 for Armagetron Advanced by  doxygen 1.5.4