Merge commit '13.0-RC1~2'

This commit is contained in:
2023-02-25 04:49:57 +00:00
603 changed files with 26913 additions and 18390 deletions

View File

@@ -17,10 +17,12 @@
#include "settings_type.h"
#include "network/network.h"
#include "network/network_func.h"
#include "window_gui.h"
#include "window_func.h"
#include "newgrf_debug.h"
#include "thread.h"
#include "core/backup_type.hpp"
#include "viewport_func.h"
#include "table/palettes.h"
#include "table/string_colours.h"
@@ -62,12 +64,9 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode,
static ReusableBuffer<uint8> _cursor_backup;
ZoomLevel _gui_zoom; ///< GUI Zoom level
ZoomLevel _font_zoom; ///< Font Zoom level
int8 _gui_zoom_cfg; ///< GUI zoom level in config.
int8 _font_zoom_cfg; ///< Font zoom level in config.
ZoomLevel _gui_zoom = ZOOM_LVL_OUT_4X; ///< GUI Zoom level
int _gui_scale = MIN_INTERFACE_SCALE; ///< GUI scale, 100 is 100%.
int _gui_scale_cfg; ///< GUI scale in config.
/**
* The rect for repaint.
@@ -565,6 +564,8 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
NOT_REACHED();
}
const uint shadow_offset = ScaleGUITrad(1);
TextColour colour = TC_BLACK;
bool draw_shadow = false;
for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
@@ -600,7 +601,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
if (draw_shadow && (glyph & SPRITE_GLYPH) == 0) {
SetColourRemap(TC_BLACK);
GfxMainBlitter(sprite, begin_x + 1, top + 1, BM_COLOUR_REMAP);
GfxMainBlitter(sprite, begin_x + shadow_offset, top + shadow_offset, BM_COLOUR_REMAP);
SetColourRemap(colour);
}
GfxMainBlitter(sprite, begin_x, top, BM_COLOUR_REMAP);
@@ -612,7 +613,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
for (int i = 0; i < 3; i++, x += dot_width) {
if (draw_shadow) {
SetColourRemap(TC_BLACK);
GfxMainBlitter(dot_sprite, x + 1, y + 1, BM_COLOUR_REMAP);
GfxMainBlitter(dot_sprite, x + shadow_offset, y + shadow_offset, BM_COLOUR_REMAP);
SetColourRemap(colour);
}
GfxMainBlitter(dot_sprite, x, y, BM_COLOUR_REMAP);
@@ -822,7 +823,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, const char *st
for (const auto &line : layout) {
int line_height = line->GetLeading();
if (y >= top && y < bottom) {
if (y >= top && y + line_height - 1 <= bottom) {
last_line = y + line_height;
if (first_line > y) first_line = y;
@@ -916,12 +917,27 @@ Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize)
* @param strid String to examine.
* @return Width and height of the bounding box for the string in pixels.
*/
Dimension GetStringBoundingBox(StringID strid)
Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize)
{
char buffer[DRAW_STRING_BUFFER];
GetString(buffer, strid, lastof(buffer));
return GetStringBoundingBox(buffer);
return GetStringBoundingBox(buffer, start_fontsize);
}
/**
* Get maximum width of a list of strings.
* @param list List of strings, terminated with INVALID_STRING_ID.
* @param fontsize Font size to use.
* @return Width of longest string within the list.
*/
uint GetStringListWidth(const StringID *list, FontSize fontsize)
{
uint width = 0;
for (const StringID *str = list; *str != INVALID_STRING_ID; str++) {
width = std::max(width, GetStringBoundingBox(*str, fontsize).width);
}
return width;
}
/**
@@ -2071,22 +2087,58 @@ void SortResolutions()
void UpdateGUIZoom()
{
/* Determine real GUI zoom to use. */
if (_gui_zoom_cfg == ZOOM_LVL_CFG_AUTO) {
_gui_zoom = static_cast<ZoomLevel>(Clamp(VideoDriver::GetInstance()->GetSuggestedUIZoom(), _settings_client.gui.zoom_min, _settings_client.gui.zoom_max));
if (_gui_scale_cfg == -1) {
_gui_scale = VideoDriver::GetInstance()->GetSuggestedUIScale();
} else {
/* Ensure the gui_zoom is clamped between min/max. Change the
* _gui_zoom_cfg if it isn't, as this is used to visually show the
* selection in the Game Options. */
_gui_zoom_cfg = Clamp(_gui_zoom_cfg, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
_gui_zoom = static_cast<ZoomLevel>(_gui_zoom_cfg);
_gui_scale = Clamp(_gui_scale_cfg, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE);
}
/* Determine real font zoom to use. */
if (_font_zoom_cfg == ZOOM_LVL_CFG_AUTO) {
_font_zoom = static_cast<ZoomLevel>(VideoDriver::GetInstance()->GetSuggestedUIZoom());
} else {
_font_zoom = static_cast<ZoomLevel>(_font_zoom_cfg);
int8 new_zoom = ScaleGUITrad(1) <= 1 ? ZOOM_LVL_OUT_4X : ScaleGUITrad(1) >= 4 ? ZOOM_LVL_MIN : ZOOM_LVL_OUT_2X;
/* Ensure the gui_zoom is clamped between min/max. */
new_zoom = Clamp(new_zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
_gui_zoom = static_cast<ZoomLevel>(new_zoom);
}
/**
* Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
* @param automatic Set if the change is occuring due to OS DPI scaling being changed.
* @returns true when the zoom level has changed, caller must call ReInitAllWindows(true)
* after resizing the application's window/buffer.
*/
bool AdjustGUIZoom(bool automatic)
{
ZoomLevel old_zoom = _gui_zoom;
int old_scale = _gui_scale;
UpdateGUIZoom();
if (old_scale == _gui_scale) return false;
/* Reload sprites if sprite zoom level has changed. */
if (old_zoom != _gui_zoom) {
GfxClearSpriteCache();
VideoDriver::GetInstance()->ClearSystemSprites();
UpdateCursorSize();
}
ClearFontCache();
LoadStringWidthTable();
UpdateAllVirtCoords();
/* Adjust all window sizes to match the new zoom level, so that they don't appear
to move around when the application is moved to a screen with different DPI. */
auto zoom_shift = old_zoom - _gui_zoom;
for (Window *w : Window::Iterate()) {
if (automatic) {
w->left = (w->left * _gui_scale) / old_scale;
w->top = (w->top * _gui_scale) / old_scale;
w->width = (w->width * _gui_scale) / old_scale;
w->height = (w->height * _gui_scale) / old_scale;
}
if (w->viewport != nullptr) {
w->viewport->zoom = Clamp(ZoomLevel(w->viewport->zoom - zoom_shift), _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
}
}
return true;
}
void ChangeGameSpeed(bool enable_fast_forward)