forked from mirror/OpenTTD
Fix #9993: Handle DPI changes on macOS and Windows
This commit is contained in:
committed by
Michael Lutz
parent
bda602f4b0
commit
45d98f689a
34
src/gfx.cpp
34
src/gfx.cpp
@@ -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"
|
||||
@@ -2042,6 +2044,38 @@ void UpdateGUIZoom()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
|
||||
* @returns true when the zoom level has changed, caller must call ReInitAllWindows(true)
|
||||
* after resizing the application's window/buffer.
|
||||
*/
|
||||
bool AdjustGUIZoom()
|
||||
{
|
||||
auto old_zoom = _gui_zoom;
|
||||
UpdateGUIZoom();
|
||||
if (old_zoom == _gui_zoom) return false;
|
||||
GfxClearSpriteCache();
|
||||
VideoDriver::GetInstance()->ClearSystemSprites();
|
||||
ClearFontCache();
|
||||
GfxClearSpriteCache();
|
||||
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 (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)
|
||||
{
|
||||
if (enable_fast_forward) {
|
||||
|
Reference in New Issue
Block a user