MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / EnsureVisibleCaption

Function EnsureVisibleCaption

src/window.cpp:2062–2087  ·  view source on GitHub ↗

* Make sure at least a part of the caption bar is still visible by moving * the window if necessary. * @param w The window to check. * @param nx The proposed new x-location of the window. * @param ny The proposed new y-location of the window. */

Source from the content-addressed store, hash-verified

2060 * @param ny The proposed new y-location of the window.
2061 */
2062static void EnsureVisibleCaption(Window *w, int nx, int ny)
2063{
2064 /* Search for the title bar rectangle. */
2065 const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION);
2066 if (caption != nullptr) {
2067 const Rect caption_rect = caption->GetCurrentRect();
2068
2069 const int min_visible = caption_rect.Height();
2070
2071 /* Make sure the window doesn't leave the screen */
2072 nx = Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left);
2073 ny = Clamp(ny, 0, _screen.height - min_visible);
2074
2075 /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */
2076 PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);
2077 PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP);
2078 }
2079
2080 if (w->viewport != nullptr) {
2081 w->viewport->left += nx - w->left;
2082 w->viewport->top += ny - w->top;
2083 }
2084
2085 w->left = nx;
2086 w->top = ny;
2087}
2088
2089/**
2090 * Resize the window.

Callers 3

ResizeWindowFunction · 0.85
HandleWindowDraggingFunction · 0.85
RelocateAllWindowsFunction · 0.85

Calls 6

ClampFunction · 0.85
PreventHidingFunction · 0.85
FindWindowByIdFunction · 0.85
GetWidgetOfTypeMethod · 0.80
GetCurrentRectMethod · 0.80
HeightMethod · 0.45

Tested by

no test coverage detected