mirror of https://github.com/OpenTTD/OpenTTD
(svn r15832) -Codechange: improve the aligning of right aligned/centered strings
parent
abff5eacbc
commit
c9e2e22bc0
16
src/gfx.cpp
16
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;
|
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) {
|
switch (align) {
|
||||||
case SA_LEFT:
|
case SA_LEFT:
|
||||||
right = left + w;
|
/* right + 1 = left + w */
|
||||||
|
right = left + w - 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SA_CENTER:
|
case SA_CENTER:
|
||||||
left += (right - left - w + 1) / 2;
|
/* The second + 1 is to round to the closest number */
|
||||||
right = left + w;
|
left = (right + 1 + left - w + 1) / 2;
|
||||||
|
/* right + 1 = left + w */
|
||||||
|
right = left + w - 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SA_RIGHT:
|
case SA_RIGHT:
|
||||||
left = right - w;
|
left = right + 1 - w;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue