Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

TEXT.C File Reference

#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "Text.h"
#include "Errorlog.h"

Go to the source code of this file.

Compounds

struct  Font_Type

Defines

#define MAX_SUPPORTED_CHARS   128

Functions

geBoolean Text_Create (geEngine *SaveEngine)
geBoolean Text_Destroy (void)
geBoolean Text_Out (char *Text, FontType FontNum, int32 x, int32 y, FontStyle Style)
int32 Text_GetWidth (FontType Font)
int32 Text_GetHeight (FontType Font)

Variables

char * Dir = "Bmp\\"
char * Ext = ".Bmp"
geEngineEngine = NULL
Font_Type Fonts [MAX_FONTS]
int32 FontLookup [MAX_SUPPORTED_CHARS]
char FontNames [MAX_FONTS][100]
geVFileMainFS


Define Documentation

#define MAX_SUPPORTED_CHARS   128
 

Definition at line 22 of file TEXT.C.

Referenced by Text_Create(), and Text_Out().


Function Documentation

geBoolean Text_Create geEngine SaveEngine  ) 
 

Definition at line 66 of file TEXT.C.

References Font_Type::AddHeight, Font_Type::AddWidth, Font_Type::Bitmap, Dir, Engine, Ext, Font_Small, Font_Type::FontHeight, FontLookup, FontNames, Fonts, Font_Type::FontWidth, GE_FALSE, GE_TRUE, GE_VFILE_OPEN_READONLY, geBitmap_CreateFromFile(), geBitmap_SetColorKey(), geBoolean, geEngine_AddBitmap(), geErrorLog_AddString, geVFile_Close(), geVFile_Open(), int32, MainFS, MAX_FONTS, MAX_SUPPORTED_CHARS, and NULL.

Referenced by WinMain().

00068 {
00069 
00070         // locals
00071         char            Filename[64];
00072         int32           i, PosX, PosY;
00073         int32           Width;
00074         geVFile *               File;
00075 
00076         // fail if we have an invalid engine pointer
00077         if ( SaveEngine == NULL )
00078         {
00079                 assert( 0 );
00080                 return GE_FALSE;
00081         }
00082 
00083         // setup font character lookup table
00084         PosX = 0;
00085         PosY = 0;
00086         Width = 17 * 15;
00087         for ( i = 0; i < MAX_SUPPORTED_CHARS; i++ )
00088         {
00089                 FontLookup[i] = ( PosX << 16 ) | PosY;
00090                 PosX += 17;
00091 
00092                 if ( PosX >= Width )
00093                 {
00094                         PosY += 17;
00095                         PosX = 0;
00096                 }
00097         }
00098 
00099         // setup all fonts (fail if we can't)
00100         for ( i = 0; i < MAX_FONTS; i++ )
00101         {
00102                 //geBitmap      *Pal;
00103 
00104                 // build font filename
00105                 strcpy( Filename, Dir );
00106                 strcat( Filename, FontNames[i] );
00107                 strcat( Filename, Ext );
00108 
00109                 // load the decal
00110                 File = geVFile_Open(MainFS, Filename, GE_VFILE_OPEN_READONLY);
00111                 if      (!File)
00112                 {
00113                         geErrorLog_AddString(-1, "Text_Create:  geVFile_Open failed:", Filename);
00114                         return GE_FALSE;
00115                 }
00116                 Fonts[i].Bitmap = geBitmap_CreateFromFile(File);
00117                 geVFile_Close(File);
00118 
00119                 if (!Fonts[i].Bitmap)
00120                 {
00121                         geErrorLog_AddString(-1, "Text_Create:  geBitmap_CreateFromFile failed.", NULL);
00122                         return GE_FALSE;
00123                 }
00124 
00125                 if (!geBitmap_SetColorKey(Fonts[i].Bitmap, GE_TRUE, 255, GE_FALSE))
00126                 {
00127                         geErrorLog_AddString(-1, "Text_Create:  geBitmap_SetColorKey failed.", NULL);
00128                         return GE_FALSE;
00129                         //goto ExitWithError;
00130                 }
00131 
00132                 if (!geEngine_AddBitmap(SaveEngine, Fonts[i].Bitmap))
00133                 {
00134                         geErrorLog_AddString(-1, "Text_Create:  geEngine_AddBitmap failed.", NULL);
00135                         return GE_FALSE;
00136                 }
00137 
00138                 // init font dimensions
00139                 if (i == Font_Small)    // special case. sorry. 
00140                         {
00141                                 Fonts[i].FontWidth  = 8;
00142                                 Fonts[i].FontHeight = 16;
00143                                 Fonts[i].AddHeight  = 16  + 2;
00144                                 Fonts[i].AddWidth   = 8  - 1;
00145                                 continue;
00146                         }
00147                 else
00148                         {
00149                                 Fonts[i].FontWidth = 16;
00150                                 Fonts[i].FontHeight = 16;
00151                                 Fonts[i].AddHeight = 16 + 5;
00152                                 Fonts[i].AddWidth = 13;
00153                         }
00154         }
00155 
00156         // save the engine pointer
00157         Engine = SaveEngine;
00158 
00159         // all done
00160         return GE_TRUE;
00161 
00162 } // Text_Create()

geBoolean Text_Destroy void   ) 
 

Definition at line 179 of file TEXT.C.

References Font_Type::Bitmap, Engine, FontLookup, Fonts, GE_FALSE, GE_TRUE, geBitmap_Destroy(), geBoolean, geEngine_RemoveBitmap(), int32, MAX_FONTS, and NULL.

Referenced by ShutdownAll(), and WinMain().

00181 {
00182 
00183         // locals
00184         int32           i;
00185         geBoolean       Ret;
00186 
00187         Ret = GE_TRUE;
00188 
00189         // fail if we have an invalid engine pointer
00190         if ( Engine == NULL )
00191         {
00192                 assert( 0 );
00193                 return GE_FALSE;
00194         }
00195 
00196         // zap font lookup table
00197         memset( FontLookup, 0, sizeof( FontLookup ) );
00198 
00199         // zap all font decals
00200         for ( i = 0; i < MAX_FONTS; i++ )
00201         {
00202                 if (!Fonts[i].Bitmap)
00203                         continue;
00204 
00205                 if (!geEngine_RemoveBitmap(Engine, Fonts[i].Bitmap))
00206                         Ret = GE_FALSE;
00207 
00208                 geBitmap_Destroy(&Fonts[i].Bitmap);
00209                 Fonts[i].Bitmap = NULL;
00210 
00211         }
00212 
00213         // zap all font info
00214         memset( Fonts, 0, sizeof( Fonts ) );
00215 
00216         // zap saved engine pointer
00217         Engine = NULL;
00218 
00219         // all done
00220         return Ret;
00221 
00222 } // Text_Create()

int32 Text_GetHeight FontType  Font  ) 
 

Definition at line 396 of file TEXT.C.

References Font_Type::AddHeight, Font_Type::Bitmap, Fonts, int32, and NULL.

Referenced by Menu_AddItem().

00398 {
00399 
00400         // fail if we have invalid data
00401         if ( Fonts[Font].Bitmap == NULL )
00402         {
00403                 assert( 0 );
00404                 return -1;
00405         }
00406 
00407         // return font spacing height
00408         return Fonts[Font].AddHeight;
00409         
00410 } // Text_GetWidth()

int32 Text_GetWidth FontType  Font  ) 
 

Definition at line 365 of file TEXT.C.

References Font_Type::AddWidth, Font_Type::Bitmap, Fonts, int32, and NULL.

Referenced by Menu_AddItem().

00367 {
00368 
00369         // fail if we have invalid data
00370         if ( Fonts[Font].Bitmap == NULL )
00371         {
00372                 assert( 0 );
00373                 return -1;
00374         }
00375 
00376         // return font spacing width
00377         return Fonts[Font].AddWidth;
00378         
00379 } // Text_GetWidth()

geBoolean Text_Out char *  Text,
FontType  FontNum,
int32  x,
int32  y,
FontStyle  Style
 

Definition at line 233 of file TEXT.C.

References Font_Type::AddWidth, GE_Rect::Bottom, Engine, Font_Small, Font_Type::FontHeight, FontLookup, Fonts, Font_Type::FontWidth, GE_FALSE, GE_TRUE, geBoolean, geEngine_DrawBitmap(), int32, GE_Rect::Left, MAX_FONTS, MAX_SUPPORTED_CHARS, NULL, GE_Rect::Right, Style_Center, Style_RightJustify, GE_Rect::Top, uint8, and y.

Referenced by Menu_Draw().

00239 {
00240 
00241         // locals
00242         GE_Rect Rect;
00243         int32   Length;
00244         uint8   Val;
00245 
00246         // fail if we have invalid data
00247         if ( ( Engine == NULL ) || ( Text == NULL ) )
00248         {
00249                 assert( 0 );
00250                 return GE_FALSE;
00251         }
00252         if ( ( FontNum < 0 ) || ( FontNum >= MAX_FONTS ) )
00253         {
00254                 assert( 0 );
00255                 return GE_FALSE;
00256         }
00257 
00258         // get length of string (fail if it's invalid)
00259         Length = strlen( Text );
00260         if ( Length <= 0 )
00261         {
00262                 return GE_FALSE;
00263         }
00264 
00265         // always center characters on y axis
00266         y -= Fonts[FontNum].FontHeight / 2;
00267 
00268         // adjust x coordinate to reflect style
00269         switch ( Style )
00270         {
00271 
00272                 case Style_Center:
00273                 {
00274                         x -= ( Length * Fonts[FontNum].AddWidth ) / 2;
00275                         break;
00276                 }
00277 
00278                 case Style_RightJustify:
00279                 {
00280                         x -= ( Length * Fonts[FontNum].AddWidth );
00281                         break;
00282                 }
00283         }
00284         if (FontNum == Font_Small)
00285                 {
00286                         // process all characters
00287                         while ( Length-- > 0 )
00288                         {
00289 
00290                                 // get current character
00291                                 Val = *Text++;
00292 
00293                                 // only print characters in range
00294                                 if ( ( Val >= 0 ) && ( Val < MAX_SUPPORTED_CHARS ) )
00295                                 {
00296                                         // setup character rect
00297                                         Rect.Left = Val * Fonts[FontNum].FontWidth;
00298                                         Rect.Right = Rect.Left + Fonts[FontNum].FontWidth;
00299                                         Rect.Top = 0;
00300                                         Rect.Bottom = Rect.Top + Fonts[FontNum].FontHeight;
00301 
00302                                         // draw character
00303                                         geEngine_DrawBitmap( Engine, Fonts[FontNum].Bitmap, &Rect, x, y );
00304                                 }
00305 
00306                                 // shift to next position
00307                                 x += Fonts[FontNum].AddWidth;
00308                         }
00309         
00310                 }
00311         else
00312                 {
00313                         // process all characters
00314                         while ( Length-- > 0 )
00315                         {
00316 
00317                                 // get current character
00318                                 Val = *Text++;
00319 
00320                                 // only print characters in range
00321                                 if ( ( Val >= 0 ) && ( Val < MAX_SUPPORTED_CHARS ) )
00322                                 {
00323                                 
00324                                         // capitalize it if required
00325                                         if ( Val >= 'a' && Val <= 'z' )
00326                                         {
00327                                                 Val += (uint8)( 'A' - 'a' );
00328                                         }
00329 
00330                                         // setup character rect
00331                                         Rect.Left = ( FontLookup[Val] >> 16 ) + 1;
00332                                         Rect.Right = Rect.Left + 16;
00333                                         Rect.Top = ( FontLookup[Val] & 0xffff ) + 1;
00334                                         Rect.Bottom = Rect.Top + 16;
00335 
00336                                         // draw character
00337                                         geEngine_DrawBitmap( Engine, Fonts[FontNum].Bitmap, &Rect, x, y );
00338                                 }
00339 
00340                                 // shift to next position
00341                                 x += Fonts[FontNum].AddWidth;
00342                         }
00343                 }
00344 
00345         // all done
00346         return GE_TRUE;
00347 
00348 } // Text_Out()


Variable Documentation

char* Dir = "Bmp\\" [static]
 

Definition at line 43 of file TEXT.C.

Referenced by Text_Create().

geEngine* Engine = NULL [static]
 

Definition at line 45 of file TEXT.C.

char* Ext = ".Bmp" [static]
 

Definition at line 44 of file TEXT.C.

Referenced by Text_Create().

int32 FontLookup[MAX_SUPPORTED_CHARS]
 

Definition at line 47 of file TEXT.C.

Referenced by Text_Create(), Text_Destroy(), and Text_Out().

char FontNames[MAX_FONTS][100] [static]
 

Initial value:

                        
{
        "SFont1",
        "SFont2",
        "Console\\640x480\\font"
}

Definition at line 48 of file TEXT.C.

Referenced by Text_Create().

Font_Type Fonts[MAX_FONTS]
 

Definition at line 46 of file TEXT.C.

Referenced by Text_Create(), Text_Destroy(), Text_GetHeight(), Text_GetWidth(), and Text_Out().

geVFile* MainFS
 

Definition at line 65 of file TEXT.C.


Generated on Tue Sep 30 12:38:11 2003 for GTestAndEngine by doxygen 1.3.2