Codechange: Make GetCurrentRect() conform to usual Rect bounds, and reuse it.

Similar code is already repeated in other locations.
pull/332/head
Peter Nelson 3 years ago committed by PeterN
parent 52b16237ad
commit d8e06e590a

@ -1440,7 +1440,7 @@ struct StationViewWindow : public Window {
if (!this->IsShaded()) {
/* Draw 'accepted cargo' or 'cargo ratings'. */
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(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<NWidgetCore>(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<NWidgetBase>(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;
}

@ -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) {

@ -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;
}

@ -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<NWidgetCore>(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) {

@ -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);

Loading…
Cancel
Save