changeset 11471:3941ac1268d5 draft

(svn r15832) -Codechange: improve the aligning of right aligned/centered strings
author rubidium <rubidium@openttd.org>
date Mon, 23 Mar 2009 14:10:54 +0000
parents 9ca1973a975d
children cb478e40b8e2
files src/gfx.cpp
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -399,18 +399,26 @@
 
 	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: