home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / tge130 / include / varfont.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-05  |  5.1 KB  |  174 lines

  1. /*****************************************************************************
  2. *       The Graphics Engine version 1.30                                     *
  3. *                                                                            *
  4. *       The Graphics Engine code and documentation are                       *
  5. *       Copyright (c) 1993-1994 by Matthew Hildebrand; all rights reserved.  *
  6. *                                                                            *
  7. *       Unauthorised usage or modification of any or all of The Graphics     *
  8. *       Engine is strictly prohibited.                                       *
  9. *****************************************************************************/
  10.  
  11. #if !defined (VARFONTdotH)
  12. #define VARFONTdotH
  13.  
  14.  
  15.  
  16. //*****
  17. //***** Structure used by the VariableFont class.
  18. //*****
  19.  
  20. #pragma option -a-
  21.  
  22. struct FontCharInfo
  23. {
  24.   unsigned short offsetFromTop;
  25.   unsigned short wide, deep;
  26.   void far *bitmap;
  27. };
  28.  
  29. #pragma option -a
  30.  
  31.  
  32.  
  33. //*****
  34. //***** Class for dealing with variable-sized, 256-colour, loadable fonts.
  35. //*****
  36.  
  37. class VariableFont
  38. {
  39.   unsigned char fontPalette[768], colourTranslate[256];
  40.   FontCharInfo characters[256];
  41.   void far *characterData, *charBuf;
  42.   unsigned short maxDeep;
  43.   unsigned spaceBetweenChars;
  44. public:
  45.   VariableFont(void);
  46.   ~VariableFont(void);
  47.   int load(char *filename);                     // returns 0 on error
  48.   void put(int x, int y, char ch);
  49.   void put(int x, int y, char *string);
  50.   unsigned width(char *string);
  51.   unsigned height(char *string);
  52.   inline unsigned short width(char ch);
  53.   inline unsigned short height(char ch);
  54.   inline unsigned short maxHeight(void);
  55.   void matchColours(void);
  56.   void palette(void *palette);
  57.   void palette(unsigned char palReg, unsigned char red, unsigned char green,
  58.                unsigned char blue);
  59.   void palette(unsigned char palReg, unsigned char *red, unsigned char *green,
  60.                unsigned char *blue);
  61.   inline void *palette(void);
  62.   inline void spacing(unsigned numPixels);
  63.   inline unsigned spacing(void);
  64. };
  65.  
  66.  
  67.  
  68. /**************************************************************************
  69. *  Function:    VariableFont::width
  70. *
  71. *  Purpose:     Return the width, in pixels, of a single character.
  72. *
  73. *  Entry:       ch = Character of which to find the width.
  74. *
  75. *  Exit:        Returns the width of the character in pixels, not
  76. *               accounting for blank space on either side.
  77. **************************************************************************/
  78.  
  79. inline unsigned short VariableFont::width(char ch)
  80. {
  81.   return (characters[(unsigned)ch].wide);
  82. }
  83.  
  84.  
  85.  
  86. /**************************************************************************
  87. *  Function:    VariableFont::height
  88. *
  89. *  Purpose:     Return the height, in pixels, of a single character's
  90. *               bitmap.  The offsetFromTop value is ignored.
  91. *
  92. *  Entry:       ch = Character of which to find the height.
  93. *
  94. *  Exit:        Returns the height of the character in pixels, not
  95. *               accounting for blank space above or below.
  96. **************************************************************************/
  97.  
  98. inline unsigned short VariableFont::height(char ch)
  99. {
  100.   return (characters[(unsigned)ch].deep);
  101. }
  102.  
  103.  
  104.  
  105. /**************************************************************************
  106. *  Function:    VariableFont::maxHeight
  107. *
  108. *  Purpose:     Return the height, in pixels, of the tallest character.
  109. *
  110. *  Entry:       N/A
  111. *
  112. *  Exit:        Returns the height of the tallest character in pixels, not
  113. *               accounting for blank space above or below.
  114. **************************************************************************/
  115.  
  116. inline unsigned short VariableFont::maxHeight(void)
  117. {
  118.   return (maxDeep);
  119. }
  120.  
  121.  
  122.  
  123. /**************************************************************************
  124. *  Function:    VariableFont::palette
  125. *
  126. *  Purpose:     Return the current font palette.
  127. *
  128. *  Entry:       N/A
  129. *
  130. *  Exit:        Returns the address of the current font palette.
  131. **************************************************************************/
  132.  
  133. inline void *VariableFont::palette(void)
  134. {
  135.   return (fontPalette);
  136. }
  137.  
  138.  
  139.  
  140. /**************************************************************************
  141. *  Function:    VariableFont::spacing
  142. *
  143. *  Purpose:     Set the spacing, in pixels, between characters.
  144. *
  145. *  Entry:       numPixels = New spacing value, in pixels.
  146. *
  147. *  Exit:        N/A
  148. **************************************************************************/
  149.  
  150. inline void VariableFont::spacing(unsigned numPixels)
  151. {
  152.   spaceBetweenChars = numPixels;            // change spacing value
  153. }
  154.  
  155.  
  156.  
  157. /**************************************************************************
  158. *  Function:    VariableFont::spacing
  159. *
  160. *  Purpose:     Return the spacing, in pixels, between characters.
  161. *
  162. *  Entry:       N/A
  163. *
  164. *  Exit:        Returns the spacing in pixels.
  165. **************************************************************************/
  166.  
  167. inline unsigned VariableFont::spacing(void)
  168. {
  169.   return (spaceBetweenChars);               // return spacing value
  170. }
  171.  
  172.  
  173. #endif
  174.