Changeset - r28212:27c374342e82
[Not reviewed]
master
0 4 0
Peter Nelson - 12 months ago 2023-11-30 18:10:07
peter1138@openttd.org
Codechange: Make a generic DrawRectOutline function from DrawOutline. (#11524)

This allows drawing an outline from Rect, not just constrained to a Widget's Rect. And reduces duplication a little.
4 files changed with 19 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -452,6 +452,21 @@ void DrawBox(int x, int y, int dx1, int 
 
}
 

	
 
/**
 
 * Draw the outline of a Rect
 
 * @param r Rect to draw.
 
 * @param colour Colour of the outline.
 
 * @param width Width of the outline.
 
 * @param dash Length of dashes for dashed lines. 0 means solid lines.
 
 */
 
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
 
{
 
	GfxDrawLine(r.left,  r.top,    r.right, r.top,    colour, width, dash);
 
	GfxDrawLine(r.left,  r.top,    r.left,  r.bottom, colour, width, dash);
 
	GfxDrawLine(r.right, r.top,    r.right, r.bottom, colour, width, dash);
 
	GfxDrawLine(r.left,  r.bottom, r.right, r.bottom, colour, width, dash);
 
}
 

	
 
/**
 
 * Set the colour remap to be for the given colour.
 
 * @param colour the new colour of the remap.
 
 */
src/gfx_func.h
Show inline comments
 
@@ -103,6 +103,7 @@ void GfxFillRect(int left, int top, int 
 
void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE);
 
void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0);
 
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
 
void DrawRectOutline(const Rect &r, int colour, int width = 1, int dash = 0);
 

	
 
/* Versions of DrawString/DrawStringMultiLine that accept a Rect instead of separate left, right, top and bottom parameters. */
 
static inline int DrawString(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL)
src/industry_gui.cpp
Show inline comments
 
@@ -2146,10 +2146,7 @@ struct CargoesField {
 
				int ypos1 = ypos + vert_inter_industry_space / 2;
 
				int ypos2 = ypos + normal_height - 1 - vert_inter_industry_space / 2;
 
				int xpos2 = xpos + industry_width - 1;
 
				GfxDrawLine(xpos,  ypos1, xpos2, ypos1, INDUSTRY_LINE_COLOUR);
 
				GfxDrawLine(xpos,  ypos1, xpos,  ypos2, INDUSTRY_LINE_COLOUR);
 
				GfxDrawLine(xpos,  ypos2, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
 
				GfxDrawLine(xpos2, ypos1, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
 
				DrawRectOutline({xpos, ypos1, xpos2, ypos2}, INDUSTRY_LINE_COLOUR);
 
				ypos += (normal_height - GetCharacterHeight(FS_NORMAL)) / 2;
 
				if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) {
 
					const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type);
src/widget.cpp
Show inline comments
 
@@ -922,15 +922,11 @@ int Window::SortButtonWidth()
 

	
 
bool _draw_widget_outlines;
 

	
 
void DrawOutline(const Window *, const NWidgetBase *wid)
 
static void DrawOutline(const Window *, const NWidgetBase *wid)
 
{
 
	if (!_draw_widget_outlines || wid->current_x == 0 || wid->current_y == 0) return;
 

	
 
	Rect r = wid->GetCurrentRect();
 
	GfxDrawLine(r.left,  r.top,    r.right, r.top,    PC_WHITE, 1, 4);
 
	GfxDrawLine(r.left,  r.top,    r.left,  r.bottom, PC_WHITE, 1, 4);
 
	GfxDrawLine(r.right, r.top,    r.right, r.bottom, PC_WHITE, 1, 4);
 
	GfxDrawLine(r.left,  r.bottom, r.right, r.bottom, PC_WHITE, 1, 4);
 
	DrawRectOutline(wid->GetCurrentRect(), PC_WHITE, 1, 4);
 
}
 

	
 
/**
0 comments (0 inline, 0 general)