1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-10-05 22:09:48 +03:00
gmenu2x/src/font.h
Maarten ter Huurne f8dc4c7bb8 Don't construct non-functional Font objects
Replaced Font constructor with factory method, so that if the TTF
cannot be loaded, the Font object is not constructed. The normal C++
way of handling this is with exceptions, but we're compiling with
-fno-exceptions.
2013-08-04 00:58:32 +02:00

51 lines
1007 B
C++

// Original font class was replaced by an SDL_ttf based one by Paul Cercueil.
// License: GPL version 2 or later.
#ifndef FONT_H
#define FONT_H
#include <SDL_ttf.h>
#include <string>
class Surface;
class Font {
public:
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
/**
* Returns a newly created Font object for the default font,
* or nullptr if there was a problem creating it.
*/
static Font *defaultFont();
~Font();
int getTextWidth(const char *text);
int getTextWidth(const std::string& text)
{
return getTextWidth(text.c_str());
}
int getHeight()
{
return fontheight;
}
void write(Surface *surface,
const std::string &text, int x, int y,
HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
private:
Font(TTF_Font *font);
void writeLine(Surface *surface, const char *text,
int x, int y, HAlign halign, VAlign valign);
TTF_Font *font;
unsigned int fontheight;
};
#endif /* FONT_H */