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

Function PositionWindow

src/window.cpp:3445–3461  ·  view source on GitHub ↗

* (Re)position a window at the screen. * @param w Window structure of the window, may also be \c nullptr. * @param clss The class of the window to position. * @param setting The actual setting used for the window's position. * @return X coordinate of left edge of the repositioned window. */

Source from the content-addressed store, hash-verified

3443 * @return X coordinate of left edge of the repositioned window.
3444 */
3445static int PositionWindow(Window *w, WindowClass clss, int setting)
3446{
3447 if (w == nullptr || w->window_class != clss) {
3448 w = FindWindowById(clss, 0);
3449 }
3450 if (w == nullptr) return 0;
3451
3452 int old_left = w->left;
3453 switch (setting) {
3454 case 1: w->left = (_screen.width - w->width) / 2; break;
3455 case 2: w->left = _screen.width - w->width; break;
3456 default: w->left = 0; break;
3457 }
3458 if (w->viewport != nullptr) w->viewport->left += w->left - old_left;
3459 AddDirtyBlock(0, w->top, _screen.width, w->top + w->height); // invalidate the whole row
3460 return w->left;
3461}
3462
3463/**
3464 * (Re)position main toolbar window at the screen.

Callers 4

PositionMainToolbarFunction · 0.85
PositionStatusbarFunction · 0.85
PositionNewsMessageFunction · 0.85

Calls 2

FindWindowByIdFunction · 0.85
AddDirtyBlockFunction · 0.85

Tested by

no test coverage detected