mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-07 23:10:04 +00:00
Codechange: Make use of Rect Width/Height helpers.
This commit is contained in:
parent
632464a623
commit
f5f035a22b
@ -252,8 +252,8 @@ void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoff
|
||||
Rect rect;
|
||||
seq.GetBounds(&rect);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID s
|
||||
Rect rect;
|
||||
seq.GetBounds(&rect);
|
||||
|
||||
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;
|
||||
@ -108,6 +108,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);
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,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));
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ 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);
|
||||
int y = r.top + GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, r.Width());
|
||||
y = DrawStringMultiLine(r.left, r.right, r.top, y, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_CENTER) + WD_PAR_VSEP_WIDE;
|
||||
|
||||
SetDParam(0, engine);
|
||||
|
@ -285,7 +285,7 @@ public:
|
||||
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);
|
||||
} else {
|
||||
int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2;
|
||||
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;
|
||||
|
@ -2921,8 +2921,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;
|
||||
|
@ -428,7 +428,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;
|
||||
@ -878,8 +878,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;
|
||||
|
||||
|
@ -354,7 +354,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) {
|
||||
@ -381,7 +381,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) {
|
||||
|
@ -1254,7 +1254,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;
|
||||
@ -1268,7 +1268,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;
|
||||
@ -1305,7 +1305,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;
|
||||
|
@ -175,8 +175,8 @@ void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs
|
||||
Rect rect;
|
||||
seq.GetBounds(&rect);
|
||||
|
||||
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;
|
||||
|
@ -119,8 +119,8 @@ void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, i
|
||||
Rect rect;
|
||||
seq.GetBounds(&rect);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selec
|
||||
Rect rect;
|
||||
seq.GetBounds(&rect);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1215,13 +1215,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;
|
||||
|
@ -549,8 +549,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)) {
|
||||
assert(mode != ADD_TRY);
|
||||
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
|
||||
|
@ -137,7 +137,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:
|
||||
|
@ -566,8 +566,8 @@ void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs,
|
||||
Rect rect;
|
||||
seq.GetBounds(&rect);
|
||||
|
||||
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);
|
||||
|
||||
@ -577,7 +577,7 @@ void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs,
|
||||
|
||||
/* 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));
|
||||
}
|
||||
|
@ -3316,7 +3316,7 @@ int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
|
||||
v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
|
||||
Rect rec;
|
||||
seq.GetBounds(&rec);
|
||||
return UnScaleGUI(rec.right - rec.left + 1);
|
||||
return UnScaleGUI(rec.Width());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,18 +322,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];
|
||||
@ -611,11 +611,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);
|
||||
|
Loading…
Reference in New Issue
Block a user