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

Method ReInit

src/window.cpp:980–1016  ·  view source on GitHub ↗

* Re-initialize a window, and optionally change its size. * @param rx Horizontal resize of the window. * @param ry Vertical resize of the window. * @param reposition If set, reposition the window to default location. * @note For just resizing the window, use #ResizeWindow instead. */

Source from the content-addressed store, hash-verified

978 * @note For just resizing the window, use #ResizeWindow instead.
979 */
980void Window::ReInit(int rx, int ry, bool reposition)
981{
982 this->SetDirty(); // Mark whole current window as dirty.
983
984 /* Save current size. */
985 int window_width = this->width * _gui_scale / this->scale;
986 int window_height = this->height * _gui_scale / this->scale;
987 this->scale = _gui_scale;
988
989 this->OnInit();
990 /* Re-initialize window smallest size. */
991 this->nested_root->SetupSmallestSize(this);
992 this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
993 this->width = this->nested_root->smallest_x;
994 this->height = this->nested_root->smallest_y;
995 this->resize.step_width = this->nested_root->resize_x;
996 this->resize.step_height = this->nested_root->resize_y;
997
998 /* Resize as close to the original size + requested resize as possible. */
999 window_width = std::max(window_width + rx, this->width);
1000 window_height = std::max(window_height + ry, this->height);
1001 int dx = (this->resize.step_width == 0) ? 0 : window_width - this->width;
1002 int dy = (this->resize.step_height == 0) ? 0 : window_height - this->height;
1003 /* dx and dy has to go by step.. calculate it.
1004 * The cast to int is necessary else dx/dy are implicitly cast to unsigned int, which won't work. */
1005 if (this->resize.step_width > 1) dx -= dx % (int)this->resize.step_width;
1006 if (this->resize.step_height > 1) dy -= dy % (int)this->resize.step_height;
1007
1008 if (reposition) {
1009 Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
1010 this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
1011 this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight(), false);
1012 }
1013
1014 ResizeWindow(this, dx, dy, true, false);
1015 /* ResizeWindow() does this->SetDirty() already, no need to do it again here. */
1016}
1017
1018/**
1019 * Set the shaded state of the window to \a make_shaded.

Callers 15

SetShadedMethod · 0.95
OnResizeMethod · 0.80
OnPaintMethod · 0.80
ToolbarSwitchClickFunction · 0.80
ReInitWindowFunction · 0.80
OnPaintMethod · 0.80
ResizeWindowAsNeededMethod · 0.80
UpdateButtonsMethod · 0.80
OnInvalidateDataMethod · 0.80
OnResizeMethod · 0.80
OnPaintMethod · 0.80
ModifyRailTypeMethod · 0.80

Calls 10

SetDirtyMethod · 0.95
OnInitMethod · 0.95
OnInitialPositionMethod · 0.95
ResizeWindowFunction · 0.85
GetDefaultWidthMethod · 0.80
GetDefaultHeightMethod · 0.80
SetupSmallestSizeMethod · 0.45
AssignSizePositionMethod · 0.45

Tested by

no test coverage detected