[+] Added special "~|" formatting symbol to specify the position symbol (useful for making translations with different string length)
This commit is contained in:
parent
f3765d485d
commit
2e91d391f3
2 changed files with 21 additions and 3 deletions
|
@ -81,7 +81,10 @@ extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e);
|
|||
|
||||
if (this->Text) {
|
||||
text = EvalString(this->Text);
|
||||
if (this->Centered) {
|
||||
int pos;
|
||||
if ((pos = text.find("~|")) != std::string::npos) {
|
||||
x += (label.Draw(x - font.getWidth(text.substr(0, pos)), y, text) - font.getWidth(text.substr(0, pos)));
|
||||
} else if (this->Centered) {
|
||||
x += (label.DrawCentered(x, y, text) * 2);
|
||||
} else {
|
||||
x += label.Draw(x, y, text);
|
||||
|
@ -153,7 +156,11 @@ extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e);
|
|||
snprintf(buf, sizeof(buf), this->Format.c_str(), usi1.i);
|
||||
}
|
||||
|
||||
if (this->Centered) {
|
||||
char *pos;
|
||||
if ((pos = strstr(buf, "~|")) != NULL) {
|
||||
std::string buf2(buf);
|
||||
label.Draw(this->Pos.x - font.getWidth(buf2.substr(0, pos - buf)), this->Pos.y, buf);
|
||||
} else if (this->Centered) {
|
||||
label.DrawCentered(this->Pos.x, this->Pos.y, buf);
|
||||
} else {
|
||||
label.Draw(this->Pos.x, this->Pos.y, buf);
|
||||
|
@ -194,7 +201,11 @@ extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e);
|
|||
snprintf(buf, sizeof(buf), this->Format.c_str(), usi1.i, usi2.i);
|
||||
}
|
||||
}
|
||||
if (this->Centered) {
|
||||
char *pos;
|
||||
if ((pos = strstr(buf, "~|")) != NULL) {
|
||||
std::string buf2(buf);
|
||||
label.Draw(this->Pos.x - font.getWidth(buf2.substr(0, pos - buf)), this->Pos.y, buf);
|
||||
} else if (this->Centered) {
|
||||
label.DrawCentered(this->Pos.x, this->Pos.y, buf);
|
||||
} else {
|
||||
label.Draw(this->Pos.x, this->Pos.y, buf);
|
||||
|
|
|
@ -359,6 +359,10 @@ int CFont::Width(const std::string &text) const
|
|||
DynamicLoad();
|
||||
while (GetUTF8(text, pos, utf8)) {
|
||||
if (utf8 == '~') {
|
||||
if (text[pos] == '|') {
|
||||
++pos;
|
||||
continue;
|
||||
}
|
||||
if (pos >= text.size()) { // bad formatted string
|
||||
break;
|
||||
}
|
||||
|
@ -510,6 +514,9 @@ int CLabel::DoDrawText(int x, int y,
|
|||
case '~':
|
||||
++pos;
|
||||
break;
|
||||
case '|':
|
||||
++pos;
|
||||
continue;
|
||||
case '!':
|
||||
if (fc != reverse) {
|
||||
fc = reverse;
|
||||
|
|
Loading…
Reference in a new issue