diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 98b44c6f98..cf3f455bc9 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1440,7 +1440,7 @@ struct StationViewWindow : public Window { if (!this->IsShaded()) { /* Draw 'accepted cargo' or 'cargo ratings'. */ const NWidgetBase *wid = this->GetWidget(WID_SV_ACCEPT_RATING_LIST); - const Rect r = {(int)wid->pos_x, (int)wid->pos_y, (int)(wid->pos_x + wid->current_x - 1), (int)(wid->pos_y + wid->current_y - 1)}; + const Rect r = wid->GetCurrentRect(); if (this->GetWidget(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) { int lines = this->DrawAcceptedCargo(r); if (lines > this->accepts_lines) { // Resize the widget, and perform re-initialization of the window. @@ -1468,7 +1468,7 @@ struct StationViewWindow : public Window { /* Draw waiting cargo. */ NWidgetBase *nwi = this->GetWidget(WID_SV_WAITING); - Rect waiting_rect = { (int)nwi->pos_x, (int)nwi->pos_y, (int)(nwi->pos_x + nwi->current_x - 1), (int)(nwi->pos_y + nwi->current_y - 1)}; + Rect waiting_rect = nwi->GetCurrentRect(); this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0); scroll_to_row = INT_MAX; } diff --git a/src/widget.cpp b/src/widget.cpp index 93a5afe953..aaa00d4d79 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1964,11 +1964,7 @@ void NWidgetBackground::Draw(const Window *w) { if (this->current_x == 0 || this->current_y == 0) return; - Rect r; - r.left = this->pos_x; - r.right = this->pos_x + this->current_x - 1; - r.top = this->pos_y; - r.bottom = this->pos_y + this->current_y - 1; + Rect r = this->GetCurrentRect(); const DrawPixelInfo *dpi = _cur_dpi; if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return; @@ -2232,11 +2228,7 @@ void NWidgetScrollbar::Draw(const Window *w) { if (this->current_x == 0 || this->current_y == 0) return; - Rect r; - r.left = this->pos_x; - r.right = this->pos_x + this->current_x - 1; - r.top = this->pos_y; - r.bottom = this->pos_y + this->current_y - 1; + Rect r = this->GetCurrentRect(); const DrawPixelInfo *dpi = _cur_dpi; if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return; @@ -2615,11 +2607,7 @@ void NWidgetLeaf::Draw(const Window *w) DrawPixelInfo *old_dpi = _cur_dpi; _cur_dpi = &new_dpi; - Rect r; - r.left = this->pos_x; - r.right = this->pos_x + this->current_x - 1; - r.top = this->pos_y; - r.bottom = this->pos_y + this->current_y - 1; + Rect r = this->GetCurrentRect(); bool clicked = this->IsLowered(); switch (this->type) { diff --git a/src/widget_type.h b/src/widget_type.h index c50a263d68..a5bd988492 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -167,8 +167,8 @@ public: Rect r; r.left = this->pos_x; r.top = this->pos_y; - r.right = this->pos_x + this->current_x; - r.bottom = this->pos_y + this->current_y; + r.right = this->pos_x + this->current_x - 1; + r.bottom = this->pos_y + this->current_y - 1; return r; } diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 4b89b48092..b6f7de3c18 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -448,12 +448,8 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, { /* Our parent's button widget is used to determine where to place the drop * down list window. */ - Rect wi_rect; NWidgetCore *nwi = w->GetWidget(button); - wi_rect.left = nwi->pos_x; - wi_rect.right = nwi->pos_x + nwi->current_x - 1; - wi_rect.top = nwi->pos_y; - wi_rect.bottom = nwi->pos_y + nwi->current_y - 1; + Rect wi_rect = nwi->GetCurrentRect(); Colours wi_colour = nwi->colour; if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) { diff --git a/src/window.cpp b/src/window.cpp index d69a34144e..3fcda7d42d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2097,10 +2097,7 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny) Rect caption_rect; const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION); if (caption != nullptr) { - caption_rect.left = caption->pos_x; - caption_rect.right = caption->pos_x + caption->current_x; - caption_rect.top = caption->pos_y; - caption_rect.bottom = caption->pos_y + caption->current_y; + caption_rect = caption->GetCurrentRect(); /* Make sure the window doesn't leave the screen */ nx = Clamp(nx, MIN_VISIBLE_TITLE_BAR - caption_rect.right, _screen.width - MIN_VISIBLE_TITLE_BAR - caption_rect.left);