diff options
author | alberth <alberth@openttd.org> | 2010-07-02 13:53:05 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-07-02 13:53:05 +0000 |
commit | 22b9bc515730e40ad834a5295d9421afeaf8802e (patch) | |
tree | 2c953357d0f0b51c676cb6f63bf8477e3a997c80 /src/gfx.cpp | |
parent | 3d329beb1b9a882fbc6530817a169ab6588e646f (diff) | |
download | openttd-22b9bc515730e40ad834a5295d9421afeaf8802e.tar.xz |
(svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r-- | src/gfx.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index a151d3676..fa9611bf1 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -527,7 +527,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last, continue; } - if ((align & SA_MASK) != SA_LEFT) { + if ((align & SA_HOR_MASK) != SA_LEFT) { DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment..."); /* For left alignment and change the left so it will roughly be in the @@ -554,7 +554,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last, } /* In case we have a RTL language we swap the alignment. */ - if (!(align & SA_FORCE) && _dynlang.text_dir == TD_RTL && align != SA_CENTER) align ^= SA_RIGHT; + if (!(align & SA_FORCE) && _dynlang.text_dir == TD_RTL && !(align & SA_STRIP) && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT; for (UChar **iter = setx_offsets.Begin(); iter != setx_offsets.End(); iter++) { UChar *to_draw = *iter; @@ -575,14 +575,14 @@ static int DrawString(int left, int right, int top, char *str, const char *last, * 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 & SA_MASK) { + switch (align & SA_HOR_MASK) { case SA_LEFT: /* right + 1 = left + w */ left = initial_left + offset; right = left + w - 1; break; - case SA_CENTER: + case SA_HOR_CENTER: left = RoundDivSU(initial_right + 1 + initial_left - w, 2); /* right + 1 = left + w */ right = left + w - 1; @@ -605,7 +605,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last, } } - return align == SA_RIGHT ? min_left : max_right; + return (align & SA_HOR_MASK) == SA_RIGHT ? min_left : max_right; } /** @@ -824,9 +824,7 @@ Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestio * @param bottom The bottom most position to draw on. * @param str String to draw. * @param colour Colour used for drawing the string, see DoDrawString() for details - * @param align The alignment of the string when drawing left-to-right. In the - * case a right-to-left language is chosen this is inverted so it - * will be drawn in the right direction. + * @param align The horizontal and vertical alignment of the string. * @param underline Whether to underline all strings * * @return The bottom to where we have written. @@ -857,7 +855,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, total_height = (num + 1) * mt; } - int y = (align == SA_CENTER) ? RoundDivSU(bottom + top - total_height, 2) : top; + int y = ((align & SA_VERT_MASK) == SA_VERT_CENTER) ? RoundDivSU(bottom + top - total_height, 2) : top; const char *src = buffer; DrawStringParams params(colour); |