src/render/rFont.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_FONT_H
00029 #define ArmageTron_FONT_H
00030 
00031 #include "rSDL.h"
00032 
00033 #include "defs.h"
00034 //#include "rTexture.h"
00035 #include "tString.h"
00036 #include "tColor.h"
00037 
00038 #include <map>
00039 
00041 enum sr_fontClass {
00042     sr_fontConsole       = 00001, 
00043     sr_fontMenu          = 00002, 
00044     sr_fontMenuTitle     = 00004, 
00045     sr_fontScoretable    = 00010, 
00046     sr_fontMenuHelp      = 00020, 
00047     sr_fontError         = 00040, 
00048     sr_fontCockpit       = 00100, 
00049     sr_fontCenterMessage = 00200, 
00050     sr_fontServerBrowser = 00400, 
00051     sr_fontCycleLabel    = 01000, 
00052     sr_fontServerDetails = 02000  
00053 };
00054 
00056 enum sr_fontTypes {
00057     sr_fontOld       = 0, 
00058     sr_fontPixmap    = 1, 
00059     sr_fontBitmap    = 2, 
00060     sr_fontTexture   = 3, 
00061     sr_fontPolygon   = 4, 
00062     sr_fontOutline   = 5, 
00063     sr_fontExtruded  = 6  
00064 };
00065 
00066 extern int sr_fontType;
00067 
00068 class FTFont;
00069 
00070 // maybe make this a child of std::ostream...
00071 class rTextField{
00072     tString buffer;       // buffer where we store stuff before we print it
00073     float  width;          // width in openGL units
00074     int  parIndent;      // number of spaces to insert after automatic newline
00075     REAL left,top;       // top left corner of the console
00076     REAL cheight; // character dimensions
00077     //    rFont *F;             // the font
00078     int  x,y,realx;      // current cursor position
00079     float nextx;          // x-coordinate the next char should go to for rendering
00080     float currentWidth;   //The current position where the next char will go to for caching
00081     bool multiline;        // linewrapping enabled?
00082     FTFont *font;
00083     sr_fontClass type;    //what is the type of this font?
00084 
00085     tColor color_;               
00086     static tColor defaultColor_; 
00087     static tColor blendColor_;   
00088 
00089     int cursor; // display mode of the cursor; 0: disabled, 1: low, 2: high
00090     int cursorPos; // position of the cursor (number of chars to come)
00091 
00092     REAL cursor_x,cursor_y; // position on the screen
00093 
00094     void FlushLine(int len,bool newline=true);
00095     void FlushLine(bool newline=true);
00096 public:
00097 #define  rCWIDTH_NORMAL  (16/640.0)
00098 #define  rCHEIGHT_NORMAL (32/480.0)
00099 
00100     rTextField(REAL Left,REAL Top,
00101                REAL Cheight, sr_fontClass Type);
00102 
00103     virtual ~rTextField(); // for future extensions (buffered console?)
00104 
00105     REAL GetCHeight() const {
00106         return cheight;
00107     }
00108 
00109    void SetTop( REAL t ){
00110         top = t;
00111     }
00112 
00113     void SetLeft( REAL l ){
00114         top = l;
00115     }
00116     
00117     REAL GetTop() const{
00118         return top;
00119     }
00120 
00121     REAL GetLeft() const{
00122         return left;
00123     }
00124 
00125     void SetWidth(float w){
00126         width=w;
00127     }
00128 
00129     float GetWidth() const {
00130         return width;
00131     }
00132 
00133     void SetIndent(int i){
00134         parIndent=i;
00135     }
00136 
00137     int GetIndent() const {
00138         return parIndent;
00139     }
00140 
00141     void SetCursor(int c,int p){
00142         cursor=c;
00143         cursorPos=p;
00144     }
00145 
00146     void ResetColor(){
00147         FlushLine(false);
00148         color_ = defaultColor_;
00149     }
00150 
00151     void EnableLineWrap() {
00152         multiline = true;
00153     }
00154 
00155     // rTextField & operator<<(unsigned char c);
00156 
00157     enum ColorMode {
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     };
00162 
00163     rTextField & StringOutput(const char *c, ColorMode colorMode = COLOR_USE );
00164 
00165     int Lines(){
00166         return y;
00167     }
00168 
00169     inline rTextField & SetColor( tColor const & color );       
00170     inline tColor const & GetColor( void ) const;       
00171     inline rTextField const & GetColor( tColor & color ) const; 
00172     static void SetDefaultColor( tColor const & defaultColor ); 
00173     static tColor const & GetDefaultColor( void );      
00174     static void GetDefaultColor( tColor & defaultColor );       
00175     static void SetBlendColor( tColor const & blendColor );     
00176     static tColor const & GetBlendColor( void );        
00177     static void GetBlendColor( tColor & blendColor );   
00178 
00179     static float GetTextLength (tString const &str, float height, bool stripColors=false, bool useNewline=true, float *resultingHeight=0); 
00180 
00181 private:
00182     inline void WriteChar(unsigned char c); 
00183 };
00184 
00185 template<class T> rTextField & operator<<(rTextField &c,const T &x){
00186     tColoredString out;
00187     out << x;
00188     return c.StringOutput(out);
00189 }
00190 
00191 void DisplayText(REAL x,REAL y,REAL h,const char *text, sr_fontClass type,int center=0,
00192                  int cursor=0,int cursorPos=0, rTextField::ColorMode colorMode = rTextField::COLOR_USE );
00193 
00194 // *******************************************************************************************
00195 // *
00196 // *    GetColor
00197 // *
00198 // *******************************************************************************************
00202 // *******************************************************************************************
00203 
00204 tColor const & rTextField::GetColor( void ) const
00205 {
00206     return this->color_;
00207 }
00208 
00209 // *******************************************************************************************
00210 // *
00211 // *    GetColor
00212 // *
00213 // *******************************************************************************************
00218 // *******************************************************************************************
00219 
00220 rTextField const & rTextField::GetColor( tColor & color ) const
00221 {
00222     color = this->color_;
00223     return *this;
00224 }
00225 
00226 // *******************************************************************************************
00227 // *
00228 // *    SetColor
00229 // *
00230 // *******************************************************************************************
00235 // *******************************************************************************************
00236 
00237 rTextField & rTextField::SetColor( tColor const & color )
00238 {
00239     this->color_ = color;
00240     return *this;
00241 }
00243 void sr_ReloadFont(void);
00244 
00245 #endif
00246 

Generated on Sat Mar 15 22:55:52 2008 for Armagetron Advanced by  doxygen 1.5.4