diff --git a/src/window.cpp b/src/window.cpp index f7092741e6..2ae61648ee 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1996,28 +1996,30 @@ static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, i { if (v == nullptr) return; + const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR); + int v_bottom = v->top + v->height; int v_right = v->left + v->width; - int safe_y = (dir == PHD_UP) ? (v->top - MIN_VISIBLE_TITLE_BAR - rect.top) : (v_bottom + MIN_VISIBLE_TITLE_BAR - rect.bottom); // Compute safe vertical position. + int safe_y = (dir == PHD_UP) ? (v->top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom); // Compute safe vertical position. - if (*ny + rect.top <= v->top - MIN_VISIBLE_TITLE_BAR) return; // Above v is enough space - if (*ny + rect.bottom >= v_bottom + MIN_VISIBLE_TITLE_BAR) return; // Below v is enough space + if (*ny + rect.top <= v->top - min_visible) return; // Above v is enough space + if (*ny + rect.bottom >= v_bottom + min_visible) return; // Below v is enough space /* Vertically, the rectangle is hidden behind v. */ - if (*nx + rect.left + MIN_VISIBLE_TITLE_BAR < v->left) { // At left of v. - if (v->left < MIN_VISIBLE_TITLE_BAR) *ny = safe_y; // But enough room, force it to a safe position. + if (*nx + rect.left + min_visible < v->left) { // At left of v. + if (v->left < min_visible) *ny = safe_y; // But enough room, force it to a safe position. return; } - if (*nx + rect.right - MIN_VISIBLE_TITLE_BAR > v_right) { // At right of v. - if (v_right > _screen.width - MIN_VISIBLE_TITLE_BAR) *ny = safe_y; // Not enough room, force it to a safe position. + if (*nx + rect.right - min_visible > v_right) { // At right of v. + if (v_right > _screen.width - min_visible) *ny = safe_y; // Not enough room, force it to a safe position. return; } /* Horizontally also hidden, force movement to a safe area. */ - if (px + rect.left < v->left && v->left >= MIN_VISIBLE_TITLE_BAR) { // Coming from the left, and enough room there. - *nx = v->left - MIN_VISIBLE_TITLE_BAR - rect.left; - } else if (px + rect.right > v_right && v_right <= _screen.width - MIN_VISIBLE_TITLE_BAR) { // Coming from the right, and enough room there. - *nx = v_right + MIN_VISIBLE_TITLE_BAR - rect.right; + if (px + rect.left < v->left && v->left >= min_visible) { // Coming from the left, and enough room there. + *nx = v->left - min_visible - rect.left; + } else if (px + rect.right > v_right && v_right <= _screen.width - min_visible) { // Coming from the right, and enough room there. + *nx = v_right + min_visible - rect.right; } else { *ny = safe_y; } @@ -2038,9 +2040,11 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny) if (caption != nullptr) { caption_rect = caption->GetCurrentRect(); + const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR); + /* 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); - ny = Clamp(ny, 0, _screen.height - MIN_VISIBLE_TITLE_BAR); + nx = Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left); + ny = Clamp(ny, 0, _screen.height - min_visible); /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */ PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);