From b2896d6bac3d8f0180ba8c0febdbb0bbf8554458 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Thu, 2 Jun 2011 04:29:19 +0200 Subject: [PATCH] ASFont: Refactored string drawing methods. Renamed methods that draw a single line from write() to writeLine(). There is now only one write() method left: the public method. Pass surface to draw on as wrapped Surface instead of SDL_Surface. At the end of the call chain we still use SDL directly though. --- src/asfont.cpp | 18 +++++++++--------- src/asfont.h | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/asfont.cpp b/src/asfont.cpp index 25dec70..c74015d 100644 --- a/src/asfont.cpp +++ b/src/asfont.cpp @@ -100,7 +100,7 @@ bool ASFont::utf8Code(unsigned char c) { //return c>=194; } -void ASFont::write(SDL_Surface *s, const std::string &text, int x, int y) { +void ASFont::writeLine(Surface *s, const std::string &text, int x, int y) { if (text.empty()) return; std::string::size_type pos; @@ -129,7 +129,7 @@ void ASFont::write(SDL_Surface *s, const std::string &text, int x, int y) { srcrect.w = charpos[pos+2] - charpos[pos]; dstrect.x = x - charpos[pos+1] + charpos[pos]; - SDL_BlitSurface(surface, &srcrect, s, &dstrect); + SDL_BlitSurface(surface, &srcrect, s->raw, &dstrect); x += charpos[pos+2] - charpos[pos+1]; } @@ -165,7 +165,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) { +void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign) { switch (halign) { case HAlignLeft: break; @@ -176,10 +176,10 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, x -= getTextWidth(text); break; } - write(surface, text, x, y); + writeLine(surface, text, x, y); } -void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) { +void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) { switch (valign) { case VAlignTop: break; @@ -190,10 +190,10 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, y -= getHeight(); break; } - write(surface, text, x, y, halign); + writeLine(surface, text, x, y, halign); } -void ASFont::write(SDL_Surface* surface, const std::vector &text, int x, int y, HAlign halign, VAlign valign) { +void ASFont::writeLine(Surface* surface, const std::vector &text, int x, int y, HAlign halign, VAlign valign) { switch (valign) { case VAlignTop: break; @@ -215,7 +215,7 @@ void ASFont::write(Surface* surface, const std::string& text, int x, int y, HAli if (text.find("\n", 0) != std::string::npos) { std::vector textArr; split(textArr, text, "\n"); - write(surface->raw, textArr, x, y, halign, valign); + writeLine(surface, textArr, x, y, halign, valign); } else - write(surface->raw, text, x, y, halign, valign); + writeLine(surface, text, x, y, halign, valign); } diff --git a/src/asfont.h b/src/asfont.h index 850ab20..a205cca 100644 --- a/src/asfont.h +++ b/src/asfont.h @@ -35,10 +35,10 @@ public: 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); - 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); + void writeLine(Surface *surface, const std::string &text, int x, int y); + void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign); + void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign); + void writeLine(Surface *surface, const std::vector &text, int x, int y, HAlign halign, VAlign valign); SDL_Surface *surface; std::vector charpos;