summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2021-05-04 00:24:14 +0100
committerPeterN <peter@fuzzle.org>2021-05-08 09:53:55 +0100
commitd8e06e590aff56c837b29ddbba3764292ea08d85 (patch)
treebb50b42e03d5e61442ce98d63001426c7dadfa56
parent52b16237ad863ce30746ac7efc46a9ece7e3bdd2 (diff)
downloadopenttd-d8e06e590aff56c837b29ddbba3764292ea08d85.tar.xz
Codechange: Make GetCurrentRect() conform to usual Rect bounds, and reuse it.
Similar code is already repeated in other locations.
-rw-r--r--src/station_gui.cpp4
-rw-r--r--src/widget.cpp18
-rw-r--r--src/widget_type.h4
-rw-r--r--src/widgets/dropdown.cpp6
-rw-r--r--src/window.cpp5
5 files changed, 9 insertions, 28 deletions
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 98b44c6f9..cf3f455bc 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<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;
}
diff --git a/src/widget.cpp b/src/widget.cpp
index 93a5afe95..aaa00d4d7 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 c50a263d6..a5bd98849 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 4b89b4809..b6f7de3c1 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<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) {
diff --git a/src/window.cpp b/src/window.cpp
index d69a34144..3fcda7d42 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);