2011-05-09 15:25:16 +03:00
|
|
|
// Based on SFont by Karl Bartel.
|
|
|
|
// Adapted to C++ by Massimiliano Torromeo.
|
|
|
|
// Refactored by Maarten ter Huurne and several others (see git log).
|
|
|
|
// License: GPL version 2 or later.
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
#ifndef ASFONT_H
|
|
|
|
#define ASFONT_H
|
|
|
|
|
2011-05-09 15:25:16 +03:00
|
|
|
#include <SDL.h>
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2011-05-09 05:13:11 +03:00
|
|
|
class Surface;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
class ASFont {
|
|
|
|
public:
|
2011-05-09 06:17:25 +03:00
|
|
|
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
|
|
|
|
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
|
|
|
|
|
2011-05-09 05:13:11 +03:00
|
|
|
ASFont(const std::string &font);
|
2010-02-04 13:33:47 +02:00
|
|
|
~ASFont();
|
|
|
|
|
|
|
|
bool utf8Code(unsigned char c);
|
|
|
|
|
2011-05-10 03:37:10 +03:00
|
|
|
int getTextWidth(const char *text);
|
2011-05-09 05:13:11 +03:00
|
|
|
int getTextWidth(const std::string& text);
|
2011-05-10 03:37:10 +03:00
|
|
|
|
|
|
|
int getHeight() {
|
|
|
|
return surface->h - 1;
|
|
|
|
}
|
|
|
|
int getLineHeight() {
|
|
|
|
return lineHeight;
|
|
|
|
}
|
|
|
|
|
2011-05-09 06:17:25 +03:00
|
|
|
void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
private:
|
2011-06-02 05:29:19 +03:00
|
|
|
void writeLine(Surface *surface, const std::string &text, int x, int y);
|
|
|
|
void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign);
|
|
|
|
void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign);
|
|
|
|
void writeLine(Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign);
|
2011-05-10 03:23:13 +03:00
|
|
|
|
2011-05-10 03:37:10 +03:00
|
|
|
SDL_Surface *surface;
|
2012-04-11 00:01:16 +03:00
|
|
|
std::vector<Uint16> charpos;
|
2011-05-10 03:37:10 +03:00
|
|
|
std::string characters;
|
|
|
|
int lineHeight;
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* ASFONT_H */
|