* Compute the position of the top-left corner of a new window that is opened. * * By default position a child window at an offset of 10/10 of its parent. * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports) * and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/toolbar-height of * its parent. So it's exactly under the parent toolbar and no bu
| 1726 | * @return Coordinate of the top-left corner of the new window. |
| 1727 | */ |
| 1728 | static Point LocalGetWindowPlacement(const WindowDesc &desc, int16_t sm_width, int16_t sm_height, int window_number) |
| 1729 | { |
| 1730 | Point pt; |
| 1731 | const Window *w; |
| 1732 | |
| 1733 | int16_t default_width = std::max(desc.GetDefaultWidth(), sm_width); |
| 1734 | int16_t default_height = std::max(desc.GetDefaultHeight(), sm_height); |
| 1735 | |
| 1736 | if (desc.parent_cls != WC_NONE && (w = FindWindowById(desc.parent_cls, window_number)) != nullptr) { |
| 1737 | bool rtl = _current_text_dir == TD_RTL; |
| 1738 | if (desc.parent_cls == WC_BUILD_TOOLBAR || desc.parent_cls == WC_SCEN_LAND_GEN) { |
| 1739 | pt.x = w->left + (rtl ? w->width - default_width : 0); |
| 1740 | pt.y = w->top + w->height; |
| 1741 | return pt; |
| 1742 | } else { |
| 1743 | /* Position child window with offset of closebox, but make sure that either closebox or resizebox is visible |
| 1744 | * - Y position: closebox of parent + closebox of child + statusbar |
| 1745 | * - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl) |
| 1746 | */ |
| 1747 | int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.captiontext.Vertical()); |
| 1748 | if (w->top + 3 * indent_y < _screen.height) { |
| 1749 | pt.y = w->top + indent_y; |
| 1750 | int indent_close = NWidgetLeaf::closebox_dimension.width; |
| 1751 | int indent_resize = NWidgetLeaf::resizebox_dimension.width; |
| 1752 | if (_current_text_dir == TD_RTL) { |
| 1753 | pt.x = std::max(w->left + w->width - default_width - indent_close, 0); |
| 1754 | if (pt.x + default_width >= indent_close && pt.x + indent_resize <= _screen.width) return pt; |
| 1755 | } else { |
| 1756 | pt.x = std::min(w->left + indent_close, _screen.width - default_width); |
| 1757 | if (pt.x + default_width >= indent_resize && pt.x + indent_close <= _screen.width) return pt; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | switch (desc.default_pos) { |
| 1764 | case WDP_ALIGN_TOOLBAR: // Align to the toolbar |
| 1765 | return GetToolbarAlignedWindowPosition(default_width); |
| 1766 | |
| 1767 | case WDP_AUTO: // Find a good automatic position for the window |
| 1768 | return GetAutoPlacePosition(default_width, default_height); |
| 1769 | |
| 1770 | case WDP_CENTER: // Centre the window horizontally |
| 1771 | pt.x = (_screen.width - default_width) / 2; |
| 1772 | pt.y = (_screen.height - default_height) / 2; |
| 1773 | break; |
| 1774 | |
| 1775 | case WDP_MANUAL: |
| 1776 | pt.x = 0; |
| 1777 | pt.y = 0; |
| 1778 | break; |
| 1779 | |
| 1780 | default: |
| 1781 | NOT_REACHED(); |
| 1782 | } |
| 1783 | |
| 1784 | return pt; |
| 1785 | } |
no test coverage detected