summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-23 14:10:54 +0000
committerrubidium <rubidium@openttd.org>2009-03-23 14:10:54 +0000
commitc9e2e22bc00ae4b3aefa7a46f9170b5dde4378fe (patch)
tree1162f2f67e2ee3e7af2fce3f67e14a438593e17d
parentabff5eacbc2090ddf10791200a2373cc10ce8248 (diff)
downloadopenttd-c9e2e22bc00ae4b3aefa7a46f9170b5dde4378fe.tar.xz
(svn r15832) -Codechange: improve the aligning of right aligned/centered strings
-rw-r--r--src/gfx.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 6d6a7342e..82214aedf 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -399,18 +399,26 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
int w = GetStringBoundingBox(str).width;
+ /* right is the right most position to draw on. In this case we want to do
+ * calculations with the width of the string. In comparison right can be
+ * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
+ * So most +1/-1 additions are to move from lengthof to 'indices'.
+ */
switch (align) {
case SA_LEFT:
- right = left + w;
+ /* right + 1 = left + w */
+ right = left + w - 1;
break;
case SA_CENTER:
- left += (right - left - w + 1) / 2;
- right = left + w;
+ /* The second + 1 is to round to the closest number */
+ left = (right + 1 + left - w + 1) / 2;
+ /* right + 1 = left + w */
+ right = left + w - 1;
break;
case SA_RIGHT:
- left = right - w;
+ left = right + 1 - w;
break;
default: