| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file font.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created OpenJazz.h |
| 10 | * - 3rd February 2009: Created font.h from parts of OpenJazz.h |
| 11 | * |
| 12 | * @par Licence: |
| 13 | * Copyright (c) 2005-2010 AJ Thomson |
| 14 | * |
| 15 | * OpenJazz is distributed under the terms of |
| 16 | * the GNU General Public License, version 2.0 |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef OJ_FONT_H |
| 21 | #define OJ_FONT_H |
| 22 | |
| 23 | #include "OpenJazz.h" |
| 24 | |
| 25 | #ifdef OJ_SDL3 |
| 26 | #include <SDL3/SDL.h> |
| 27 | #else |
| 28 | #include <SDL.h> |
| 29 | #endif |
| 30 | |
| 31 | #define MAX_FONT_CHARS 128 |
| 32 | |
| 33 | // Classes |
| 34 | |
| 35 | /// Font |
| 36 | class Font { |
| 37 | |
| 38 | private: |
| 39 | void commonSetup(); |
| 40 | void cleanMapping(); |
| 41 | SDL_Surface *characterAtlas; ///< Symbol images |
| 42 | SDL_Rect atlasRects[MAX_FONT_CHARS]; ///< Symbol positions |
| 43 | bool isOk; ///< Font is loaded and usable |
| 44 | int nCharacters; ///< Number of symbols |
| 45 | unsigned char spaceWidth; ///< Horizontal spacing of displayed characters |
| 46 | unsigned char lineHeight; ///< Vertical spacing of displayed characters |
| 47 | unsigned int map[MAX_FONT_CHARS]; ///< Maps ASCII values to symbol indices |
| 48 | |
| 49 | public: |
| 50 | explicit Font(const char *fileName); |
| 51 | Font(unsigned char *pixels, bool big); |
| 52 | explicit Font(bool bonus); |
| 53 | ~Font(); |
| 54 | |
| 55 | Point showString (const char *s, int x, int y, alignX xAlign = alignX::Left, alignY yAlign = alignY::Top); |
| 56 | Point showStringCentered (const char *s); |
| 57 | int showSceneString (const unsigned char *s, int x, int y); |
| 58 | void showNumber (int n, int x, int y); |
| 59 | void mapPalette (int start, int length, int newStart, int newLength); |
| 60 | void restorePalette (); |
| 61 | int getHeight () const; |
| 62 | int getSpaceWidth () const; |
| 63 | int getStringWidth (const char *string); |
| 64 | int getStringHeight (const char *string); |
| 65 | int getSceneStringWidth (const unsigned char *string); |
| 66 | #ifdef DEBUG_FONTS |
| 67 | void saveAtlasAsBMP (const char *fileName); |
| 68 | #endif |
| 69 | |
| 70 | }; |
| 71 | |
| 72 | // Inline functions |
| 73 | |
| 74 | inline int Font::getHeight() const { return lineHeight; } ///< Get the height of a single line of any text. |
| 75 | inline int Font::getSpaceWidth() const { return spaceWidth; } ///< Get the width of a space. |
| 76 | |
| 77 | // Variables |
| 78 | |
| 79 | EXTERN Font *font2; /** Taken from .0FN file name */ |
| 80 | EXTERN Font *fontbig; /** Taken from .0FN file name */ |
| 81 | EXTERN Font *fontiny; /** Taken from .0FN file name */ |
| 82 | EXTERN Font *fontmn1; /** Taken from .0FN file name */ |
| 83 | EXTERN Font *fontmn2; /** Taken from .0FN file name */ |
| 84 | EXTERN Font *panelBigFont; /** Found in PANEL.000 */ |
| 85 | EXTERN Font *panelSmallFont; /** Found in PANEL.000 */ |
| 86 | |
| 87 | #endif |