mirror of https://github.com/OpenTTD/OpenTTD
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.pull/11526/head
parent
33ba609290
commit
6f7153bf71
15
src/gfx.cpp
15
src/gfx.cpp
|
@ -451,6 +451,21 @@ void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
|
|||
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -103,6 +103,7 @@ void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectM
|
|||
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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue