Merge remote-tracking branch 'upstream/master' into 13.0

This commit is contained in:
dP
2023-01-19 04:08:55 +04:00
336 changed files with 13062 additions and 8849 deletions

View File

@@ -359,6 +359,17 @@ QueryString *Window::GetQueryString(uint widnum)
return query != this->querystrings.End() ? query->second : nullptr;
}
/**
* Update size of all QueryStrings of this window.
*/
void Window::UpdateQueryStringSize()
{
for (auto &qs : this->querystrings)
{
qs.second->text.UpdateSize();
}
}
/**
* Get the current input text if an edit box has the focus.
* @return The currently focused input text or nullptr if no input focused.
@@ -1645,7 +1656,7 @@ static Point GetAutoPlacePosition(int width, int height)
*/
int left = rtl ? _screen.width - width : 0, top = toolbar_y;
int offset_x = rtl ? -(int)NWidgetLeaf::closebox_dimension.width : (int)NWidgetLeaf::closebox_dimension.width;
int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
restart:
for (const Window *w : Window::Iterate()) {
@@ -1711,7 +1722,7 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
* - Y position: closebox of parent + closebox of child + statusbar
* - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl)
*/
int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
if (w->top + 3 * indent_y < _screen.height) {
pt.y = w->top + indent_y;
int indent_close = NWidgetLeaf::closebox_dimension.width;
@@ -2004,28 +2015,30 @@ static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, i
{
if (v == nullptr) return;
const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
int v_bottom = v->top + v->height;
int v_right = v->left + v->width;
int safe_y = (dir == PHD_UP) ? (v->top - MIN_VISIBLE_TITLE_BAR - rect.top) : (v_bottom + MIN_VISIBLE_TITLE_BAR - rect.bottom); // Compute safe vertical position.
int safe_y = (dir == PHD_UP) ? (v->top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom); // Compute safe vertical position.
if (*ny + rect.top <= v->top - MIN_VISIBLE_TITLE_BAR) return; // Above v is enough space
if (*ny + rect.bottom >= v_bottom + MIN_VISIBLE_TITLE_BAR) return; // Below v is enough space
if (*ny + rect.top <= v->top - min_visible) return; // Above v is enough space
if (*ny + rect.bottom >= v_bottom + min_visible) return; // Below v is enough space
/* Vertically, the rectangle is hidden behind v. */
if (*nx + rect.left + MIN_VISIBLE_TITLE_BAR < v->left) { // At left of v.
if (v->left < MIN_VISIBLE_TITLE_BAR) *ny = safe_y; // But enough room, force it to a safe position.
if (*nx + rect.left + min_visible < v->left) { // At left of v.
if (v->left < min_visible) *ny = safe_y; // But enough room, force it to a safe position.
return;
}
if (*nx + rect.right - MIN_VISIBLE_TITLE_BAR > v_right) { // At right of v.
if (v_right > _screen.width - MIN_VISIBLE_TITLE_BAR) *ny = safe_y; // Not enough room, force it to a safe position.
if (*nx + rect.right - min_visible > v_right) { // At right of v.
if (v_right > _screen.width - min_visible) *ny = safe_y; // Not enough room, force it to a safe position.
return;
}
/* Horizontally also hidden, force movement to a safe area. */
if (px + rect.left < v->left && v->left >= MIN_VISIBLE_TITLE_BAR) { // Coming from the left, and enough room there.
*nx = v->left - MIN_VISIBLE_TITLE_BAR - rect.left;
} else if (px + rect.right > v_right && v_right <= _screen.width - MIN_VISIBLE_TITLE_BAR) { // Coming from the right, and enough room there.
*nx = v_right + MIN_VISIBLE_TITLE_BAR - rect.right;
if (px + rect.left < v->left && v->left >= min_visible) { // Coming from the left, and enough room there.
*nx = v->left - min_visible - rect.left;
} else if (px + rect.right > v_right && v_right <= _screen.width - min_visible) { // Coming from the right, and enough room there.
*nx = v_right + min_visible - rect.right;
} else {
*ny = safe_y;
}
@@ -2046,9 +2059,11 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny)
if (caption != nullptr) {
caption_rect = caption->GetCurrentRect();
const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
/* Make sure the window doesn't leave the screen */
nx = Clamp(nx, MIN_VISIBLE_TITLE_BAR - caption_rect.right, _screen.width - MIN_VISIBLE_TITLE_BAR - caption_rect.left);
ny = Clamp(ny, 0, _screen.height - MIN_VISIBLE_TITLE_BAR);
nx = Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left);
ny = Clamp(ny, 0, _screen.height - min_visible);
/* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */
PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);
@@ -3076,6 +3091,9 @@ void UpdateWindows()
PerformanceMeasurer framerate(PFE_DRAWING);
PerformanceAccumulator::Reset(PFE_DRAWWORLD);
extern void ProcessPendingPerformanceMeasurements();
ProcessPendingPerformanceMeasurements();
CallWindowRealtimeTickEvent(delta_ms);
static GUITimer network_message_timer = GUITimer(1);
@@ -3356,13 +3374,17 @@ void HideVitalWindows()
void ReInitWindow(Window *w, bool zoom_changed)
{
if (w == nullptr) return;
if (zoom_changed) w->nested_root->AdjustPaddingForZoom();
if (zoom_changed) {
w->nested_root->AdjustPaddingForZoom();
w->UpdateQueryStringSize();
}
w->ReInit();
}
/** Re-initialize all windows. */
void ReInitAllWindows(bool zoom_changed)
{
SetupWidgetDimensions();
NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
NWidgetScrollbar::InvalidateDimensionCache();