1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-10-02 15:43:16 +03: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()); 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) { switch (halign) {
case HAlignLeft: case HAlignLeft:
break; break;
@ -184,7 +184,10 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y,
x -= getTextWidth(text); x -= getTextWidth(text);
break; 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) { switch (valign) {
case VAlignTop: case VAlignTop:
break; break;
@ -195,9 +198,9 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y,
y -= getHeight(); y -= getHeight();
break; break;
} }
write(surface, text, x, y, halign);
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) { void ASFont::write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) {
switch (valign) { switch (valign) {
case VAlignTop: 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) { for (std::vector<std::string>::const_iterator it = text.begin(); it != text.end(); ++it) {
int ix = x; write(surface, *it, x, y, halign);
switch (halign) {
case HAlignLeft:
break;
case HAlignCenter:
ix -= getTextWidth(*it) / 2;
break;
case HAlignRight:
ix -= getTextWidth(*it);
break;
}
write(surface, *it, ix, y);
y += getHeight(); 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); void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
private: 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); 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; SDL_Surface *surface;
std::vector<unsigned> charpos; std::vector<unsigned> charpos;