Merge branch upstream/master

This commit is contained in:
Sergii Pylypenko
2021-11-28 03:16:36 +02:00
326 changed files with 9186 additions and 8099 deletions

View File

@@ -949,8 +949,7 @@ static bool MayBeShown(const Window *w)
*/
static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
{
const Window *v;
FOR_ALL_WINDOWS_FROM_BACK_FROM(v, w->z_front) {
for (const Window *v : Window::IterateFromBack(w->z_front)) {
if (MayBeShown(v) &&
right > v->left &&
bottom > v->top &&
@@ -1009,13 +1008,11 @@ static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bo
*/
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
{
Window *w;
DrawPixelInfo *old_dpi = _cur_dpi;
DrawPixelInfo bk;
_cur_dpi = &bk;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (MayBeShown(w) &&
right > w->left &&
bottom > w->top &&
@@ -1108,8 +1105,7 @@ void Window::SetShaded(bool make_shaded)
*/
static Window *FindChildWindow(const Window *w, WindowClass wc)
{
Window *v;
FOR_ALL_WINDOWS_FROM_BACK(v) {
for (Window *v : Window::IterateFromBack()) {
if ((wc == WC_INVALID || wc == v->window_class) && v->parent == w) return v;
}
@@ -1183,8 +1179,7 @@ Window::~Window()
*/
Window *FindWindowById(WindowClass cls, WindowNumber number)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls && w->window_number == number) return w;
}
@@ -1199,8 +1194,7 @@ Window *FindWindowById(WindowClass cls, WindowNumber number)
*/
Window *FindWindowByClass(WindowClass cls)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls) return w;
}
@@ -1216,8 +1210,7 @@ Window *FindWindowByClass(WindowClass cls)
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
{
Window *w = FindWindowById(cls, number);
if (force || w == nullptr ||
(w->flags & WF_STICKY) == 0) {
if (w != nullptr && (force || (w->flags & WF_STICKY) == 0)) {
delete w;
}
}
@@ -1228,13 +1221,11 @@ void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
*/
void DeleteWindowByClass(WindowClass cls)
{
Window *w;
restart_search:
/* When we find the window to delete, we need to restart the search
* as deleting this window could cascade in deleting (many) others
* anywhere in the z-array */
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls) {
delete w;
goto restart_search;
@@ -1250,13 +1241,11 @@ restart_search:
*/
void DeleteCompanyWindows(CompanyID id)
{
Window *w;
restart_search:
/* When we find the window to delete, we need to restart the search
* as deleting this window could cascade in deleting (many) others
* anywhere in the z-array */
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->owner == id) {
delete w;
goto restart_search;
@@ -1276,8 +1265,7 @@ restart_search:
*/
void ChangeWindowOwner(Owner old_owner, Owner new_owner)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->owner != old_owner) continue;
switch (w->window_class) {
@@ -1674,8 +1662,7 @@ static bool IsGoodAutoPlace1(int left, int top, int width, int height, int toolb
}
/* Make sure it is not obscured by any window. */
const Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_MAIN_WINDOW) continue;
if (right > w->left &&
@@ -1720,8 +1707,7 @@ static bool IsGoodAutoPlace2(int left, int top, int width, int height, int toolb
if (top < toolbar_y || top > _screen.height - (height >> 2)) return false;
/* Make sure it is not obscured by any window. */
const Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_MAIN_WINDOW) continue;
if (left + width > w->left &&
@@ -1763,8 +1749,7 @@ static Point GetAutoPlacePosition(int width, int height)
* The new window must be entirely on-screen, and not overlap with an existing window.
* Eight starting points are tried, two at each corner.
*/
const Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_MAIN_WINDOW) continue;
if (IsGoodAutoPlace1(w->left + w->width, w->top, width, height, toolbar_y, pt)) return pt;
@@ -1781,7 +1766,7 @@ static Point GetAutoPlacePosition(int width, int height)
* The new window may be partly off-screen, and must not overlap with an existing window.
* Only four starting points are tried.
*/
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_MAIN_WINDOW) continue;
if (IsGoodAutoPlace2(w->left + w->width, w->top, width, height, toolbar_y, pt)) return pt;
@@ -1802,7 +1787,7 @@ static Point GetAutoPlacePosition(int width, int height)
int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
restart:
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->left == left && w->top == top) {
left += offset_x;
top += offset_y;
@@ -1983,8 +1968,7 @@ Window::Window(WindowDesc *desc) : window_desc(desc), mouse_capture_widget(-1)
*/
Window *FindWindowFromPt(int x, int y)
{
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
if (MayBeShown(w) && IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
return w;
}
@@ -2036,10 +2020,9 @@ void UnInitWindowSystem()
{
UnshowCriticalError();
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) delete w;
for (Window *w : Window::IterateFromFront()) delete w;
for (w = _z_front_window; w != nullptr; /* nothing */) {
for (Window *w = _z_front_window; w != nullptr; /* nothing */) {
Window *to_del = w;
w = w->z_back;
free(to_del);
@@ -2066,8 +2049,7 @@ static void DecreaseWindowCounters()
if (_scroller_click_timeout != 0) _scroller_click_timeout--;
if (hundredth_tick_timeout != 0) hundredth_tick_timeout--;
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
if (!_network_dedicated && hundredth_tick_timeout == 0) w->OnHundredthTick();
if (_scroller_click_timeout == 0) {
@@ -2093,7 +2075,7 @@ static void DecreaseWindowCounters()
w->OnMouseLoop();
}
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
if ((w->flags & WF_TIMEOUT) && --w->timeout_timer == 0) {
CLRBITS(w->flags, WF_TIMEOUT);
@@ -2421,8 +2403,7 @@ static EventState HandleWindowDragging()
if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
/* Otherwise find the window... */
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->flags & WF_DRAGGING) {
/* Stop the dragging if the left mouse button was released */
if (!_left_button_down) {
@@ -2441,13 +2422,11 @@ static EventState HandleWindowDragging()
int ny = y;
if (_settings_client.gui.window_snap_radius != 0) {
const Window *v;
int hsnap = _settings_client.gui.window_snap_radius;
int vsnap = _settings_client.gui.window_snap_radius;
int delta;
FOR_ALL_WINDOWS_FROM_BACK(v) {
for (const Window *v : Window::IterateFromBack()) {
if (v == w) continue; // Don't snap at yourself
if (y + w->height > v->top && y < v->top + v->height) {
@@ -2670,8 +2649,7 @@ static void HandleScrollbarScrolling(Window *w)
*/
static EventState HandleActiveWidget()
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->mouse_capture_widget >= 0) {
/* Abort if no button is clicked any more. */
if (!_left_button_down) {
@@ -2797,8 +2775,7 @@ static bool MaybeBringWindowToFront(Window *w)
w_height = w->unshaded_size.height;
}
Window *u;
FOR_ALL_WINDOWS_FROM_BACK_FROM(u, w->z_front) {
for (Window *u : Window::IterateFromBack(w->z_front)) {
/* A modal child will prevent the activation of the parent window */
if (u->parent == w && (u->window_desc->flags & WDF_MODAL)) {
u->SetWhiteBorder();
@@ -2940,8 +2917,7 @@ void HandleKeypress(uint keycode, WChar key)
}
/* Call the event, start with the uppermost window, but ignore the toolbar. */
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
if (w->window_class == WC_MAIN_TOOLBAR) continue;
if (w->window_desc->hotkeys != nullptr) {
int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
@@ -2950,7 +2926,7 @@ void HandleKeypress(uint keycode, WChar key)
if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
}
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
/* When there is no toolbar w is null, check for that */
if (w != nullptr) {
if (w->window_desc->hotkeys != nullptr) {
@@ -2969,8 +2945,7 @@ void HandleKeypress(uint keycode, WChar key)
void HandleCtrlChanged()
{
/* Call the event, start with the uppermost window. */
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
if (w->OnCTRLStateChange() == ES_HANDLED) return;
}
}
@@ -3370,8 +3345,8 @@ static void CheckSoftLimit()
for (;;) {
uint deletable_count = 0;
Window *w, *last_deletable = nullptr;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
Window *last_deletable = nullptr;
for (Window *w : Window::IterateFromFront()) {
if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || (w->flags & WF_STICKY)) continue;
last_deletable = w;
@@ -3426,8 +3401,7 @@ void InputLoop()
*/
void CallWindowRealtimeTickEvent(uint delta_ms)
{
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
w->OnRealtimeTick(delta_ms);
}
}
@@ -3455,10 +3429,8 @@ void UpdateWindows()
NetworkChatMessageLoop();
}
Window *w;
/* Process invalidations before anything else. */
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
w->ProcessScheduledInvalidations();
w->ProcessHighlightedInvalidations();
}
@@ -3491,7 +3463,7 @@ void UpdateWindows()
if (window_timer.HasElapsed()) {
window_timer.SetInterval(MILLISECONDS_PER_TICK);
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) {
CLRBITS(w->flags, WF_WHITE_BORDER);
w->SetDirty();
@@ -3501,7 +3473,7 @@ void UpdateWindows()
DrawDirtyBlocks();
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
/* Update viewport only if window is not shaded. */
if (w->viewport != nullptr && !w->IsShaded()) UpdateViewportPosition(w);
}
@@ -3517,8 +3489,7 @@ void UpdateWindows()
*/
void SetWindowDirty(WindowClass cls, WindowNumber number)
{
const Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == cls && w->window_number == number) w->SetDirty();
}
}
@@ -3531,8 +3502,7 @@ void SetWindowDirty(WindowClass cls, WindowNumber number)
*/
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
{
const Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == cls && w->window_number == number) {
w->SetWidgetDirty(widget_index);
}
@@ -3545,8 +3515,7 @@ void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_inde
*/
void SetWindowClassesDirty(WindowClass cls)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class == cls) w->SetDirty();
}
}
@@ -3618,8 +3587,7 @@ void Window::ProcessHighlightedInvalidations()
*/
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls && w->window_number == number) {
w->InvalidateData(data, gui_scope);
}
@@ -3636,9 +3604,7 @@ void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool g
*/
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls) {
w->InvalidateData(data, gui_scope);
}
@@ -3650,8 +3616,7 @@ void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
*/
void CallWindowGameTickEvent()
{
Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
for (Window *w : Window::IterateFromFront()) {
w->OnGameTick();
}
}
@@ -3664,13 +3629,11 @@ void CallWindowGameTickEvent()
*/
void DeleteNonVitalWindows()
{
Window *w;
restart_search:
/* When we find the window to delete, we need to restart the search
* as deleting this window could cascade in deleting (many) others
* anywhere in the z-array */
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class != WC_MAIN_WINDOW &&
w->window_class != WC_SELECT_GAME &&
w->window_class != WC_MAIN_TOOLBAR &&
@@ -3694,8 +3657,6 @@ restart_search:
*/
void DeleteAllNonVitalWindows()
{
Window *w;
/* Delete every window except for stickied ones, then sticky ones as well */
DeleteNonVitalWindows();
@@ -3703,7 +3664,7 @@ restart_search:
/* When we find the window to delete, we need to restart the search
* as deleting this window could cascade in deleting (many) others
* anywhere in the z-array */
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->flags & WF_STICKY) {
delete w;
goto restart_search;
@@ -3728,20 +3689,18 @@ void DeleteAllMessages()
*/
void DeleteConstructionWindows()
{
Window *w;
restart_search:
/* When we find the window to delete, we need to restart the search
* as deleting this window could cascade in deleting (many) others
* anywhere in the z-array */
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->window_desc->flags & WDF_CONSTRUCTION) {
delete w;
goto restart_search;
}
}
FOR_ALL_WINDOWS_FROM_BACK(w) w->SetDirty();
for (const Window *w : Window::IterateFromBack()) w->SetDirty();
}
/**
@@ -3775,7 +3734,7 @@ void HideVitalWindows()
}
/** Re-initialize all windows. */
void ReInitAllWindows()
void ReInitAllWindows(bool zoom_changed)
{
NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
NWidgetScrollbar::InvalidateDimensionCache();
@@ -3783,8 +3742,8 @@ void ReInitAllWindows()
extern void InitDepotWindowBlockSizes();
InitDepotWindowBlockSizes();
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
if (zoom_changed) w->nested_root->AdjustPaddingForZoom();
w->ReInit();
}
@@ -3874,8 +3833,7 @@ int PositionNetworkChatWindow(Window *w)
*/
void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index)
{
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (const Window *w : Window::IterateFromBack()) {
if (w->viewport != nullptr && w->viewport->follow_vehicle == from_index) {
w->viewport->follow_vehicle = to_index;
w->SetDirty();
@@ -3893,8 +3851,7 @@ void RelocateAllWindows(int neww, int newh)
{
DeleteWindowById(WC_DROPDOWN_MENU, 0);
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
for (Window *w : Window::IterateFromBack()) {
int left, top;
/* XXX - this probably needs something more sane. For example specifying
* in a 'backup'-desc that the window should always be centered. */