From 22f5aeab07cb1c67561b9e348e2c944740233607 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Fri, 8 Jan 2021 22:15:06 +0100 Subject: Feature: Automatic UI and font zoom levels when supported by the OS. --- src/video/video_driver.hpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/video/video_driver.hpp') diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index d4e750134..bc445d92d 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -13,6 +13,7 @@ #include "../driver.h" #include "../core/geometry_type.hpp" #include "../core/math_func.hpp" +#include "../zoom_type.h" #include extern std::string _ini_videodriver; @@ -105,6 +106,18 @@ public: */ virtual void EditBoxGainedFocus() {} + /** + * Get a suggested default GUI zoom taking screen DPI into account. + */ + virtual ZoomLevel GetSuggestedUIZoom() + { + float dpi_scale = this->GetDPIScale(); + + if (dpi_scale >= 3.0f) return ZOOM_LVL_NORMAL; + if (dpi_scale >= 1.5f) return ZOOM_LVL_OUT_2X; + return ZOOM_LVL_OUT_4X; + } + /** * Get the currently active instance of the video driver. */ @@ -113,11 +126,17 @@ public: } protected: - /* + /** * Get the resolution of the main screen. */ virtual Dimension GetScreenSize() const { return { DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT }; } + /** + * Get DPI scaling factor of the screen OTTD is displayed on. + * @return 1.0 for default platform DPI, > 1.0 for higher DPI values, and < 1.0 for smaller DPI values. + */ + virtual float GetDPIScale() { return 1.0f; } + /** * Apply resolution auto-detection and clamp to sensible defaults. */ -- cgit v1.2.3-54-g00ecf