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

Function RelocateAllWindows

src/window.cpp:3529–3596  ·  view source on GitHub ↗

* Relocate all windows to fit the new size of the game application screen * @param neww New width of the game application screen * @param newh New height of the game application screen. */

Source from the content-addressed store, hash-verified

3527 * @param newh New height of the game application screen.
3528 */
3529void RelocateAllWindows(int neww, int newh)
3530{
3531 CloseWindowByClass(WC_DROPDOWN_MENU);
3532
3533 /* Reposition toolbar then status bar before other all windows. */
3534 if (Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); wt != nullptr) {
3535 ResizeWindow(wt, std::min<uint>(neww, _toolbar_width) - wt->width, 0, false);
3536 wt->left = PositionMainToolbar(wt);
3537 }
3538
3539 if (Window *ws = FindWindowById(WC_STATUS_BAR, 0); ws != nullptr) {
3540 ResizeWindow(ws, std::min<uint>(neww, _toolbar_width) - ws->width, 0, false);
3541 ws->top = newh - ws->height;
3542 ws->left = PositionStatusbar(ws);
3543 }
3544
3545 for (Window *w : Window::Iterate()) {
3546 int left, top;
3547 /* XXX - this probably needs something more sane. For example specifying
3548 * in a 'backup'-desc that the window should always be centered. */
3549 switch (w->window_class) {
3550 case WC_MAIN_WINDOW:
3551 case WC_BOOTSTRAP:
3552 case WC_HIGHSCORE:
3553 case WC_ENDSCREEN:
3554 ResizeWindow(w, neww, newh);
3555 continue;
3556
3557 case WC_MAIN_TOOLBAR:
3558 case WC_STATUS_BAR:
3559 continue;
3560
3561 case WC_NEWS_WINDOW:
3562 top = newh - w->height;
3563 left = PositionNewsMessage(w);
3564 break;
3565
3566 case WC_SEND_NETWORK_MSG:
3567 ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
3568
3569 top = newh - w->height - FindWindowById(WC_STATUS_BAR, 0)->height;
3570 left = PositionNetworkChatWindow(w);
3571 break;
3572
3573 case WC_CONSOLE:
3574 IConsoleResize(w);
3575 continue;
3576
3577 default: {
3578 if (w->flags.Test(WindowFlag::Centred)) {
3579 top = (newh - w->height) >> 1;
3580 left = (neww - w->width) >> 1;
3581 break;
3582 }
3583
3584 left = w->left;
3585 if (left + (w->width >> 1) >= neww) left = neww - w->width;
3586 if (left < 0) left = 0;

Callers 2

ReInitAllWindowsFunction · 0.85
GameSizeChangedFunction · 0.85

Calls 10

CloseWindowByClassFunction · 0.85
FindWindowByIdFunction · 0.85
ResizeWindowFunction · 0.85
PositionMainToolbarFunction · 0.85
PositionStatusbarFunction · 0.85
PositionNewsMessageFunction · 0.85
IConsoleResizeFunction · 0.85
EnsureVisibleCaptionFunction · 0.85
TestMethod · 0.80

Tested by

no test coverage detected