summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-07-31 11:47:08 +0000
committeryexo <yexo@openttd.org>2010-07-31 11:47:08 +0000
commitd9bc65cdd873f2ea438a0d91d243766a72ba5ff7 (patch)
treeb1509c1cea499733c6c7e845c2a2c4d962fe0190 /src/gfx.cpp
parentd6eab96a220a9e3c896a4e78831228992446efd5 (diff)
downloadopenttd-d9bc65cdd873f2ea438a0d91d243766a72ba5ff7.tar.xz
(svn r20256) -Codechange: add a DrawStringMultiline variant that accepts const char* instead of StringID
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp52
1 files changed, 46 insertions, 6 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 4180be1d6..bbb93af8f 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -822,13 +822,14 @@ Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestio
* @param top The top most position to draw on.
* @param bottom The bottom most position to draw on.
* @param str String to draw.
+ * @param last The end of the string buffer to draw.
* @param colour Colour used for drawing the string, see DoDrawString() for details
* @param align The horizontal and vertical alignment of the string.
* @param underline Whether to underline all strings
*
* @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
*/
-int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline)
+static int DrawStringMultiLine(int left, int right, int top, int bottom, char *str, const char *last, TextColour colour, StringAlignment align, bool underline)
{
int maxw = right - left + 1;
int maxh = bottom - top + 1;
@@ -837,10 +838,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
* do we really want to support fonts of 0 or less pixels high? */
if (maxh <= 0) return top;
- char buffer[DRAW_STRING_BUFFER];
- GetString(buffer, str, lastof(buffer));
-
- uint32 tmp = FormatStringLinebreaks(buffer, lastof(buffer), maxw);
+ uint32 tmp = FormatStringLinebreaks(str, last, maxw);
int num = GB(tmp, 0, 16) + 1;
int mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
@@ -876,7 +874,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
default: NOT_REACHED();
}
- const char *src = buffer;
+ const char *src = str;
DrawStringParams params(colour);
int written_top = bottom; // Uppermost position of rendering a line of text
for (;;) {
@@ -916,6 +914,48 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
}
}
+/**
+ * Draw string, possibly over multiple lines.
+ *
+ * @param left The left most position to draw on.
+ * @param right The right most position to draw on.
+ * @param top The top most position to draw on.
+ * @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 horizontal and vertical alignment of the string.
+ * @param underline Whether to underline all strings
+ *
+ * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
+ */
+int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline)
+{
+ char buffer[DRAW_STRING_BUFFER];
+ strecpy(buffer, str, lastof(buffer));
+ return DrawStringMultiLine(left, right, top, bottom, buffer, lastof(buffer), colour, align, underline);
+}
+
+/**
+ * Draw string, possibly over multiple lines.
+ *
+ * @param left The left most position to draw on.
+ * @param right The right most position to draw on.
+ * @param top The top most position to draw on.
+ * @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 horizontal and vertical alignment of the string.
+ * @param underline Whether to underline all strings
+ *
+ * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
+ */
+int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline)
+{
+ char buffer[DRAW_STRING_BUFFER];
+ GetString(buffer, str, lastof(buffer));
+ return DrawStringMultiLine(left, right, top, bottom, buffer, lastof(buffer), colour, align, underline);
+}
+
/** Return the string dimension in pixels. The height and width are returned
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only
* supported as the first character of the string. The returned dimensions