mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 05:55:00 +02:00
ASFont: cleanups in text write methods.
This commit is contained in:
parent
ff546cdcb0
commit
1bc55392cd
@ -189,16 +189,12 @@ bool ASFont::utf8Code(unsigned char c) {
|
|||||||
return font.utf8Code(c);
|
return font.utf8Code(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASFont::write(SDL_Surface* surface, const char* text, int x, int y) {
|
|
||||||
font.write(surface, text, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, VAlign valign) {
|
||||||
switch (halign) {
|
switch (halign) {
|
||||||
case HAlignLeft:
|
case HAlignLeft:
|
||||||
break;
|
break;
|
||||||
case HAlignCenter:
|
case HAlignCenter:
|
||||||
x -= getTextWidth(text)/2;
|
x -= getTextWidth(text) / 2;
|
||||||
break;
|
break;
|
||||||
case HAlignRight:
|
case HAlignRight:
|
||||||
x -= getTextWidth(text);
|
x -= getTextWidth(text);
|
||||||
@ -218,40 +214,41 @@ void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y,
|
|||||||
|
|
||||||
font.write(surface, text, x, y);
|
font.write(surface, text, x, y);
|
||||||
}
|
}
|
||||||
void ASFont::write(SDL_Surface* surface, 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:
|
||||||
break;
|
break;
|
||||||
case VAlignMiddle:
|
case VAlignMiddle:
|
||||||
y -= (getHeight() / 2) * text->size();
|
y -= (getHeight() / 2) * text.size();
|
||||||
break;
|
break;
|
||||||
case VAlignBottom:
|
case VAlignBottom:
|
||||||
y -= getHeight()*text->size();
|
y -= getHeight() * text.size();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i=0; i<text->size(); i++) {
|
for (std::vector<std::string>::const_iterator it = text.begin(); it != text.end(); ++it) {
|
||||||
int ix = x;
|
int ix = x;
|
||||||
switch (halign) {
|
switch (halign) {
|
||||||
case HAlignLeft:
|
case HAlignLeft:
|
||||||
break;
|
break;
|
||||||
case HAlignCenter:
|
case HAlignCenter:
|
||||||
ix -= getTextWidth(text->at(i))/2;
|
ix -= getTextWidth(*it) / 2;
|
||||||
break;
|
break;
|
||||||
case HAlignRight:
|
case HAlignRight:
|
||||||
ix -= getTextWidth(text->at(i));
|
ix -= getTextWidth(*it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
font.write(surface, text->at(i), x, y+getHeight()*i);
|
font.write(surface, *it, ix, y);
|
||||||
|
y += getHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASFont::write(Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
|
void ASFont::write(Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
|
||||||
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);
|
write(surface->raw, textArr, x, y, halign, valign);
|
||||||
} else
|
} else
|
||||||
write(surface->raw, text, x, y, halign, valign);
|
write(surface->raw, text, x, y, halign, valign);
|
||||||
}
|
}
|
||||||
|
@ -48,12 +48,12 @@ public:
|
|||||||
int getLineHeight();
|
int getLineHeight();
|
||||||
int getTextWidth(const char* text);
|
int getTextWidth(const char* text);
|
||||||
int getTextWidth(const std::string& text);
|
int getTextWidth(const std::string& text);
|
||||||
void write(SDL_Surface* surface, const char* text, int x, int y);
|
|
||||||
void write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
|
|
||||||
void write(SDL_Surface* surface, std::vector<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);
|
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, HAlign halign, VAlign valign);
|
||||||
|
void write(SDL_Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign);
|
||||||
|
|
||||||
SFontPlus font;
|
SFontPlus font;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user