diff --git a/src/asfont.cpp b/src/asfont.cpp index e34bdf8..0854d15 100644 --- a/src/asfont.cpp +++ b/src/asfont.cpp @@ -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 &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 &text, i } for (std::vector::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(); } } diff --git a/src/asfont.h b/src/asfont.h index bea7266..4e30cdc 100644 --- a/src/asfont.h +++ b/src/asfont.h @@ -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 &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 &text, int x, int y, HAlign halign, VAlign valign); SDL_Surface *surface; std::vector charpos;