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

@@ -65,12 +65,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.
@@ -569,6 +566,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++) {
@@ -604,7 +603,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);
@@ -616,7 +615,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);
@@ -920,12 +919,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;
}
/**
@@ -2033,48 +2047,52 @@ 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 AdjustGUIZoom(bool automatic)
{
auto old_zoom = _gui_zoom;
ZoomLevel old_zoom = _gui_zoom;
int old_scale = _gui_scale;
UpdateGUIZoom();
if (old_zoom == _gui_zoom) return false;
GfxClearSpriteCache();
VideoDriver::GetInstance()->ClearSystemSprites();
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();
GfxClearSpriteCache();
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()) {
w->left = AdjustByZoom(w->left, zoom_shift);
w->top = AdjustByZoom(w->top, zoom_shift);
w->width = AdjustByZoom(w->width, zoom_shift);
w->height = AdjustByZoom(w->height, zoom_shift);
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);
}