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

Function AdjustGUIZoom

src/gfx.cpp:1818–1856  ·  view source on GitHub ↗

* Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested. * @param automatic Set if the change is occurring 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. */

Source from the content-addressed store, hash-verified

1816 * after resizing the application's window/buffer.
1817 */
1818bool AdjustGUIZoom(bool automatic)
1819{
1820 if (VideoDriver::GetInstance() == nullptr) return false;
1821
1822 ZoomLevel old_gui_zoom = _gui_zoom;
1823 ZoomLevel old_font_zoom = _font_zoom;
1824 int old_scale = _gui_scale;
1825 UpdateGUIZoom();
1826 if (old_scale == _gui_scale && old_gui_zoom == _gui_zoom) return false;
1827
1828 /* Update cursors if sprite zoom level has changed. */
1829 if (old_gui_zoom != _gui_zoom) {
1830 VideoDriver::GetInstance()->ClearSystemSprites();
1831 UpdateCursorSize();
1832 }
1833 if (old_font_zoom != _font_zoom) {
1834 GfxClearFontSpriteCache();
1835 }
1836 FontCache::ClearFontCaches(FONTSIZES_ALL);
1837 LoadStringWidthTable();
1838
1839 SetupWidgetDimensions();
1840 UpdateAllVirtCoords();
1841
1842 /* Adjust all window sizes to match the new zoom level, so that they don't appear
1843 to move around when the application is moved to a screen with different DPI. */
1844 auto zoom_shift = old_gui_zoom - _gui_zoom;
1845 for (Window *w : Window::Iterate()) {
1846 if (automatic) {
1847 w->left = (w->left * _gui_scale) / old_scale;
1848 w->top = (w->top * _gui_scale) / old_scale;
1849 }
1850 if (w->viewport != nullptr) {
1851 w->viewport->zoom = Clamp(w->viewport->zoom - zoom_shift, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max);
1852 }
1853 }
1854
1855 return true;
1856}
1857
1858void ChangeGameSpeed(bool enable_fast_forward)
1859{

Callers 5

ScreenSizeChangedFunction · 0.85
OnClickMethod · 0.85
OnMouseLoopMethod · 0.85
ZoomMinMaxChangedFunction · 0.85
WndProcGdiFunction · 0.85

Calls 8

UpdateGUIZoomFunction · 0.85
UpdateCursorSizeFunction · 0.85
GfxClearFontSpriteCacheFunction · 0.85
LoadStringWidthTableFunction · 0.85
SetupWidgetDimensionsFunction · 0.85
UpdateAllVirtCoordsFunction · 0.85
ClampFunction · 0.85
ClearSystemSpritesMethod · 0.45

Tested by

no test coverage detected