Root/
| 1 | // Original font class was replaced by an SDL_ttf based one by Paul Cercueil. |
| 2 | // License: GPL version 2 or later. |
| 3 | |
| 4 | #ifndef FONT_H |
| 5 | #define FONT_H |
| 6 | |
| 7 | #include <SDL_ttf.h> |
| 8 | #include <string> |
| 9 | |
| 10 | class Surface; |
| 11 | |
| 12 | class Font { |
| 13 | public: |
| 14 | enum HAlign { HAlignLeft, HAlignRight, HAlignCenter }; |
| 15 | enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle }; |
| 16 | |
| 17 | /** |
| 18 | * Returns a newly created Font object for the default font, |
| 19 | * or nullptr if there was a problem creating it. |
| 20 | */ |
| 21 | static Font *defaultFont(); |
| 22 | ~Font(); |
| 23 | |
| 24 | int getTextWidth(const char *text); |
| 25 | |
| 26 | int getTextWidth(const std::string& text) |
| 27 | { |
| 28 | return getTextWidth(text.c_str()); |
| 29 | } |
| 30 | |
| 31 | int getHeight() |
| 32 | { |
| 33 | return fontheight; |
| 34 | } |
| 35 | |
| 36 | void write(Surface *surface, |
| 37 | const std::string &text, int x, int y, |
| 38 | HAlign halign = HAlignLeft, VAlign valign = VAlignTop); |
| 39 | |
| 40 | private: |
| 41 | Font(TTF_Font *font); |
| 42 | |
| 43 | void writeLine(Surface *surface, const char *text, |
| 44 | int x, int y, HAlign halign, VAlign valign); |
| 45 | |
| 46 | TTF_Font *font; |
| 47 | unsigned int fontheight; |
| 48 | }; |
| 49 | |
| 50 | #endif /* FONT_H */ |
| 51 |
Branches:
install_locations
master
opkrun
packages
