Changeset - r25395:65af9d4639ed
[Not reviewed]
master
0 3 0
rubidium42 - 3 years ago 2021-05-06 14:32:57
rubidium@openttd.org
Codechange: add DrawString(Multiline) that accepts std::string&
3 files changed with 48 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -673,6 +673,28 @@ int DrawString(int left, int right, int 
 
 * @return In case of left or center alignment the right most pixel we have drawn to.
 
 *         In case of right alignment the left most pixel we have drawn to.
 
 */
 
int DrawString(int left, int right, int top, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 
{
 
	return DrawString(left, right, top, str.c_str(), colour, align, underline, fontsize);
 
}
 

	
 
/**
 
 * Draw string, possibly truncated to make it fit in its allocated space
 
 *
 
 * @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 str    String to draw.
 
 * @param colour Colour used for drawing the string, for details see _string_colourmap in
 
 *               table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
 
 * @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 underline Whether to underline what has been drawn or not.
 
 * @param fontsize The size of the initial characters.
 
 * @return In case of left or center alignment the right most pixel we have drawn to.
 
 *         In case of right alignment the left most pixel we have drawn to.
 
 */
 
int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 
{
 
	char buffer[DRAW_STRING_BUFFER];
 
@@ -806,6 +828,28 @@ int DrawStringMultiLine(int left, int ri
 
	return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line;
 
}
 

	
 

	
 
/**
 
 * 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, for details see _string_colourmap in
 
 *               table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
 
 * @param align  The horizontal and vertical alignment of the string.
 
 * @param underline Whether to underline all strings
 
 * @param fontsize The size of the initial characters.
 
 *
 
 * @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 std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
 
{
 
	return DrawStringMultiLine(left, right, top, bottom, str.c_str(), colour, align, underline, fontsize);
 
}
 

	
 
/**
 
 * Draw string, possibly over multiple lines.
 
 *
src/gfx_func.h
Show inline comments
 
@@ -92,8 +92,10 @@ void DrawSpriteViewport(SpriteID img, Pa
 
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
 

	
 
int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
 
int DrawString(int left, int right, int top, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
 
int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
 
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, FontSize fontsize = FS_NORMAL);
 
int DrawStringMultiLine(int left, int right, int top, int bottom, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
 
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, FontSize fontsize = FS_NORMAL);
 

	
 
void DrawCharCentered(WChar c, const Rect &r, TextColour colour);
src/industry_gui.cpp
Show inline comments
 
@@ -572,12 +572,12 @@ public:
 
				/* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
 
				GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
 
				std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
 
				y = DrawStringMultiLine(left, right, y, bottom, cargostring.c_str());
 
				y = DrawStringMultiLine(left, right, y, bottom, cargostring);
 

	
 
				/* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
 
				GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
 
				cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
 
				y = DrawStringMultiLine(left, right, y, bottom, cargostring.c_str());
 
				y = DrawStringMultiLine(left, right, y, bottom, cargostring);
 

	
 
				/* Get the additional purchase info text, if it has not already been queried. */
 
				if (HasBit(indsp->callback_mask, CBM_IND_FUND_MORE_TEXT)) {
0 comments (0 inline, 0 general)