diff options
author | zuu <zuu@openttd.org> | 2013-06-09 12:21:44 +0000 |
---|---|---|
committer | zuu <zuu@openttd.org> | 2013-06-09 12:21:44 +0000 |
commit | e31190219872a69e4497f8d8f0fb3235c59f826b (patch) | |
tree | c73ca8de93f8773535cd46a34cd534a9b4e9976a | |
parent | 9aa1bf026443ddc65ab4381e86c294943ddc30d8 (diff) | |
download | openttd-e31190219872a69e4497f8d8f0fb3235c59f826b.tar.xz |
(svn r25343) -Add: method to count the number of lines required to draw a string with line warping
-rw-r--r-- | src/gfx.cpp | 17 | ||||
-rw-r--r-- | src/gfx_func.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index 962913495..7cfe08241 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -883,6 +883,23 @@ int GetStringHeight(StringID str, int maxw) } /** + * Calculates number of lines of string. The string is changed to a multiline string if needed. + * @param str string to check + * @param maxw maximum string width + * @return number of lines of string when it is drawn + */ +int GetStringLineCount(StringID str, int maxw) +{ + char buffer[DRAW_STRING_BUFFER]; + + GetString(buffer, str, lastof(buffer)); + + uint32 tmp = FormatStringLinebreaks(buffer, lastof(buffer), maxw); + + return 1 + GB(tmp, 0, 16); +} + +/** * Calculate string bounding box for multi-line strings. * @param str String to check. * @param suggestion Suggested bounding box. diff --git a/src/gfx_func.h b/src/gfx_func.h index 65616e618..42c2b3a5e 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -124,6 +124,7 @@ Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NOR Dimension GetStringBoundingBox(StringID strid); uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize start_fontsize = FS_NORMAL); int GetStringHeight(StringID str, int maxw); +int GetStringLineCount(StringID str, int maxw); Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion); Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion); void LoadStringWidthTable(bool monospace = false); |