* Resize window towards the default size. * Prior to construction, a position for the new window (for its default size) * has been found with LocalGetWindowPlacement(). Initially, the window is * constructed with minimal size. Resizing the window to its default size is * done here. * @param def_width default width in pixels of the window * @param def_height default height in pixels of the wi
| 1474 | * @see Window::Window(), Window::InitializeData(), Window::InitializePositionSize() |
| 1475 | */ |
| 1476 | void Window::FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) |
| 1477 | { |
| 1478 | if (allow_resize) { |
| 1479 | def_width = std::max(def_width, this->width); // Don't allow default size to be smaller than smallest size |
| 1480 | def_height = std::max(def_height, this->height); |
| 1481 | /* Try to make windows smaller when our window is too small. |
| 1482 | * w->(width|height) is normally the same as min_(width|height), |
| 1483 | * but this way the GUIs can be made a little more dynamic; |
| 1484 | * one can use the same spec for multiple windows and those |
| 1485 | * can then determine the real minimum size of the window. */ |
| 1486 | if (this->width != def_width || this->height != def_height) { |
| 1487 | /* Think about the overlapping toolbars when determining the minimum window size */ |
| 1488 | int free_height = _screen.height; |
| 1489 | const Window *wt = FindWindowById(WC_STATUS_BAR, 0); |
| 1490 | if (wt != nullptr) free_height -= wt->height; |
| 1491 | wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
| 1492 | if (wt != nullptr) free_height -= wt->height; |
| 1493 | |
| 1494 | int enlarge_x = std::max(std::min(def_width - this->width, _screen.width - this->width), 0); |
| 1495 | int enlarge_y = std::max(std::min(def_height - this->height, free_height - this->height), 0); |
| 1496 | |
| 1497 | /* X and Y has to go by step.. calculate it. |
| 1498 | * The cast to int is necessary else x/y are implicitly cast to |
| 1499 | * unsigned int, which won't work. */ |
| 1500 | if (this->resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width; |
| 1501 | if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height; |
| 1502 | |
| 1503 | ResizeWindow(this, enlarge_x, enlarge_y, true, false); |
| 1504 | /* ResizeWindow() calls this->OnResize(). */ |
| 1505 | } else { |
| 1506 | /* Always call OnResize; that way the scrollbars and matrices get initialized. */ |
| 1507 | this->OnResize(); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | int nx = this->left; |
| 1512 | int ny = this->top; |
| 1513 | |
| 1514 | if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width); |
| 1515 | |
| 1516 | const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
| 1517 | ny = std::max(ny, (wt == nullptr || this == wt || this->top == 0) ? 0 : wt->height); |
| 1518 | nx = std::max(nx, 0); |
| 1519 | |
| 1520 | if (this->viewport != nullptr) { |
| 1521 | this->viewport->left += nx - this->left; |
| 1522 | this->viewport->top += ny - this->top; |
| 1523 | } |
| 1524 | this->left = nx; |
| 1525 | this->top = ny; |
| 1526 | |
| 1527 | this->SetDirty(); |
| 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * Decide whether a given rectangle is a good place to open a completely visible new window. |
no test coverage detected