1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 18:53:09 +02:00

ASFont: simplified object initialization and cleanup.

Do initialization and cleanup in constructor and destructor respectively.
Removed constructors that are not used by gmenu2x.
This commit is contained in:
Maarten ter Huurne 2011-05-09 14:54:11 +02:00
parent ec5d426d83
commit 492a36b9df
2 changed files with 34 additions and 75 deletions

View File

@ -5,6 +5,8 @@
#include <cassert>
#define SFONTPLUS_CHARSET "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¿ÀÁÈÉÌÍÒÓÙÚÝÄËÏÖÜŸÂÊÎÔÛÅÃÕÑÆÇČĎĚĽĹŇÔŘŔŠŤŮŽàáèéìíòóùúýäëïöüÿâêîôûåãõñæçčďěľĺňôřŕšťžůðßÐÞþАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяØøąćęłńśżźĄĆĘŁŃŚŻŹ"
Uint32 SFontPlus::getPixel(Sint32 x, Sint32 y) {
assert(x>=0);
assert(x<surface->w);
@ -38,42 +40,17 @@ Uint32 SFontPlus::getPixel(Sint32 x, Sint32 y) {
return 0;
}
SFontPlus::SFontPlus() {
surface = NULL;
}
SFontPlus::SFontPlus(SDL_Surface* font) {
surface = NULL;
initFont(font);
}
SFontPlus::SFontPlus(const std::string &font) {
surface = NULL;
initFont(font);
}
SFontPlus::~SFontPlus() {
freeFont();
}
bool SFontPlus::utf8Code(unsigned char c) {
return (c>=194 && c<=198) || c==208 || c==209;
//return c>=194;
}
void SFontPlus::initFont(const std::string &font, const std::string &characters) {
SDL_Surface *buf = loadPNG(font);
if (buf!=NULL) {
initFont( SDL_DisplayFormatAlpha(buf), characters );
SDL_FreeSurface(buf);
}
}
void SFontPlus::initFont(SDL_Surface *font, const std::string &characters) {
freeFont();
SFontPlus::SFontPlus(const std::string &fontImagePath, const std::string &characters) {
this->characters = characters;
if (font==NULL) return;
surface = font;
SDL_Surface *buf = loadPNG(fontImagePath);
if (!buf) {
surface = NULL;
return;
}
surface = SDL_DisplayFormatAlpha(buf);
SDL_FreeSurface(buf);
Uint32 pink = SDL_MapRGB(surface->format, 255,0,255);
#ifdef DEBUG
bool utf8 = false;
@ -120,13 +97,17 @@ void SFontPlus::initFont(SDL_Surface *font, const std::string &characters) {
lineHeight = y+1;
}
void SFontPlus::freeFont() {
if (surface!=NULL) {
SFontPlus::~SFontPlus() {
if (surface) {
SDL_FreeSurface(surface);
surface = NULL;
}
}
bool SFontPlus::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) {
if (text.empty()) return;
@ -193,26 +174,14 @@ unsigned SFontPlus::getLineHeight() {
return lineHeight;
}
ASFont::ASFont(SDL_Surface* font) {
this->font.initFont(font);
halfHeight = getHeight()/2;
halfLineHeight = getLineHeight()/2;
}
ASFont::ASFont(Surface* font) {
this->font.initFont(font->raw);
halfHeight = getHeight()/2;
halfLineHeight = getLineHeight()/2;
}
ASFont::ASFont(const std::string &font) {
this->font.initFont(font);
ASFont::ASFont(const std::string &fontImagePath)
: font(fontImagePath, SFONTPLUS_CHARSET)
{
halfHeight = getHeight()/2;
halfLineHeight = getLineHeight()/2;
}
ASFont::~ASFont() {
font.freeFont();
}
bool ASFont::utf8Code(unsigned char c) {

View File

@ -12,9 +12,19 @@
class Surface;
#define SFONTPLUS_CHARSET "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¿ÀÁÈÉÌÍÒÓÙÚÝÄËÏÖÜŸÂÊÎÔÛÅÃÕÑÆÇČĎĚĽĹŇÔŘŔŠŤŮŽàáèéìíòóùúýäëïöüÿâêîôûåãõñæçčďěľĺňôřŕšťžůðßÐÞþАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяØøąćęłńśżźĄĆĘŁŃŚŻŹ"
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 std::string &text);
unsigned getHeight();
unsigned getLineHeight();
private:
Uint32 getPixel(Sint32 x, Sint32 y);
@ -22,24 +32,6 @@ private:
std::vector<unsigned> charpos;
std::string characters;
unsigned height, lineHeight;
public:
SFontPlus();
SFontPlus(SDL_Surface *font);
SFontPlus(const std::string &font);
~SFontPlus();
bool utf8Code(unsigned char c);
void initFont(SDL_Surface *font, const std::string &characters = SFONTPLUS_CHARSET);
void initFont(const std::string &font, const std::string &characters = SFONTPLUS_CHARSET);
void freeFont();
void write(SDL_Surface *s, const std::string &text, int x, int y);
unsigned getTextWidth(const std::string &text);
unsigned getHeight();
unsigned getLineHeight();
};
class ASFont {
@ -47,8 +39,6 @@ public:
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
ASFont(SDL_Surface* font);
ASFont(Surface* font);
ASFont(const std::string &font);
~ASFont();