From d9bc65cdd873f2ea438a0d91d243766a72ba5ff7 Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 31 Jul 2010 11:47:08 +0000 Subject: (svn r20256) -Codechange: add a DrawStringMultiline variant that accepts const char* instead of StringID --- src/gfx.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ src/gfx_func.h | 1 + 2 files changed, 47 insertions(+), 6 deletions(-) (limited to 'src') 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 diff --git a/src/gfx_func.h b/src/gfx_func.h index 2c7b33dc8..07c7c8130 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -112,6 +112,7 @@ DECLARE_ENUM_AS_BIT_SET(StringAlignment) int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false); int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false); +int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false); int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false); void DrawCharCentered(uint32 c, int x, int y, TextColour colour); -- cgit v1.2.3-70-g09d2