2013-08-03 23:30:12 +03:00
|
|
|
// Original font class was replaced by an SDL_ttf based one by Paul Cercueil.
|
2011-05-09 15:25:16 +03:00
|
|
|
// License: GPL version 2 or later.
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2013-08-03 23:30:12 +03:00
|
|
|
#ifndef FONT_H
|
|
|
|
#define FONT_H
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2013-07-05 21:07:46 +03:00
|
|
|
#include <SDL_ttf.h>
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <string>
|
|
|
|
|
2011-05-09 05:13:11 +03:00
|
|
|
class Surface;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2013-08-03 23:30:12 +03:00
|
|
|
class Font {
|
2010-02-04 13:33:47 +02:00
|
|
|
public:
|
2011-05-09 06:17:25 +03:00
|
|
|
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
|
|
|
|
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
|
|
|
|
|
2013-08-04 01:58:32 +03:00
|
|
|
/**
|
|
|
|
* Returns a newly created Font object for the default font,
|
|
|
|
* or nullptr if there was a problem creating it.
|
|
|
|
*/
|
|
|
|
static Font *defaultFont();
|
2014-01-15 21:32:17 +02:00
|
|
|
Font(const std::string &path, unsigned int size);
|
2013-08-03 23:30:12 +03:00
|
|
|
~Font();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-05-10 03:37:10 +03:00
|
|
|
int getTextWidth(const char *text);
|
|
|
|
|
2013-07-05 21:07:46 +03:00
|
|
|
int getTextWidth(const std::string& text)
|
|
|
|
{
|
|
|
|
return getTextWidth(text.c_str());
|
2011-05-10 03:37:10 +03:00
|
|
|
}
|
2013-07-05 21:07:46 +03:00
|
|
|
|
|
|
|
int getHeight()
|
|
|
|
{
|
|
|
|
return fontheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2013-08-04 01:58:32 +03:00
|
|
|
Font(TTF_Font *font);
|
|
|
|
|
2013-07-05 21:07:46 +03:00
|
|
|
void writeLine(Surface *surface, const char *text,
|
|
|
|
int x, int y, HAlign halign, VAlign valign);
|
|
|
|
|
|
|
|
TTF_Font *font;
|
|
|
|
unsigned int fontheight;
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
2013-08-03 23:30:12 +03:00
|
|
|
#endif /* FONT_H */
|