mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r18143) -Codechange: allow stripping/ignoring of SETX(Y) during DrawString
This commit is contained in:
parent
cbc12fdd86
commit
e297f79b7f
17
src/gfx.cpp
17
src/gfx.cpp
@ -327,9 +327,10 @@ static UChar *HandleBiDiAndArabicShapes(UChar *buffer)
|
|||||||
* If the string is truncated, add three dots ('...') to show this.
|
* If the string is truncated, add three dots ('...') to show this.
|
||||||
* @param *str string that is checked and possibly truncated
|
* @param *str string that is checked and possibly truncated
|
||||||
* @param maxw maximum width in pixels of the string
|
* @param maxw maximum width in pixels of the string
|
||||||
|
* @param ignore_setxy whether to ignore SETX(Y) or not
|
||||||
* @return new width of (truncated) string
|
* @return new width of (truncated) string
|
||||||
*/
|
*/
|
||||||
static int TruncateString(char *str, int maxw)
|
static int TruncateString(char *str, int maxw, bool ignore_setxy)
|
||||||
{
|
{
|
||||||
int w = 0;
|
int w = 0;
|
||||||
FontSize size = _cur_fontsize;
|
FontSize size = _cur_fontsize;
|
||||||
@ -353,10 +354,10 @@ static int TruncateString(char *str, int maxw)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (c == SCC_SETX) {
|
if (c == SCC_SETX) {
|
||||||
w = *str;
|
if (!ignore_setxy) w = *str;
|
||||||
str++;
|
str++;
|
||||||
} else if (c == SCC_SETXY) {
|
} else if (c == SCC_SETXY) {
|
||||||
w = *str;
|
if (!ignore_setxy) w = *str;
|
||||||
str += 2;
|
str += 2;
|
||||||
} else if (c == SCC_TINYFONT) {
|
} else if (c == SCC_TINYFONT) {
|
||||||
size = FS_SMALL;
|
size = FS_SMALL;
|
||||||
@ -446,7 +447,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
|||||||
int initial_right = right;
|
int initial_right = right;
|
||||||
int initial_top = top;
|
int initial_top = top;
|
||||||
|
|
||||||
if (truncate) TruncateString(str, right - left + 1);
|
if (truncate) TruncateString(str, right - left + 1, (align & SA_STRIP) == SA_STRIP);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To support SETX and SETXY properly with RTL languages we have to
|
* To support SETX and SETXY properly with RTL languages we have to
|
||||||
@ -480,6 +481,14 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (align & SA_STRIP) {
|
||||||
|
/* We do not want to keep the SETX(Y)!. It was already copied, so
|
||||||
|
* remove it and undo the incrementing of the pointer! */
|
||||||
|
*p-- = '\0';
|
||||||
|
loc += len + (c == SCC_SETXY ? 2 : 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ((align & SA_MASK) != SA_LEFT) {
|
if ((align & SA_MASK) != SA_LEFT) {
|
||||||
DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
|
DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
|
||||||
|
|
||||||
|
@ -100,6 +100,7 @@ enum StringAlignment {
|
|||||||
SA_RIGHT, ///< Right align the text
|
SA_RIGHT, ///< Right align the text
|
||||||
SA_MASK = 3, ///< Mask for base alignment
|
SA_MASK = 3, ///< Mask for base alignment
|
||||||
SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
|
SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
|
||||||
|
SA_STRIP = 8, ///< Strip the SETX/SETXY commands from the string
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(StringAlignment);
|
DECLARE_ENUM_AS_BIT_SET(StringAlignment);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user