* Do not allow hiding of the rectangle with base coordinates \a nx and \a ny behind window \a v. * If needed, move the window base coordinates to keep it visible. * @param nx Base horizontal coordinate of the rectangle. * @param ny Base vertical coordinate of the rectangle. * @param rect Rectangle that must stay visible (horizontally, vertically, or both) * @param v Window lying in fro
| 2020 | * @param dir If no room horizontally, move the rectangle to the indicated position. |
| 2021 | */ |
| 2022 | static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, int px, PreventHideDirection dir) |
| 2023 | { |
| 2024 | if (v == nullptr) return; |
| 2025 | |
| 2026 | const int min_visible = rect.Height(); |
| 2027 | |
| 2028 | int v_bottom = v->top + v->height - 1; |
| 2029 | int v_right = v->left + v->width - 1; |
| 2030 | int safe_y = (dir == PHD_UP) ? (v->top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom); // Compute safe vertical position. |
| 2031 | |
| 2032 | if (*ny + rect.top <= v->top - min_visible) return; // Above v is enough space |
| 2033 | if (*ny + rect.bottom >= v_bottom + min_visible) return; // Below v is enough space |
| 2034 | |
| 2035 | /* Vertically, the rectangle is hidden behind v. */ |
| 2036 | if (*nx + rect.left + min_visible < v->left) { // At left of v. |
| 2037 | if (v->left < min_visible) *ny = safe_y; // But enough room, force it to a safe position. |
| 2038 | return; |
| 2039 | } |
| 2040 | if (*nx + rect.right - min_visible > v_right) { // At right of v. |
| 2041 | if (v_right > _screen.width - min_visible) *ny = safe_y; // Not enough room, force it to a safe position. |
| 2042 | return; |
| 2043 | } |
| 2044 | |
| 2045 | /* Horizontally also hidden, force movement to a safe area. */ |
| 2046 | if (px + rect.left < v->left && v->left >= min_visible) { // Coming from the left, and enough room there. |
| 2047 | *nx = v->left - min_visible - rect.left; |
| 2048 | } else if (px + rect.right > v_right && v_right <= _screen.width - min_visible) { // Coming from the right, and enough room there. |
| 2049 | *nx = v_right + min_visible - rect.right; |
| 2050 | } else { |
| 2051 | *ny = safe_y; |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * Make sure at least a part of the caption bar is still visible by moving |
no test coverage detected