Changeset - r11466:58245d5f39af
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-03-23 14:10:54
rubidium@openttd.org
(svn r15832) -Codechange: improve the aligning of right aligned/centered strings
1 file changed with 12 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -396,24 +396,32 @@ static int DrawString(int left, int righ
 
{
 
	if (truncate) TruncateString(str, right - left);
 
	HandleBiDiAndArabicShapes(str, 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:
 
			NOT_REACHED();
 
	}
 
	ReallyDoDrawString(str, left, top, colour, !truncate);
0 comments (0 inline, 0 general)