Merge branch 'master' into jgrpp

# Conflicts:
#	src/core/geometry_type.hpp
#	src/error_gui.cpp
#	src/rail_gui.cpp
#	src/tree_gui.cpp
#	src/vehicle_gui.cpp
#	src/widgets/dropdown.cpp
pull/461/head
Jonathan G Rennison 2 years ago
commit 5bbf1f5375

@ -265,10 +265,10 @@ void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoff
VehicleSpriteSeq seq;
GetAircraftIcon(engine, image_type, &seq);
Rect16 rect = seq.GetBounds();
Rect rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
width = UnScaleGUI(rect.right - rect.left + 1);
height = UnScaleGUI(rect.bottom - rect.top + 1);
width = UnScaleGUI(rect.Width());
height = UnScaleGUI(rect.Height());
xoffs = UnScaleGUI(rect.left);
yoffs = UnScaleGUI(rect.top);
}

@ -84,9 +84,9 @@ void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID s
VehicleSpriteSeq seq;
v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
Rect16 rect = seq.GetBounds();
Rect rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
int width = UnScaleGUI(rect.right - rect.left + 1);
int width = UnScaleGUI(rect.Width());
int x_offs = UnScaleGUI(rect.left);
int x = rtl ? right - width - x_offs : left - x_offs;
bool helicopter = v->subtype == AIR_HELICOPTER;
@ -107,6 +107,6 @@ void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID s
if (v->index == selection) {
x += x_offs;
y += UnScaleGUI(rect.top) + y_offs - heli_offs;
DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.bottom - rect.top + 1) + heli_offs + 1, COLOUR_WHITE, FR_BORDERONLY);
DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.Height()) + heli_offs + 1, COLOUR_WHITE, FR_BORDERONLY);
}
}

@ -392,7 +392,7 @@ public:
case WID_AP_AIRPORT_SPRITE:
if (this->preview_sprite != 0) {
Dimension d = GetSpriteSize(this->preview_sprite);
DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), (r.left + r.right - d.width) / 2, (r.top + r.bottom - d.height) / 2);
DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), CenterBounds(r.left, r.right, d.width), CenterBounds(r.top, r.bottom, d.height));
}
break;

@ -59,8 +59,8 @@ public:
void Initialize(const Rect &r)
{
this->tile = TileXY(r.left, r.top);
this->w = r.right - r.left + 1;
this->h = r.bottom - r.top + 1;
this->w = r.Width();
this->h = r.Height();
this->data.clear();
this->data.resize(Index(w, h));
}

@ -651,18 +651,17 @@ public:
return true;
}
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override
void Draw(const Rect &r, bool sel, Colours bg_colour) const override
{
bool rtl = _current_text_dir == TD_RTL;
int height = bottom - top;
int icon_y_offset = height / 2;
int text_y_offset = (height - FONT_HEIGHT_NORMAL) / 2 + 1;
int icon_y = CenterBounds(r.top, r.bottom, 0);
int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL);
DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + (this->result % COLOUR_END),
rtl ? right - 2 - ScaleGUITrad(14) : left + ScaleGUITrad(14) + 2,
top + icon_y_offset);
DrawString(rtl ? left + 2 : left + ScaleGUITrad(28) + 4,
rtl ? right - ScaleGUITrad(28) - 4 : right - 2,
top + text_y_offset, this->String(), sel ? TC_WHITE : TC_BLACK);
rtl ? r.right - 2 - ScaleGUITrad(14) : r.left + ScaleGUITrad(14) + 2,
icon_y);
DrawString(rtl ? r.left + 2 : r.left + ScaleGUITrad(28) + 4,
rtl ? r.right - ScaleGUITrad(28) - 4 : r.right - 2,
text_y, this->String(), sel ? TC_WHITE : TC_BLACK);
}
};
@ -2567,7 +2566,7 @@ struct CompanyWindow : Window
Point offset;
Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
d.height -= offset.y;
DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, (r.top + r.bottom - d.height) / 2 - offset.y);
DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, CenterBounds(r.top, r.bottom, d.height) - offset.y);
break;
}

@ -108,17 +108,16 @@ struct EnginePreviewWindow : Window {
EngineID engine = this->window_number;
SetDParam(0, GetEngineCategoryName(engine));
int y = r.top + GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, r.right - r.left + 1);
y = DrawStringMultiLine(r.left, r.right, r.top, y, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_CENTER) + WD_PAR_VSEP_WIDE;
int y = DrawStringMultiLine(r, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WD_PAR_VSEP_WIDE;
SetDParam(0, engine);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
DrawString(r.left, r.right, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
y += FONT_HEIGHT_NORMAL;
DrawVehicleEngine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
y += this->vehicle_space;
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
}
void OnClick(Point pt, int widget, int click_count) override

@ -35,7 +35,7 @@ static const NWidgetPart _nested_errmsg_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION, STR_NULL),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_RED),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_MESSAGE), SetPadding(0, 2, 0, 2), SetMinimalSize(236, 32),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_MESSAGE), SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT), SetFill(1, 0), SetMinimalSize(236, 0),
EndContainer(),
};
@ -52,9 +52,9 @@ static const NWidgetPart _nested_errmsg_face_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_NULL),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_RED),
NWidget(NWID_HORIZONTAL), SetPIP(2, 1, 2),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_FACE), SetMinimalSize(92, 119), SetFill(0, 1), SetPadding(2, 0, 1, 0),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_MESSAGE), SetFill(0, 1), SetMinimalSize(238, 123),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_FACE), SetPadding(2, 0, 2, 2), SetFill(0, 1), SetMinimalSize(92, 119),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_MESSAGE), SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT), SetFill(1, 1), SetMinimalSize(236, 0),
EndContainer(),
EndContainer(),
};
@ -203,14 +203,13 @@ public:
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
int text_width = std::max(0, (int)size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
this->height_summary = GetStringHeight(this->summary_msg, text_width);
this->height_detailed = (this->detailed_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->detailed_msg, text_width);
this->height_extra = (this->extra_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->extra_msg, text_width);
this->height_summary = GetStringHeight(this->summary_msg, size->width);
this->height_detailed = (this->detailed_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->detailed_msg, size->width);
this->height_extra = (this->extra_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->extra_msg, size->width);
if (this->textref_stack_size > 0) StopTextRefStackUsage();
uint panel_height = WD_FRAMERECT_TOP + this->height_summary + WD_FRAMERECT_BOTTOM;
uint panel_height = this->height_summary;
if (this->detailed_msg != INVALID_STRING_ID) panel_height += this->height_detailed + WD_PAR_VSEP_WIDE;
if (this->extra_msg != INVALID_STRING_ID) panel_height += this->height_extra + WD_PAR_VSEP_WIDE;
@ -287,34 +286,25 @@ public:
if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
if (this->detailed_msg == INVALID_STRING_ID) {
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
this->summary_msg, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, this->summary_msg, TC_FROMSTRING, SA_CENTER);
} else if (this->extra_msg == INVALID_STRING_ID) {
int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2;
/* Extra space when message is shorter than company face window */
int extra = (r.Height() - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2;
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
int top = r.top + WD_FRAMERECT_TOP;
int bottom = top + this->height_summary + extra;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->summary_msg, TC_WHITE, SA_CENTER);
bottom = r.bottom - WD_FRAMERECT_BOTTOM;
top = bottom - this->height_detailed - extra;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->detailed_msg, TC_WHITE, SA_CENTER);
DrawStringMultiLine(r.WithHeight(this->height_summary + extra, false), this->summary_msg, TC_WHITE, SA_CENTER);
DrawStringMultiLine(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg, TC_WHITE, SA_CENTER);
} else {
int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed - this->height_extra - (WD_PAR_VSEP_WIDE * 2)) / 3;
/* Extra space when message is shorter than company face window */
int extra = (r.Height() - this->height_summary - this->height_detailed - this->height_extra - (WD_PAR_VSEP_WIDE * 2)) / 3;
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
int top = r.top + WD_FRAMERECT_TOP;
int bottom = top + this->height_summary + extra;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->summary_msg, TC_WHITE, SA_CENTER);
top = bottom + WD_PAR_VSEP_WIDE;
bottom = top + this->height_detailed + extra;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->detailed_msg, TC_WHITE, SA_CENTER);
bottom = r.bottom - WD_FRAMERECT_BOTTOM;
top = bottom - this->height_extra - extra;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->extra_msg, TC_WHITE, SA_CENTER);
Rect top_section = r.WithHeight(this->height_summary + extra, false);
Rect bottom_section = r.WithHeight(this->height_extra + extra, true);
Rect middle_section = { top_section.left, top_section.bottom, top_section.right, bottom_section.top };
DrawStringMultiLine(top_section, this->summary_msg, TC_WHITE, SA_CENTER);
DrawStringMultiLine(middle_section, this->detailed_msg, TC_WHITE, SA_CENTER);
DrawStringMultiLine(bottom_section, this->extra_msg, TC_WHITE, SA_CENTER);
}
if (this->textref_stack_size > 0) StopTextRefStackUsage();

@ -115,6 +115,42 @@ void GfxDrawLine(const DrawPixelInfo *dpi, int left, int top, int right, int bot
inline void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0) { GfxDrawLine(_cur_dpi, left, top, right, bottom, colour, width, dash); }
void DrawBox(const DrawPixelInfo *dpi, int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
/* Versions of DrawString/DrawStringMultiLine that accept a Rect instead of separate left, right, top and bottom parameters. */
static inline int DrawString(const Rect &r, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL)
{
return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
}
static inline int DrawString(const Rect &r, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL)
{
return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
}
static inline int DrawString(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL)
{
return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
}
static inline int DrawStringMultiLine(const Rect &r, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL)
{
return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
}
static inline int DrawStringMultiLine(const Rect &r, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL)
{
return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
}
static inline int DrawStringMultiLine(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL)
{
return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
}
static inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FILLRECT_OPAQUE)
{
GfxFillRect(r.left, r.top, r.right, r.bottom, colour, mode);
}
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize = FS_NORMAL);
Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize = FS_NORMAL);
@ -147,7 +183,7 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int heigh
*/
static inline int CenterBounds(int min, int max, int size)
{
return min + (max - min - size + 1) / 2;
return (min + max - size + 1) / 2;
}
/* window.cpp */

@ -1263,7 +1263,7 @@ struct PerformanceRatingDetailWindow : Window {
CompanyID cid = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
int offset = (cid == this->company) ? 1 : 0;
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, (r.left + r.right - sprite_size.width) / 2 + offset, (r.top + r.bottom - sprite_size.height) / 2 + offset);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width) + offset, CenterBounds(r.top, r.bottom, sprite_size.height) + offset);
return;
}

@ -2957,8 +2957,8 @@ struct IndustryCargoesWindow : public Window {
if (widget != WID_IC_PANEL) return;
DrawPixelInfo tmp_dpi, *old_dpi;
int width = r.right - r.left + 1;
int height = r.bottom - r.top + 1 - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM;
int width = r.Width();
int height = r.Height() - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM;
if (!FillDrawPixelInfo(&tmp_dpi, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, width, height)) return;
old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;

@ -761,7 +761,7 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, (r.left + r.right + 1 - sprite_size.width) / 2, (r.top + r.bottom + 1 - sprite_size.height) / 2);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
}
if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
uint8 colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST];
@ -775,14 +775,14 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
str = STR_LINKGRAPH_LEGEND_SATURATED;
}
if (str != STR_NULL) {
DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER);
DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_SMALL), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER);
}
}
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return;
CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, cargo->legend_colour);
DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER);
DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_SMALL), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER);
}
}

@ -882,7 +882,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
int bottom = wi->pos_y + wi->current_y - 1;
DrawFrameRect(clearbtn_left, top, clearbtn_right, bottom, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, clearbtn_left + WD_IMGBTN_LEFT + (wi->IsLowered() ? 1 : 0), (top + bottom - sprite_size.height) / 2 + (wi->IsLowered() ? 1 : 0));
DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, clearbtn_left + WD_IMGBTN_LEFT + (wi->IsLowered() ? 1 : 0), CenterBounds(top, bottom, sprite_size.height) + (wi->IsLowered() ? 1 : 0));
if (this->text.bytes == 1) GfxFillRect(clearbtn_left + 1, top + 1, clearbtn_right - 1, bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
DrawFrameRect(left, top, right, bottom, wi->colour, FR_LOWERED | FR_DARKENED);

@ -474,7 +474,7 @@ struct NewGRFInspectWindow : Window {
if (u == v) sel_end = total_width;
}
int width = r.right + 1 - r.left - WD_BEVEL_LEFT - WD_BEVEL_RIGHT;
int width = r.Width() - WD_BEVEL_LEFT - WD_BEVEL_RIGHT;
int skip = 0;
if (total_width > width) {
int sel_center = (sel_start + sel_end) / 2;
@ -483,7 +483,7 @@ struct NewGRFInspectWindow : Window {
GrfSpecFeature f = GetFeatureNum(this->window_number);
int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height;
int y = (r.top + r.bottom - h) / 2;
int y = CenterBounds(r.top, r.bottom, h);
DrawVehicleImage(v->First(), r.left + WD_BEVEL_LEFT, r.right - WD_BEVEL_RIGHT, y + 1, INVALID_VEHICLE, EIT_IN_DETAILS, skip);
/* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */
@ -1301,8 +1301,8 @@ struct SpriteAlignerWindow : Window {
case WID_SA_SPRITE: {
/* Center the sprite ourselves */
const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL);
int width = r.right - r.left + 1 - WD_BEVEL_LEFT - WD_BEVEL_RIGHT;
int height = r.bottom - r.top + 1 - WD_BEVEL_TOP - WD_BEVEL_BOTTOM;
int width = r.Width() - WD_BEVEL_LEFT - WD_BEVEL_RIGHT;
int height = r.Height() - WD_BEVEL_TOP - WD_BEVEL_BOTTOM;
int x = -UnScaleGUI(spr->x_offs) + (width - UnScaleGUI(spr->width) ) / 2;
int y = -UnScaleGUI(spr->y_offs) + (height - UnScaleGUI(spr->height)) / 2;

@ -901,7 +901,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_NEWGRF_INFO_TITLE:
/* Create the nice grayish rectangle at the details top. */
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_DARK_BLUE);
DrawString(r.left, r.right, (r.top + r.bottom - FONT_HEIGHT_NORMAL) / 2, STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
break;
case WID_NS_NEWGRF_INFO: {

@ -465,7 +465,7 @@ struct NewsWindow : Window {
case WID_N_VEH_SPR: {
assert(this->ni->reftype1 == NR_ENGINE);
EngineID engine = this->ni->ref1;
DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
break;
}

@ -351,7 +351,7 @@ public:
DrawPixelInfo tmp_dpi;
/* Set up a clipping area for the preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
if (spec->grf_prop.grffile == nullptr) {
@ -378,7 +378,7 @@ public:
}
DrawPixelInfo tmp_dpi;
/* Set up a clipping area for the preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
if (spec->grf_prop.grffile == nullptr) {

@ -1398,7 +1398,7 @@ public:
switch (GB(widget, 0, 16)) {
case WID_BRAS_PLATFORM_DIR_X:
/* Set up a clipping area for the '/' station preview */
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
int x = ScaleGUITrad(31) + 1;
@ -1412,7 +1412,7 @@ public:
case WID_BRAS_PLATFORM_DIR_Y:
/* Set up a clipping area for the '\' station preview */
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
int x = ScaleGUITrad(31) + 1;
@ -1449,7 +1449,7 @@ public:
}
/* Set up a clipping area for the station preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
int x = ScaleGUITrad(31) + 1;
@ -1822,15 +1822,13 @@ private:
* @param widget_index index of this widget in the window
* @param image the sprite to draw
*/
void DrawSignalSprite(byte widget_index, PalSpriteID image) const
void DrawSignalSprite(const Rect &r, int widget_index, PalSpriteID image) const
{
Point offset;
Dimension sprite_size = GetSpriteSize(image.sprite, &offset);
const NWidgetBase *widget = this->GetWidget<NWidgetBase>(widget_index);
int x = widget->pos_x - offset.x +
(widget->current_x - sprite_size.width + offset.x) / 2; // centered
int y = widget->pos_y - sig_sprite_bottom_offset + WD_IMGBTN_TOP +
(widget->current_y - WD_IMGBTN_TOP - WD_IMGBTN_BOTTOM + sig_sprite_size.height) / 2; // aligned to bottom
int x = CenterBounds(r.left, r.right, sprite_size.width - offset.x);
int y = r.top - sig_sprite_bottom_offset + WD_IMGBTN_TOP +
(r.bottom - r.top - WD_IMGBTN_TOP - WD_IMGBTN_BOTTOM + sig_sprite_size.height) / 2; // aligned to bottom
DrawSprite(image.sprite, image.pal,
x + this->IsWidgetLowered(widget_index),
@ -2005,7 +2003,7 @@ public:
sprite = GetRailTypeInfo(_cur_railtype)->gui_sprites.signals[type][var][this->IsWidgetLowered(widget)];
}
this->DrawSignalSprite(widget, sprite);
this->DrawSignalSprite(r, widget, sprite);
}
}

@ -174,10 +174,10 @@ void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs
VehicleSpriteSeq seq;
GetRoadVehIcon(engine, image_type, &seq);
Rect16 rect = seq.GetBounds();
Rect rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
width = UnScaleGUI(rect.right - rect.left + 1);
height = UnScaleGUI(rect.bottom - rect.top + 1);
width = UnScaleGUI(rect.Width());
height = UnScaleGUI(rect.Height());
xoffs = UnScaleGUI(rect.left);
yoffs = UnScaleGUI(rect.top);
}

@ -155,7 +155,7 @@ ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, Scr
if ((station_type & ScriptStation::STATION_AIRPORT) != 0) station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG);
if ((station_type & ScriptStation::STATION_DOCK) != 0) station_type_value |= (1 << ::STATION_DOCK) | (1 << ::STATION_OILRIG);
TileArea ta(::TileXY(rect->left, rect->top), rect->right - rect->left + 1, rect->bottom - rect->top + 1);
TileArea ta(::TileXY(rect->left, rect->top), rect->Width(), rect->Height());
for (TileIndex cur_tile : ta) {
if (!::IsTileType(cur_tile, MP_STATION)) continue;
if (::GetStationIndex(cur_tile) != station_id) continue;

@ -127,10 +127,10 @@ void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, i
VehicleSpriteSeq seq;
GetShipIcon(engine, image_type, &seq);
Rect16 rect = seq.GetBounds();
Rect rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
width = UnScaleGUI(rect.right - rect.left + 1);
height = UnScaleGUI(rect.bottom - rect.top + 1);
width = UnScaleGUI(rect.Width());
height = UnScaleGUI(rect.Height());
xoffs = UnScaleGUI(rect.left);
yoffs = UnScaleGUI(rect.top);
}

@ -37,9 +37,9 @@ void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selec
VehicleSpriteSeq seq;
v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
Rect16 rect = seq.GetBounds();
Rect rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
int width = UnScaleGUI(rect.right - rect.left + 1);
int width = UnScaleGUI(rect.Width());
int x_offs = UnScaleGUI(rect.left);
int x = rtl ? right - width - x_offs : left - x_offs;
@ -49,7 +49,7 @@ void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selec
if (v->index == selection) {
x += x_offs;
y += UnScaleGUI(rect.top);
DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.bottom - rect.top + 1) + 1, COLOUR_WHITE, FR_BORDERONLY);
DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleGUI(rect.Height()) + 1, COLOUR_WHITE, FR_BORDERONLY);
}
}

@ -1242,13 +1242,13 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
switch (widget) {
case WID_SM_MAP: {
DrawPixelInfo new_dpi;
if (!FillDrawPixelInfo(&new_dpi, r.left + 1, r.top + 1, r.right - r.left - 1, r.bottom - r.top - 1)) return;
if (!FillDrawPixelInfo(&new_dpi, r.left + 1, r.top + 1, r.Width(), r.Height())) return;
this->DrawSmallMap(&new_dpi);
break;
}
case WID_SM_LEGEND: {
uint columns = this->GetNumberColumnsLegend(r.right - r.left + 1);
uint columns = this->GetNumberColumnsLegend(r.Width());
uint number_of_rows = this->GetNumberRowsLegend(columns);
bool rtl = _current_text_dir == TD_RTL;
uint y_org = r.top + WD_FRAMERECT_TOP;
@ -1750,8 +1750,8 @@ void SmallMapWindow::SmallMapCenterOnCurrentPos()
*/
Point SmallMapWindow::GetStationMiddle(const Station *st) const
{
int x = (st->rect.right + st->rect.left + 1) / 2;
int y = (st->rect.bottom + st->rect.top + 1) / 2;
int x = CenterBounds(st->rect.left, st->rect.right, 0);
int y = CenterBounds(st->rect.top, st->rect.bottom, 0);
Point ret = this->RemapTile(x, y);
/* Same magic 3 as in DrawVehicles; that's where I got it from.

@ -614,8 +614,8 @@ CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
/* check new rect dimensions against preset max */
int w = new_rect.right - new_rect.left + 1;
int h = new_rect.bottom - new_rect.top + 1;
int w = new_rect.Width();
int h = new_rect.Height();
if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
dbg_assert(mode != ADD_TRY);
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);

@ -562,7 +562,7 @@ public:
int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 1 : 0;
GfxFillRect(r.left + cg_ofst + 1, r.top + cg_ofst + 1, r.right - 1 + cg_ofst, r.bottom - 1 + cg_ofst, cs->rating_colour);
TextColour tc = GetContrastColour(cs->rating_colour);
DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER);
DrawString(r.left + cg_ofst, r.right + cg_ofst, CenterBounds(r.top, r.bottom, FONT_HEIGHT_SMALL) + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER);
}
break;
}

@ -138,7 +138,7 @@ struct StatusBarWindow : Window {
void DrawWidget(const Rect &r, int widget) const override
{
int text_offset = std::max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
int text_offset = std::max(0, (r.Height() - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
int text_top = r.top + text_offset;
switch (widget) {
case WID_S_LEFT:
@ -190,7 +190,7 @@ struct StatusBarWindow : Window {
if (!this->reminder_timeout.HasElapsed()) {
Dimension icon_size = GetSpriteSize(SPR_UNREAD_NEWS);
DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, r.right - WD_FRAMERECT_RIGHT - icon_size.width, r.top + std::max(0, ((int)(r.bottom - r.top + 1) - (int)icon_size.height) / 2));
DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, r.right - WD_FRAMERECT_RIGHT - icon_size.width, CenterBounds(r.top, r.bottom, icon_size.height));
}
break;
}

@ -101,18 +101,18 @@ public:
this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
}
uint Width() const
uint Width() const override
{
return DropDownListStringItem::Width() + this->checkmark_width;
}
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void Draw(const Rect &r, bool sel, Colours bg_colour) const override
{
bool rtl = _current_text_dir == TD_RTL;
if (this->checked) {
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
}
DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : this->checkmark_width), right - WD_FRAMERECT_RIGHT - (rtl ? this->checkmark_width : 0), top, this->String(), sel ? TC_WHITE : TC_BLACK);
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : this->checkmark_width), r.right - WD_FRAMERECT_RIGHT - (rtl ? this->checkmark_width : 0), r.top, this->String(), sel ? TC_WHITE : TC_BLACK);
}
};
@ -149,7 +149,7 @@ public:
return std::max(std::max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
}
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override
void Draw(const Rect &r, bool sel, Colours bg_colour) const override
{
CompanyID company = (CompanyID)this->result;
bool rtl = _current_text_dir == TD_RTL;
@ -157,13 +157,13 @@ public:
/* It's possible the company is deleted while the dropdown is open */
if (!Company::IsValidID(company)) return;
int icon_offset = (bottom - top - icon_size.height) / 2;
int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
int lock_offset = (bottom - top - lock_size.height) / 2;
int icon_y = CenterBounds(r.top, r.bottom, icon_size.height);
int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL);
int lock_y = CenterBounds(r.top, r.bottom, lock_size.height);
DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
DrawCompanyIcon(company, rtl ? r.right - this->icon_size.width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT, icon_y);
if (NetworkCompanyIsPassworded(company)) {
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? r.left + WD_FRAMERECT_LEFT : r.right - this->lock_size.width - WD_FRAMERECT_RIGHT, lock_y);
}
SetDParam(0, company);
@ -174,7 +174,7 @@ public:
} else {
col = sel ? TC_WHITE : TC_BLACK;
}
DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 3 + this->lock_size.width : 3 + this->icon_size.width), right - WD_FRAMERECT_RIGHT - (rtl ? 3 + this->icon_size.width : 3 + this->lock_size.width), top + text_offset, STR_COMPANY_NAME_COMPANY_NUM, col);
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 3 + this->lock_size.width : 3 + this->icon_size.width), r.right - WD_FRAMERECT_RIGHT - (rtl ? 3 + this->icon_size.width : 3 + this->lock_size.width), text_y, STR_COMPANY_NAME_COMPANY_NUM, col);
}
};

@ -1387,20 +1387,20 @@ void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs,
VehicleSpriteSeq seq;
GetRailIcon(engine, false, y, image_type, &seq);
Rect16 rect = seq.GetBounds();
Rect rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
width = UnScaleGUI(rect.right - rect.left + 1);
height = UnScaleGUI(rect.bottom - rect.top + 1);
width = UnScaleGUI(rect.Width());
height = UnScaleGUI(rect.Height());
xoffs = UnScaleGUI(rect.left);
yoffs = UnScaleGUI(rect.top);
if (RailVehInfo(engine)->railveh_type == RAILVEH_MULTIHEAD) {
GetRailIcon(engine, true, y, image_type, &seq);
rect = seq.GetBounds();
rect = ConvertRect<Rect16, Rect>(seq.GetBounds());
/* Calculate values relative to an imaginary center between the two sprites. */
width = ScaleGUITrad(TRAININFO_DEFAULT_VEHICLE_WIDTH) + UnScaleGUI(rect.right) - xoffs;
height = std::max<uint>(height, UnScaleGUI(rect.bottom - rect.top + 1));
height = std::max<uint>(height, UnScaleGUI(rect.Height()));
xoffs = xoffs - ScaleGUITrad(TRAININFO_DEFAULT_VEHICLE_WIDTH) / 2;
yoffs = std::min(yoffs, UnScaleGUI(rect.top));
}

@ -156,7 +156,7 @@ public:
if (widget >= WID_BT_TYPE_BUTTON_FIRST) {
const int index = widget - WID_BT_TYPE_BUTTON_FIRST;
/* Trees "grow" in the centre on the bottom line of the buttons */
DrawSprite(_tree_sprites[index].sprite, _tree_sprites[index].pal, (r.left + r.right) / 2 + WD_FRAMERECT_LEFT, r.bottom - ScaleGUITrad(BUTTON_BOTTOM_OFFSET));
DrawSprite(_tree_sprites[index].sprite, _tree_sprites[index].pal, CenterBounds(r.left, r.right, 0) + WD_FRAMERECT_LEFT, r.bottom - ScaleGUITrad(BUTTON_BOTTOM_OFFSET));
}
}

@ -3167,7 +3167,7 @@ struct VehicleDetailsWindow : Window {
/* Draw service interval text */
SetDParam(0, v->GetServiceInterval());
SetDParam(1, v->date_of_last_service);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + (r.bottom - r.top + 1 - FONT_HEIGHT_NORMAL) / 2,
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL),
v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS);
break;
}
@ -3793,13 +3793,12 @@ public:
/* Draw the flag plus orders. */
bool rtl = (_current_text_dir == TD_RTL);
uint text_offset = std::max({GetSpriteSize(SPR_WARNING_SIGN).width, GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width}) + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
int height = r.bottom - r.top;
int text_left = r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : text_offset);
int text_right = r.right - (rtl ? text_offset : (uint)WD_FRAMERECT_RIGHT);
int text_top = r.top + WD_FRAMERECT_TOP + (height - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM - FONT_HEIGHT_NORMAL) / 2;
int text_top = CenterBounds(r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, FONT_HEIGHT_NORMAL);
int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
int image_left = (rtl ? text_right + 1 : r.left) + WD_IMGBTN_LEFT;
int image_top = r.top + WD_IMGBTN_TOP + (height - WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM - GetSpriteSize(image).height) / 2;
int image_top = CenterBounds(r.top + WD_IMGBTN_TOP, r.bottom - WD_IMGBTN_BOTTOM, GetSpriteSize(image).height);
int lowered = this->IsWidgetLowered(WID_VV_START_STOP) ? 1 : 0;
DrawSprite(image, PAL_NONE, image_left + lowered, image_top + lowered);
DrawString(text_left + lowered, text_right + lowered, text_top + lowered, str, text_colour, SA_HOR_CENTER);
@ -4164,8 +4163,8 @@ int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
bool rtl = _current_text_dir == TD_RTL;
VehicleSpriteSeq seq;
v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
Rect16 rec = seq.GetBounds();
return UnScaleGUI(rec.right - rec.left + 1);
Rect rec = ConvertRect<Rect16, Rect>(seq.GetBounds());
return UnScaleGUI(rec.Width());
}
}

@ -401,18 +401,18 @@ static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint1
int column_width; // Width of a single column in the matrix.
if (num_columns == 0) {
column_width = resize_x;
num_columns = (r.right - r.left + 1) / column_width;
num_columns = r.Width() / column_width;
} else {
column_width = (r.right - r.left + 1) / num_columns;
column_width = r.Width() / num_columns;
}
int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
int row_height; // Height of a single row in the matrix.
if (num_rows == 0) {
row_height = resize_y;
num_rows = (r.bottom - r.top + 1) / row_height;
num_rows = r.Height() / row_height;
} else {
row_height = (r.bottom - r.top + 1) / num_rows;
row_height = r.Height() / num_rows;
}
int col = _colour_gradient[colour & 0xF][6];
@ -690,11 +690,11 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_col
*/
static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
{
int text_offset = std::max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
int text_offset = std::max(0, (r.Height() - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
int dd_width = NWidgetLeaf::dropdown_dimension.width;
int dd_height = NWidgetLeaf::dropdown_dimension.height;
int image_offset = std::max(0, ((int)(r.bottom - r.top + 1) - dd_height) / 2);
int image_offset = std::max(0, (r.Height() - dd_height) / 2);
if (_current_text_dir == TD_LTR) {
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);

@ -20,14 +20,14 @@
#include "../safeguards.h"
void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void DropDownListItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
int c1 = _colour_gradient[bg_colour][3];
int c2 = _colour_gradient[bg_colour][7];
int mid = top + this->Height(0) / 2;
GfxFillRect(left + 1, mid - 2, right - 1, mid - 2, c1);
GfxFillRect(left + 1, mid - 1, right - 1, mid - 1, c2);
int mid = (r.top + r.bottom) / 2;
GfxFillRect(r.left + 1, mid - 2, r.right - 1, mid - 2, c1);
GfxFillRect(r.left + 1, mid - 1, r.right - 1, mid - 1, c2);
}
uint DropDownListStringItem::Width() const
@ -37,9 +37,9 @@ uint DropDownListStringItem::Width() const
return GetStringBoundingBox(buffer).width;
}
void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top, this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
}
/**
@ -85,11 +85,11 @@ uint DropDownListIconItem::Width() const
return DropDownListStringItem::Width() + this->dim.width + WD_FRAMERECT_LEFT;
}
void DropDownListIconItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void DropDownListIconItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
DrawSprite(this->sprite, this->pal, rtl ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, CenterBounds(top, bottom, this->sprite_y));
DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), CenterBounds(top, bottom, FONT_HEIGHT_NORMAL), this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
DrawSprite(this->sprite, this->pal, rtl ? r.right - this->dim.width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT, CenterBounds(r.top, r.bottom, this->sprite_y));
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), r.right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), (sel ? TC_WHITE : TC_BLACK) | this->colour_flags);
}
void DropDownListIconItem::SetDimension(Dimension d)
@ -219,9 +219,9 @@ struct DropdownWindow : Window {
{
if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_DM_ITEMS);
int y = _cursor.pos.y - this->top - nwi->pos_y - 2;
int width = nwi->current_x - 4;
const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect();
int y = _cursor.pos.y - this->top - r.top - 2;
int width = r.Width();
int pos = this->vscroll->GetPosition();
for (const auto &item : this->list) {
@ -251,7 +251,7 @@ struct DropdownWindow : Window {
int y = r.top + 2;
int pos = this->vscroll->GetPosition();
for (const auto &item : this->list) {
int item_height = item->Height(r.right - r.left + 1);
int item_height = item->Height(r.Width());
/* Skip items that are scrolled up */
if (--pos >= 0) continue;
@ -260,7 +260,7 @@ struct DropdownWindow : Window {
bool selected = (this->selected_index == item->result);
if (selected) GfxFillRect(r.left + 2, y, r.right - 1, y + item_height - 1, PC_BLACK);
item->Draw(r.left, r.right, y, y + item_height, selected, colour);
item->Draw({r.left, y, r.right, y + item_height - 1}, selected, colour);
if (item->masked) {
GfxFillRect(r.left + 1, y, r.right - 1, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
@ -386,7 +386,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
int top = w->top + wi_rect.bottom + 1;
/* The preferred width equals the calling widget */
uint width = wi_rect.right - wi_rect.left + 1;
uint width = wi_rect.Width();
/* Longest item in the list, if auto_width is enabled */
uint max_item_width = 0;

@ -37,7 +37,7 @@ public:
virtual bool Selectable() const { return false; }
virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
virtual uint Width() const { return 0; }
virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const;
virtual void Draw(const Rect &r, bool sel, Colours bg_colour) const;
};
/**
@ -52,7 +52,7 @@ public:
bool Selectable() const override { return true; }
uint Width() const override;
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
void Draw(const Rect &r, bool sel, Colours bg_colour) const override;
virtual StringID String() const { return this->string; }
void SetColourFlags(TextColour colour_flags) { this->colour_flags = colour_flags; }
@ -98,7 +98,7 @@ public:
uint Height(uint width) const override;
uint Width() const override;
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
void Draw(const Rect &r, bool sel, Colours bg_colour) const override;
void SetDimension(Dimension d);
};

@ -170,6 +170,12 @@ enum WidgetDrawDistances {
/* widget.cpp */
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
static inline void DrawFrameRect(const Rect &r, Colours colour, FrameFlags flags)
{
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags);
}
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align);
/* window.cpp */

Loading…
Cancel
Save