diff options
author | yexo <yexo@openttd.org> | 2012-01-12 19:11:51 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2012-01-12 19:11:51 +0000 |
commit | b1a830491aa01218cf0ec699269bd5d6a107f6f8 (patch) | |
tree | 8d7a388597837627e9bba12460d25777fac50885 /src/gfx.cpp | |
parent | 1ea634fcba9a2a03b0cfe07c05d307ee0e0152c6 (diff) | |
download | openttd-b1a830491aa01218cf0ec699269bd5d6a107f6f8.tar.xz |
(svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
If you resize the window so it's smaller than default the text might still not fit
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r-- | src/gfx.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index 5dcd9a09d..55721e052 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -821,6 +821,36 @@ Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestio return box; } + +/** + * Calculates height of string (in pixels). The string is changed to a multiline string if needed. + * @param str string to check + * @param maxw maximum string width + * @return height of pixels of string when it is drawn + */ +int GetStringHeight(const char *str, int maxw) +{ + char buffer[DRAW_STRING_BUFFER]; + + strecpy(buffer, str, lastof(buffer)); + + uint32 tmp = FormatStringLinebreaks(buffer, lastof(buffer), maxw); + + return GetMultilineStringHeight(buffer, GB(tmp, 0, 16), FS_NORMAL); +} + +/** + * Calculate string bounding box for multi-line strings. + * @param str String to check. + * @param suggestion Suggested bounding box. + * @return Bounding box for the multi-line string, may be bigger than \a suggestion. + */ +Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion) +{ + Dimension box = {suggestion.width, GetStringHeight(str, suggestion.width)}; + return box; +} + /** * Draw string, possibly over multiple lines. * |