Root/src/asfont.h

1// Based on SFont by Karl Bartel.
2// Adapted to C++ by Massimiliano Torromeo.
3// Refactored by Maarten ter Huurne and several others (see git log).
4// License: GPL version 2 or later.
5
6#ifndef ASFONT_H
7#define ASFONT_H
8
9#include <SDL.h>
10#include <string>
11#include <vector>
12
13class Surface;
14
15class ASFont {
16public:
17    enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
18    enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
19
20    ASFont(const std::string &font);
21    ~ASFont();
22
23    bool utf8Code(unsigned char c);
24
25    int getTextWidth(const char *text);
26    int getTextWidth(const std::string& text);
27
28    int getHeight() {
29        return surface->h - 1;
30    }
31    int getLineHeight() {
32        return lineHeight;
33    }
34
35    void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
36
37private:
38    void writeLine(Surface *surface, const std::string &text, int x, int y);
39    void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign);
40    void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign);
41    void writeLine(Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign);
42
43    SDL_Surface *surface;
44    std::vector<unsigned> charpos;
45    std::string characters;
46    int lineHeight;
47};
48
49#endif /* ASFONT_H */
50

Archive Download this file



interactive