1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-02-02 00:54:19 +01:00

Codechange: Use Rect WithX/WithY in some places.

This commit is contained in:
Peter Nelson
2025-09-21 20:35:58 +01:00
committed by Peter Nelson
parent 6d3f39609f
commit 31eec7106b
11 changed files with 29 additions and 27 deletions

View File

@@ -1030,7 +1030,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
if (has_variants) {
Rect fr = tr.WithWidth(circle_width, rtl);
DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, textr.top, fr.right, textr.bottom}, SA_CENTER);
DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, fr.WithY(textr), SA_CENTER);
}
tr = tr.Indent(circle_width + WidgetDimensions::scaled.hsep_normal, rtl);

View File

@@ -248,7 +248,7 @@ struct DropdownWindow : Window {
if (y < item_height) {
if (item->masked || !item->Selectable()) return false;
result = item->result;
click_result = item->OnClick({r.left, 0, r.right, item_height - 1}, {_cursor.pos.x - this->left, y});
click_result = item->OnClick(r.WithY(0, item_height - 1), {_cursor.pos.x - this->left, y});
return true;
}
@@ -274,7 +274,7 @@ struct DropdownWindow : Window {
if (--pos >= 0) continue;
if (y + item_height - 1 <= ir.bottom) {
Rect full{ir.left, y, ir.right, y + item_height - 1};
Rect full = ir.WithY(y, y + item_height - 1);
bool selected = (this->selected_result == item->result) && item->Selectable();
if (selected) GfxFillRect(full, PC_BLACK);

View File

@@ -41,8 +41,8 @@ public:
PixelColour c2 = GetColourGradient(bg_colour, SHADE_LIGHTEST);
int mid = CentreBounds(full.top, full.bottom, 0);
GfxFillRect(full.left, mid - WidgetDimensions::scaled.bevel.bottom, full.right, mid - 1, c1);
GfxFillRect(full.left, mid, full.right, mid + WidgetDimensions::scaled.bevel.top - 1, c2);
GfxFillRect(full.WithY(mid - WidgetDimensions::scaled.bevel.bottom, mid - 1), c1);
GfxFillRect(full.WithY(mid, mid + WidgetDimensions::scaled.bevel.top - 1), c2);
}
};

View File

@@ -209,7 +209,7 @@ public:
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
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 };
Rect middle_section = top_section.WithY(top_section.bottom, bottom_section.top);
DrawStringMultiLineWithClipping(top_section, this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(middle_section, this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(bottom_section, this->extra_msg.GetDecodedString(), TC_WHITE, SA_CENTER);

View File

@@ -527,9 +527,9 @@ public:
const FiosItem *item = *it;
if (item == this->selected) {
GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_DARK_BLUE);
GfxFillRect(br.WithY(tr), PC_DARK_BLUE);
} else if (item == this->highlighted) {
GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_VERY_DARK_BLUE);
GfxFillRect(br.WithY(tr), PC_VERY_DARK_BLUE);
}
DrawString(tr, item->title.GetDecodedString(), _fios_colours[item->type.detailed]);
tr = tr.Translate(0, this->resize.step_height);

View File

@@ -833,7 +833,7 @@ Rect QueryString::GetBoundingRect(const Window *w, WidgetID wid, size_t from, si
const auto p1 = GetCharPosInString(tb->GetText(), from, FS_NORMAL);
const auto p2 = from != to ? GetCharPosInString(tb->GetText(), to, FS_NORMAL) : p1;
return { Clamp(r.left + p1.left, r.left, r.right), r.top, Clamp(r.left + p2.right, r.left, r.right), r.bottom };
return r.WithX(Clamp(r.left + p1.left, r.left, r.right), Clamp(r.left + p2.right, r.left, r.right));
}
/**

View File

@@ -673,7 +673,7 @@ public:
case ContentInfo::State::DoesNotExist: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
default: NOT_REACHED();
}
DrawSpriteIgnorePadding(sprite, pal, {checkbox.left, mr.top, checkbox.right, mr.bottom}, SA_CENTER);
DrawSpriteIgnorePadding(sprite, pal, checkbox.WithY(mr), SA_CENTER);
StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS;
DrawString(type.left, type.right, mr.top + text_y_offset, str, TC_BLACK, SA_HOR_CENTER);

View File

@@ -401,7 +401,7 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t v
if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
int py = r.top - line_height * vscroll_pos + text_y_offset;
if (i > 0 || separate_sprite_row) {
if (vscroll_pos != 0) GfxFillRect(r.left, py - WidgetDimensions::scaled.matrix.top - 1, r.right, py - WidgetDimensions::scaled.matrix.top, GetColourGradient(COLOUR_GREY, SHADE_LIGHT));
if (vscroll_pos != 0) GfxFillRect(r.WithY(py - WidgetDimensions::scaled.matrix.top - 1, py - WidgetDimensions::scaled.matrix.top), GetColourGradient(COLOUR_GREY, SHADE_LIGHT));
}
switch (det_tab) {
case TDW_TAB_CARGO:

View File

@@ -62,7 +62,7 @@ public:
if (i == WID_TT_TEXT) continue; // Loading and cost/income text has no invisibility button.
const Rect wr = this->GetWidget<NWidgetBase>(i)->GetCurrentRect().Shrink(WidgetDimensions::scaled.fullbevel);
DrawFrameRect(wr.left, fr.top, wr.right, fr.bottom, COLOUR_PALE_GREEN,
DrawFrameRect(wr.WithY(fr), COLOUR_PALE_GREEN,
HasBit(_invisibility_opt, i - WID_TT_BEGIN) ? FrameFlag::Lowered : FrameFlags{});
}
break;

View File

@@ -1042,7 +1042,7 @@ struct RefitWindow : public Window {
switch (widget) {
case WID_VR_VEHICLE_PANEL_DISPLAY: {
Vehicle *v = Vehicle::Get(this->window_number);
DrawVehicleImage(v, {this->sprite_left, r.top, this->sprite_right, r.bottom},
DrawVehicleImage(v, r.WithX(this->sprite_left, this->sprite_right),
VehicleID::Invalid(), EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0);
/* Highlight selected vehicles. */
@@ -1791,7 +1791,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
DrawSprite(SPR_WARNING_SIGN, PAL_NONE, vehicle_button_x, ir.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + profit.height);
}
DrawVehicleImage(v, {image_left, ir.top, image_right, ir.bottom}, selected_vehicle, EIT_IN_LIST, 0);
DrawVehicleImage(v, ir.WithX(image_left, image_right), selected_vehicle, EIT_IN_LIST, 0);
if (_settings_client.gui.show_cargo_in_vehicle_lists) {
/* Get the cargoes the vehicle can carry */
@@ -1843,7 +1843,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
for (int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
if (image_left + WidgetDimensions::scaled.hsep_wide * i >= image_right) break; // Break if there is no more space to draw any more vehicles anyway.
DrawVehicleImage(vehgroup.vehicles_begin[i], {image_left + WidgetDimensions::scaled.hsep_wide * i, ir.top, image_right, ir.bottom}, selected_vehicle, EIT_IN_LIST, 0);
DrawVehicleImage(vehgroup.vehicles_begin[i], ir.WithX(image_left + WidgetDimensions::scaled.hsep_wide * i, image_right), selected_vehicle, EIT_IN_LIST, 0);
}
if (show_orderlist) DrawSmallOrderList(vehgroup.vehicles_begin[0]->orders, olr.left, olr.right, ir.top + GetCharacterHeight(FS_SMALL), this->order_arrow_width);

View File

@@ -510,8 +510,9 @@ static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_
PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST);
/* draw "shaded" background */
GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c1, FILLRECT_CHECKER);
Rect bg = r.Shrink(0, height);
GfxFillRect(bg, c2);
GfxFillRect(bg, c1, FILLRECT_CHECKER);
/* track positions. These fractions are based on original 1x dimensions, but scale better. */
int left = r.left + r.Width() * 3 / 11; /* left track is positioned 3/11ths from the left */
@@ -520,10 +521,10 @@ static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_
const uint8_t br = WidgetDimensions::scaled.bevel.right;
/* draw shaded lines */
GfxFillRect(left - bl, r.top + height, left - 1, r.bottom - height, c1);
GfxFillRect(left, r.top + height, left + br - 1, r.bottom - height, c2);
GfxFillRect(right - bl, r.top + height, right - 1, r.bottom - height, c1);
GfxFillRect(right, r.top + height, right + br - 1, r.bottom - height, c2);
GfxFillRect(bg.WithX(left - bl, left - 1), c1);
GfxFillRect(bg.WithX(left, left + br - 1), c2);
GfxFillRect(bg.WithX(right - bl, right - 1), c1);
GfxFillRect(bg.WithX(right, right + br - 1), c2);
auto [top, bottom] = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
DrawFrameRect(r.left, top, r.right, bottom, colour, bar_dragged ? FrameFlag::Lowered : FrameFlags{});
@@ -549,8 +550,9 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l
PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST);
/* draw "shaded" background */
GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c1, FILLRECT_CHECKER);
Rect bg = r.Shrink(width, 0);
GfxFillRect(bg, c2);
GfxFillRect(bg, c1, FILLRECT_CHECKER);
/* track positions. These fractions are based on original 1x dimensions, but scale better. */
int top = r.top + r.Height() * 3 / 11; /* top track is positioned 3/11ths from the top */
@@ -559,10 +561,10 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l
const uint8_t bb = WidgetDimensions::scaled.bevel.bottom;
/* draw shaded lines */
GfxFillRect(r.left + width, top - bt, r.right - width, top - 1, c1);
GfxFillRect(r.left + width, top, r.right - width, top + bb - 1, c2);
GfxFillRect(r.left + width, bottom - bt, r.right - width, bottom - 1, c1);
GfxFillRect(r.left + width, bottom, r.right - width, bottom + bb - 1, c2);
GfxFillRect(bg.WithY(top - bt, top - 1), c1);
GfxFillRect(bg.WithY(top, top + bb - 1), c2);
GfxFillRect(bg.WithY(bottom - bt, bottom - 1), c1);
GfxFillRect(bg.WithY(bottom, bottom + bb - 1), c2);
/* draw actual scrollbar */
auto [left, right] = HandleScrollbarHittest(scrollbar, r.left, r.right, true);