summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-08 22:15:06 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-14 14:16:40 +0100
commit22f5aeab07cb1c67561b9e348e2c944740233607 (patch)
tree0dbb0edbf02962e297e7d99e6d96b14ee570333b /src/video
parenta2c3197f424daa6e02201d8304015b0eb67d0b04 (diff)
downloadopenttd-22f5aeab07cb1c67561b9e348e2c944740233607.tar.xz
Feature: Automatic UI and font zoom levels when supported by the OS.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/video_driver.hpp21
1 files changed, 20 insertions, 1 deletions
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 <vector>
extern std::string _ini_videodriver;
@@ -106,6 +107,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.
*/
static VideoDriver *GetInstance() {
@@ -113,12 +126,18 @@ 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.
*/
void UpdateAutoResolution()