1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-10-04 02:23:15 +03:00

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.
This commit is contained in:
Maarten ter Huurne 2011-06-02 04:29:19 +02:00
parent b6a5d89bc8
commit b2896d6bac
2 changed files with 13 additions and 13 deletions

View File

@ -100,7 +100,7 @@ bool ASFont::utf8Code(unsigned char c) {
//return c>=194; //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; if (text.empty()) return;
std::string::size_type pos; 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]; srcrect.w = charpos[pos+2] - charpos[pos];
dstrect.x = x - charpos[pos+1] + 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]; x += charpos[pos+2] - charpos[pos+1];
} }
@ -165,7 +165,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) { void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign) {
switch (halign) { switch (halign) {
case HAlignLeft: case HAlignLeft:
break; break;
@ -176,10 +176,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); 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) { switch (valign) {
case VAlignTop: case VAlignTop:
break; break;
@ -190,10 +190,10 @@ 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); writeLine(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) { void ASFont::writeLine(Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) {
switch (valign) { switch (valign) {
case VAlignTop: case VAlignTop:
break; 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) { if (text.find("\n", 0) != std::string::npos) {
std::vector<std::string> textArr; std::vector<std::string> textArr;
split(textArr, text, "\n"); split(textArr, text, "\n");
write(surface->raw, textArr, x, y, halign, valign); writeLine(surface, textArr, x, y, halign, valign);
} else } else
write(surface->raw, text, x, y, halign, valign); writeLine(surface, text, x, y, halign, valign);
} }

View File

@ -35,10 +35,10 @@ 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 *surface, const std::string &text, int x, int y); void writeLine(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 writeLine(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 writeLine(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); void writeLine(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;