mirror of https://github.com/OpenTTD/OpenTTD.git
Feature: Automatic UI and font zoom levels when supported by the OS.
This commit is contained in:
parent
a2c3197f42
commit
22f5aeab07
24
src/gfx.cpp
24
src/gfx.cpp
|
@ -59,6 +59,10 @@ 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.
|
||||
|
||||
|
||||
/**
|
||||
* The rect for repaint.
|
||||
*
|
||||
|
@ -1876,3 +1880,23 @@ void SortResolutions()
|
|||
{
|
||||
std::sort(_resolutions.begin(), _resolutions.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve GUI zoom level, if auto-suggestion is requested.
|
||||
*/
|
||||
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));
|
||||
} else {
|
||||
_gui_zoom = static_cast<ZoomLevel>(_gui_zoom_cfg);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ void UpdateWindows();
|
|||
void DrawMouseCursor();
|
||||
void ScreenSizeChanged();
|
||||
void GameSizeChanged();
|
||||
void UpdateGUIZoom();
|
||||
void UndrawMouseCursor();
|
||||
|
||||
/** Size of the buffer used for drawing strings. */
|
||||
|
|
|
@ -1004,6 +1004,7 @@ STR_GAME_OPTIONS_RESOLUTION_OTHER :other
|
|||
STR_GAME_OPTIONS_GUI_ZOOM_FRAME :{BLACK}Interface size
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP :{BLACK}Select the interface element size to use
|
||||
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_AUTO :(auto-detect)
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL :Normal
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM :Double size
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM :Quad size
|
||||
|
@ -1011,6 +1012,7 @@ STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM :Quad size
|
|||
STR_GAME_OPTIONS_FONT_ZOOM :{BLACK}Font size
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP :{BLACK}Select the interface font size to use
|
||||
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_AUTO :(auto-detect)
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL :Normal
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM :Double size
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM :Quad size
|
||||
|
|
|
@ -771,6 +771,7 @@ int openttd_main(int argc, char *argv[])
|
|||
|
||||
/* Initialize the zoom level of the screen to normal */
|
||||
_screen.zoom = ZOOM_LVL_NORMAL;
|
||||
UpdateGUIZoom();
|
||||
|
||||
NetworkStartUp(); // initialize network-core
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ static const StringID _autosave_dropdown[] = {
|
|||
};
|
||||
|
||||
static const StringID _gui_zoom_dropdown[] = {
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_AUTO,
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL,
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM,
|
||||
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM,
|
||||
|
@ -65,6 +66,7 @@ static const StringID _gui_zoom_dropdown[] = {
|
|||
};
|
||||
|
||||
static const StringID _font_zoom_dropdown[] = {
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_AUTO,
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL,
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM,
|
||||
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM,
|
||||
|
@ -291,16 +293,16 @@ struct GameOptionsWindow : Window {
|
|||
break;
|
||||
|
||||
case WID_GO_GUI_ZOOM_DROPDOWN: {
|
||||
*selected_index = ZOOM_LVL_OUT_4X - _gui_zoom;
|
||||
*selected_index = _gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom + 1 : 0;
|
||||
const StringID *items = _gui_zoom_dropdown;
|
||||
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
|
||||
list.emplace_back(new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i));
|
||||
list.emplace_back(new DropDownListStringItem(*items, i, i != 0 && _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i + 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_GO_FONT_ZOOM_DROPDOWN: {
|
||||
*selected_index = ZOOM_LVL_OUT_4X - _font_zoom;
|
||||
*selected_index = _font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom + 1 : 0;
|
||||
const StringID *items = _font_zoom_dropdown;
|
||||
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
|
||||
list.emplace_back(new DropDownListStringItem(*items, i, false));
|
||||
|
@ -333,8 +335,8 @@ struct GameOptionsWindow : Window {
|
|||
case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
|
||||
case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
|
||||
case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
|
||||
case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[ZOOM_LVL_OUT_4X - _gui_zoom]); break;
|
||||
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[ZOOM_LVL_OUT_4X - _font_zoom]); break;
|
||||
case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
|
||||
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
|
||||
case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
|
||||
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
|
||||
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
|
||||
|
@ -538,7 +540,8 @@ struct GameOptionsWindow : Window {
|
|||
|
||||
case WID_GO_GUI_ZOOM_DROPDOWN:
|
||||
GfxClearSpriteCache();
|
||||
_gui_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index);
|
||||
_gui_zoom_cfg = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
|
||||
UpdateGUIZoom();
|
||||
UpdateCursorSize();
|
||||
UpdateAllVirtCoords();
|
||||
FixTitleGameZoom();
|
||||
|
@ -547,7 +550,8 @@ struct GameOptionsWindow : Window {
|
|||
|
||||
case WID_GO_FONT_ZOOM_DROPDOWN:
|
||||
GfxClearSpriteCache();
|
||||
_font_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index);
|
||||
_font_zoom_cfg = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
|
||||
UpdateGUIZoom();
|
||||
ClearFontCache();
|
||||
LoadStringWidthTable();
|
||||
UpdateAllVirtCoords();
|
||||
|
|
|
@ -334,19 +334,19 @@ proc = ZoomMinMaxChanged
|
|||
|
||||
[SDTG_VAR]
|
||||
name = ""gui_zoom""
|
||||
type = SLE_UINT8
|
||||
var = _gui_zoom
|
||||
def = ZOOM_LVL_OUT_4X
|
||||
min = ZOOM_LVL_MIN
|
||||
type = SLE_INT8
|
||||
var = _gui_zoom_cfg
|
||||
def = ZOOM_LVL_CFG_AUTO
|
||||
min = ZOOM_LVL_CFG_AUTO
|
||||
max = ZOOM_LVL_OUT_4X
|
||||
cat = SC_BASIC
|
||||
|
||||
[SDTG_VAR]
|
||||
name = ""font_zoom""
|
||||
type = SLE_UINT8
|
||||
var = _font_zoom
|
||||
def = ZOOM_LVL_OUT_4X
|
||||
min = ZOOM_LVL_MIN
|
||||
type = SLE_INT8
|
||||
var = _font_zoom_cfg
|
||||
def = ZOOM_LVL_CFG_AUTO
|
||||
min = ZOOM_LVL_CFG_AUTO
|
||||
max = ZOOM_LVL_OUT_4X
|
||||
cat = SC_BASIC
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
static uint const ZOOM_LVL_SHIFT = 2;
|
||||
static uint const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT;
|
||||
|
||||
static const int8 ZOOM_LVL_CFG_AUTO = -1;
|
||||
|
||||
/** All zoom levels we know. */
|
||||
enum ZoomLevel : byte {
|
||||
/* Our possible zoom-levels */
|
||||
|
@ -48,6 +50,9 @@ enum ZoomLevel : byte {
|
|||
};
|
||||
DECLARE_POSTFIX_INCREMENT(ZoomLevel)
|
||||
|
||||
extern int8 _gui_zoom_cfg;
|
||||
extern int8 _font_zoom_cfg;
|
||||
|
||||
extern ZoomLevel _gui_zoom;
|
||||
extern ZoomLevel _font_zoom;
|
||||
#define ZOOM_LVL_GUI (_gui_zoom)
|
||||
|
|
Loading…
Reference in New Issue