1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 09:48:28 +02:00

ASFont: removed duplication of horizontal alignment code.

This commit is contained in:
Maarten ter Huurne 2011-05-10 02:43:15 +02:00
parent b4f3cde526
commit bff04d2418
2 changed files with 11 additions and 19 deletions

View File

@ -173,7 +173,7 @@ 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) {
void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign) {
switch (halign) {
case HAlignLeft:
break;
@ -184,7 +184,10 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y,
x -= getTextWidth(text);
break;
}
write(surface, text, x, y);
}
void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
switch (valign) {
case VAlignTop:
break;
@ -195,9 +198,9 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y,
y -= getHeight();
break;
}
write(surface, text, x, y);
write(surface, text, x, y, halign);
}
void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) {
switch (valign) {
case VAlignTop:
@ -211,19 +214,7 @@ void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, i
}
for (std::vector<std::string>::const_iterator it = text.begin(); it != text.end(); ++it) {
int ix = x;
switch (halign) {
case HAlignLeft:
break;
case HAlignCenter:
ix -= getTextWidth(*it) / 2;
break;
case HAlignRight:
ix -= getTextWidth(*it);
break;
}
write(surface, *it, ix, y);
write(surface, *it, x, y, halign);
y += getHeight();
}
}

View File

@ -35,10 +35,11 @@ public:
void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
private:
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);
void write(SDL_Surface *surface, const std::string &text, int x, int y);
void write(SDL_Surface *surface, const std::string &text, int x, int y, HAlign halign);
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);
SDL_Surface *surface;
std::vector<unsigned> charpos;