1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-05 05:08:05 +02:00

ASFont: merged SFontPlus class into ASFont class.

This commit is contained in:
Maarten ter Huurne 2011-05-10 02:37:10 +02:00
parent 1bc55392cd
commit b4f3cde526
2 changed files with 29 additions and 70 deletions

View File

@ -7,7 +7,7 @@
#define SFONTPLUS_CHARSET "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¿ÀÁÈÉÌÍÒÓÙÚÝÄËÏÖÜŸÂÊÎÔÛÅÃÕÑÆÇČĎĚĽĹŇÔŘŔŠŤŮŽàáèéìíòóùúýäëïöüÿâêîôûåãõñæçčďěľĺňôřŕšťžůðßÐÞþАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяØøąćęłńśżźĄĆĘŁŃŚŻŹ"
Uint32 SFontPlus::getPixel(Sint32 x, Sint32 y) {
Uint32 ASFont::getPixel(Sint32 x, Sint32 y) {
assert(x>=0);
assert(x<surface->w);
assert(y>=0);
@ -40,8 +40,8 @@ Uint32 SFontPlus::getPixel(Sint32 x, Sint32 y) {
return 0;
}
SFontPlus::SFontPlus(const std::string &fontImagePath, const std::string &characters) {
this->characters = characters;
ASFont::ASFont(const std::string &fontImagePath) {
this->characters = SFONTPLUS_CHARSET;
SDL_Surface *buf = loadPNG(fontImagePath);
if (!buf) {
@ -97,18 +97,18 @@ SFontPlus::SFontPlus(const std::string &fontImagePath, const std::string &charac
lineHeight = y+1;
}
SFontPlus::~SFontPlus() {
ASFont::~ASFont() {
if (surface) {
SDL_FreeSurface(surface);
}
}
bool SFontPlus::utf8Code(unsigned char c) {
bool ASFont::utf8Code(unsigned char c) {
return (c>=194 && c<=198) || c==208 || c==209;
//return c>=194;
}
void SFontPlus::write(SDL_Surface *s, const std::string &text, int x, int y) {
void ASFont::write(SDL_Surface *s, const std::string &text, int x, int y) {
if (text.empty()) return;
std::string::size_type pos;
@ -143,8 +143,8 @@ void SFontPlus::write(SDL_Surface *s, const std::string &text, int x, int y) {
}
}
unsigned SFontPlus::getTextWidth(const char *text) {
unsigned maxWidth = 0, width = 0;
int ASFont::getTextWidth(const char *text) {
int maxWidth = 0, width = 0;
while (char ch = *text++) {
if (ch == '\n') {
// New line.
@ -169,24 +169,8 @@ unsigned SFontPlus::getTextWidth(const char *text) {
return max(width, maxWidth);
}
unsigned SFontPlus::getHeight() {
return surface->h - 1;
}
unsigned SFontPlus::getLineHeight() {
return lineHeight;
}
ASFont::ASFont(const std::string &fontImagePath)
: font(fontImagePath, SFONTPLUS_CHARSET)
{
}
ASFont::~ASFont() {
}
bool ASFont::utf8Code(unsigned char c) {
return font.utf8Code(c);
int ASFont::getTextWidth(const std::string& text) {
return getTextWidth(text.c_str());
}
void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
@ -212,7 +196,7 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y,
break;
}
font.write(surface, text, x, y);
write(surface, text, x, y);
}
void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) {
switch (valign) {
@ -239,7 +223,7 @@ void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, i
break;
}
font.write(surface, *it, ix, y);
write(surface, *it, ix, y);
y += getHeight();
}
}
@ -252,17 +236,3 @@ void ASFont::write(Surface* surface, const std::string& text, int x, int y, HAli
} else
write(surface->raw, text, x, y, halign, valign);
}
int ASFont::getHeight() {
return font.getHeight();
}
int ASFont::getLineHeight() {
return font.getLineHeight();
}
int ASFont::getTextWidth(const char* text) {
return font.getTextWidth(text);
}
int ASFont::getTextWidth(const std::string& text) {
return font.getTextWidth(text.c_str());
}

View File

@ -12,28 +12,6 @@
class Surface;
class SFontPlus {
public:
SFontPlus(const std::string &fontImagePath, const std::string &characters);
~SFontPlus();
bool utf8Code(unsigned char c);
void write(SDL_Surface *s, const std::string &text, int x, int y);
unsigned getTextWidth(const char *text);
unsigned getHeight();
unsigned getLineHeight();
private:
Uint32 getPixel(Sint32 x, Sint32 y);
SDL_Surface *surface;
std::vector<unsigned> charpos;
std::string characters;
unsigned height, lineHeight;
};
class ASFont {
public:
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
@ -44,17 +22,28 @@ public:
bool utf8Code(unsigned char c);
int getHeight();
int getLineHeight();
int getTextWidth(const char* text);
int getTextWidth(const char *text);
int getTextWidth(const std::string& text);
int getHeight() {
return surface->h - 1;
}
int getLineHeight() {
return lineHeight;
}
void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
private:
void write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign);
void write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign);
void write(SDL_Surface *s, const std::string &text, int x, int y);
void write(SDL_Surface *surface, const std::string& text, int x, int y, HAlign halign, VAlign valign);
void write(SDL_Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign);
Uint32 getPixel(Sint32 x, Sint32 y);
SFontPlus font;
SDL_Surface *surface;
std::vector<unsigned> charpos;
std::string characters;
int lineHeight;
};
#endif /* ASFONT_H */