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

Similar code is already repeated in other locations.

(cherry picked from commit d8e06e590a)
This commit is contained in:
Peter Nelson
2021-05-04 00:24:14 +01:00
committed by Jonathan G Rennison
parent 065ae3964a
commit b414060f7c
5 changed files with 9 additions and 28 deletions

View File

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