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

Function ResizeWindow

src/window.cpp:2099–2132  ·  view source on GitHub ↗

* Resize the window. * Update all the widgets of a window based on their resize flags * Both the areas of the old window and the new sized window are set dirty * ensuring proper redrawing. * @param w Window to resize * @param delta_x Delta x-size of changed window (positive if larger, etc.) * @param delta_y Delta y-size of changed window * @param clamp_to_screen Whether to make sure t

Source from the content-addressed store, hash-verified

2097 * @param clamp_to_screen Whether to make sure the whole window stays visible
2098 */
2099void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
2100{
2101 if (delta_x != 0 || delta_y != 0) {
2102 if (clamp_to_screen) {
2103 /* Determine the new right/bottom position. If that is outside of the bounds of
2104 * the resolution clamp it in such a manner that it stays within the bounds. */
2105 int new_right = w->left + w->width + delta_x;
2106 int new_bottom = w->top + w->height + delta_y;
2107 if (new_right >= (int)_screen.width) delta_x -= Ceil(new_right - _screen.width, std::max(1U, w->nested_root->resize_x));
2108 if (new_bottom >= (int)_screen.height) delta_y -= Ceil(new_bottom - _screen.height, std::max(1U, w->nested_root->resize_y));
2109 }
2110
2111 w->SetDirty();
2112
2113 uint new_xinc = std::max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
2114 uint new_yinc = std::max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
2115 assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
2116 assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
2117
2118 w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, _current_text_dir == TD_RTL);
2119 w->width = w->nested_root->current_x;
2120 w->height = w->nested_root->current_y;
2121 }
2122
2123 EnsureVisibleCaption(w, w->left, w->top);
2124
2125 /* Schedule OnResize to make sure everything is initialised correctly if it needs to be. */
2126 if (schedule_resize) {
2127 w->ScheduleResize();
2128 } else {
2129 w->OnResize();
2130 }
2131 w->SetDirty();
2132}
2133
2134/**
2135 * Return the top of the main view available for general use.

Callers 14

IConsoleWindowMethod · 0.85
BootstrapBackgroundMethod · 0.85
DispatchLeftClickEventFunction · 0.85
ReInitMethod · 0.85
HandleWindowDraggingFunction · 0.85
RelocateAllWindowsFunction · 0.85
FramerateWindowMethod · 0.85
DrawRatingsMethod · 0.85
OnPaintMethod · 0.85
OnPaintMethod · 0.85

Calls 6

CeilFunction · 0.85
EnsureVisibleCaptionFunction · 0.85
ScheduleResizeMethod · 0.80
SetDirtyMethod · 0.45
AssignSizePositionMethod · 0.45
OnResizeMethod · 0.45

Tested by

no test coverage detected