home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / texfont.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-18  |  4.6 KB  |  88 lines

  1. #ifndef __texfont_h__
  2. #define __texfont_h__
  3.  
  4. /*!
  5. \file texfont.h
  6. \author Karsten Schwenk
  7.  
  8. \brief This file contains routines for drawing text on the (OpenGL-)screen using texture fonts.
  9.  
  10. Usage is quite simple. First of all you have to obtain a valid pointer to a texFont_s struct (usually done with #FontHandler::getFont()).
  11. Then you can write text on the screen using the \c drawString functions.
  12.  
  13. The fonts are defined in separate .font files. They are made up as follows.
  14.  
  15. The first keyword should be \c texture followed by a filename. This is the texture with the characters.
  16. In the next two lines \c height and \c spacing should be specified in pixels.
  17. Then come the character describtions in the format \c character \c C \c x \c y \c width. \c C is the character whoose specification follows, \c x and \c y are the charcters coordinates in the texture (from bottom left) and \c width is the characters width in pixels (so variable widths are allowed).
  18. \c C can be enclosed in quotation marks or not, it doesn't matter ("C"=C) - however the character " itself is represented through double inverted commas (''). You should have a look into one of the .font files in the gui/fonts directory and everything will become clear.
  19.  
  20. The \c drawString() functions allow dynamic color changing IN ONE string through the '^0-9' characters (just like in Quake 3). An example shows it best:
  21. In
  22.  
  23. \c "^0I am ^1a colored ^2string"
  24.  
  25. "I am" will be drawed using color 0, "a colored" will appear in color 1 and "string" in color 2. A special character is 'b'; it will result in a blinking string (red-black).
  26.  
  27. */
  28.  
  29. #include "Texture.h"
  30.  
  31. #define TEX_FONT_MAX_CHARACTERS    128    //!< number of characters in a #texFont_t
  32.  
  33. //! enum of possible text alignments (to be passed to drawString()-functions)
  34. enum textAlignments_e{
  35.     TEXT_ALIGN_LEFT,    //!< text should be aligned left (relative to the passed x-coordinate)
  36.     TEXT_ALIGN_RIGHT,    //!< text should be aligned right (relative to the passed x-coordinate)
  37.     TEXT_ALIGN_CENTER,    //!< text should be aligned centered (relative to the passed x-coordinate)
  38.  
  39.     NUM_TEXT_ALIGNMENTS    //!< number of allowed alignments (just for counting)
  40. };
  41.  
  42. //! represents ONE texFont character
  43. typedef struct texFontCharacter_s{
  44.     float u,v;                //!< texture coordinates of this character in the fonts texture
  45.     float texCoordWidth;    //!< width of this character in texture coordinates
  46.     int width;                //!< width of this character in pixels
  47. }texFontCharacter_t;
  48.  
  49. //! represents a texFont
  50. typedef struct texFont_s{
  51.     char* filename;
  52.     Texture* tex;                            //!< texture of this font
  53.     texFontCharacter_t* chars[TEX_FONT_MAX_CHARACTERS];        //!< array with characters (may be NULL for some chars!)
  54.     int height;                                //!< height of this font in pixels
  55.     float texCoordHeight;                    //!< height of the font in texture coordinates
  56.     int spacing;                            //!< spacing between characters in pixels
  57. }texFont_t;
  58.  
  59. //! loads a texFont (should be used directly - use #FontHandler::getFont() instead!)
  60. texFont_t* loadFont(const char* filename);
  61.  
  62. //! frees a texFont allocated with #loadFont (should not be used directly - use #FontHandler::freeFont() instead!)
  63. void freeFont(texFont_t* font);
  64.  
  65. //! returns how many pixels a string occupies in a particular font
  66. int getStringWidth(texFont_t* font, const char* string);
  67.  
  68. //! sets OpenGL color to color number c (REALLY THE CHARACTER: '1'=1)
  69. bool setFontColor(char c);
  70.  
  71. //! draws a string on the screen using a particluar font
  72. void drawString(int x, int y, texFont_t* font, const char* string);
  73. void drawScaledString(int x, int y, float scaleX, float scaleY, texFont_t* font, const char* string);
  74. void drawAlignedString(int x, int y, texFont_t* font, int alignment, const char* string);
  75. void drawScaledAndAlignedString(int x, int y, float scaleX, float scaleY, texFont_t* font, int alignment, const char* string);
  76. void drawShadowedString(float x, float y, float scale, int shadowOffset, texFont_t* font, int alignment, const char* string);
  77.  
  78. void drawFormatString(int x, int y, texFont_t* font, const char* formatString, ...);
  79. void drawScaledFormatString(int x, int y, float scaleX, float scaleY, texFont_t* font, const char* formatString, ...);
  80. void drawAlignedFormatString(int x, int y, texFont_t* font, int alignment, const char* formatString, ...);
  81. void drawScaledAndAlignedFormatString(int x, int y, float scaleX, float scaleY, texFont_t* font, int alignment, const char* formatString, ...);
  82. void drawShadowedFormatString(float x, float y, float scale, int shadowOffset, texFont_t* font, int alignment, const char* formatString, ...);
  83.  
  84.  
  85.  
  86.  
  87. #endif    /* __texfont_h__*/
  88.