diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 07163886cb..ba7f238303 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1467,7 +1467,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. @@ -1495,7 +1495,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 06f14d969c..120591a1ec 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2016,11 +2016,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; @@ -2299,11 +2295,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; @@ -2685,11 +2677,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 aa78335c05..b7b94c1813 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -179,8 +179,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 d0f5753af8..c73e705abf 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -469,12 +469,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 76cfe1ca96..cd359492b1 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2121,10 +2121,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);