summaryrefslogtreecommitdiff
path: root/gfx.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-09-05 23:02:31 +0000
committerDarkvater <Darkvater@openttd.org>2006-09-05 23:02:31 +0000
commit4721a3fcce1ef7e6f7c37c8d49ecac972933ecfd (patch)
tree16f206b170f4b50a5c5b5d51d72aa1b3daafad08 /gfx.c
parentab5135dd3801278c750d80c72830e7eadfcf438c (diff)
downloadopenttd-4721a3fcce1ef7e6f7c37c8d49ecac972933ecfd.tar.xz
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
contained newlines.
Diffstat (limited to 'gfx.c')
-rw-r--r--gfx.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/gfx.c b/gfx.c
index cfd9fa58e..308eb659a 100644
--- a/gfx.c
+++ b/gfx.c
@@ -542,8 +542,10 @@ void DrawStringMultiLine(int x, int y, StringID str, int maxw)
int GetStringWidth(const char *str)
{
FontSize size = _cur_fontsize;
- int w = 0;
+ int w, max_w;
byte c;
+
+ w = max_w = 0;
for (c = *str; c != '\0'; c = *(++str)) {
if (c >= ASCII_LETTERSTART) {
w += GetCharacterWidth(size, c);
@@ -552,9 +554,11 @@ int GetStringWidth(const char *str)
else if (c == ASCII_SETXY) str += 2;
else if (c == ASCII_TINYFONT) size = FS_SMALL;
else if (c == ASCII_BIGFONT) size = FS_LARGE;
+ else if (c == ASCII_NL && w > max_w) {max_w = w; w = 0;}
}
}
- return w;
+
+ return max(w, max_w);
}