mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
Fix #9995: Adjust viewport zoom level for HiDPI displays
On HiDPI screens the zoom level is increased for detailed rendering. This causes hard-coded zoom levels to be off by this adjustment. To fix these default zoom levels, we scale the zoom level based on `_gui_zoom` to get the scaled zoom level.
This commit is contained in:
parent
47a998fb0c
commit
93d2d4590f
@ -837,7 +837,7 @@ public:
|
||||
|
||||
this->InitNested(window_number);
|
||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
|
||||
nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ZOOM_LVL_INDUSTRY);
|
||||
nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_INDUSTRY));
|
||||
|
||||
this->InvalidateData();
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ struct MainWindow : Window
|
||||
ResizeWindow(this, _screen.width, _screen.height);
|
||||
|
||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
|
||||
nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
|
||||
nvp->InitializeViewport(this, TileXY(32, 32), ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
|
||||
|
||||
this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
|
||||
this->refresh.SetInterval(LINKGRAPH_DELAY);
|
||||
|
@ -310,7 +310,7 @@ struct NewsWindow : Window {
|
||||
/* Initialize viewport if it exists. */
|
||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
|
||||
if (nvp != nullptr) {
|
||||
nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : (uint32)GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
|
||||
nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : (uint32)GetReferenceTile(ni->reftype1, ni->ref1),ScaleZoomGUI(ZOOM_LVL_NEWS));
|
||||
if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
|
||||
if ((this->ni->flags & NF_INCOLOUR) == 0) {
|
||||
nvp->disp_flags |= ND_SHADE_GREY;
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
#include "zoom_func.h"
|
||||
|
||||
TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
|
||||
|
||||
@ -331,7 +332,7 @@ public:
|
||||
|
||||
this->flags |= WF_DISABLE_VP_SCROLL;
|
||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
|
||||
nvp->InitializeViewport(this, this->town->xy, ZOOM_LVL_NEWS);
|
||||
nvp->InitializeViewport(this, this->town->xy, ScaleZoomGUI(ZOOM_LVL_TOWN));
|
||||
|
||||
/* disable renaming town in network games if you are not the server */
|
||||
this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, _networking && !_network_server);
|
||||
|
@ -2736,7 +2736,7 @@ public:
|
||||
}
|
||||
this->FinishInitNested(window_number);
|
||||
this->owner = v->owner;
|
||||
this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), _vehicle_view_zoom_levels[v->type]);
|
||||
this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), ScaleZoomGUI(_vehicle_view_zoom_levels[v->type]));
|
||||
|
||||
this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->type;
|
||||
this->GetWidget<NWidgetCore>(WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type;
|
||||
|
@ -57,8 +57,8 @@ public:
|
||||
this->InitNested(window_number);
|
||||
|
||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_EV_VIEWPORT);
|
||||
nvp->InitializeViewport(this, 0, ZOOM_LVL_VIEWPORT);
|
||||
if (_settings_client.gui.zoom_min == ZOOM_LVL_VIEWPORT) this->DisableWidget(WID_EV_ZOOM_IN);
|
||||
nvp->InitializeViewport(this, 0, ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
|
||||
if (_settings_client.gui.zoom_min == viewport->zoom) this->DisableWidget(WID_EV_ZOOM_IN);
|
||||
|
||||
Point pt;
|
||||
if (tile == INVALID_TILE) {
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
#include "zoom_func.h"
|
||||
|
||||
/** GUI for accessing waypoints and buoys. */
|
||||
struct WaypointWindow : Window {
|
||||
@ -70,7 +71,7 @@ public:
|
||||
this->flags |= WF_DISABLE_VP_SCROLL;
|
||||
|
||||
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_W_VIEWPORT);
|
||||
nvp->InitializeViewport(this, this->GetCenterTile(), ZOOM_LVL_VIEWPORT);
|
||||
nvp->InitializeViewport(this, this->GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
|
||||
|
||||
this->OnInvalidateData(0);
|
||||
}
|
||||
|
@ -79,6 +79,26 @@ static inline int UnScaleGUI(int value)
|
||||
return UnScaleByZoom(value, ZOOM_LVL_GUI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale zoom level relative to GUI zoom.
|
||||
* @param value zoom level to scale
|
||||
* @return scaled zoom level
|
||||
*/
|
||||
static inline ZoomLevel ScaleZoomGUI(ZoomLevel value)
|
||||
{
|
||||
return std::clamp(ZoomLevel(value + (ZOOM_LVL_GUI - ZOOM_LVL_OUT_4X)), ZOOM_LVL_MIN, ZOOM_LVL_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* UnScale zoom level relative to GUI zoom.
|
||||
* @param value zoom level to scale
|
||||
* @return un-scaled zoom level
|
||||
*/
|
||||
static inline ZoomLevel UnScaleZoomGUI(ZoomLevel value)
|
||||
{
|
||||
return std::clamp(ZoomLevel(value - (ZOOM_LVL_GUI - ZOOM_LVL_OUT_4X)), ZOOM_LVL_MIN, ZOOM_LVL_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale traditional pixel dimensions to GUI zoom level.
|
||||
* @param value Pixel amount at #ZOOM_LVL_BASE (traditional "normal" interface size).
|
||||
|
@ -35,7 +35,7 @@ enum ZoomLevel : byte {
|
||||
ZOOM_LVL_VIEWPORT = ZOOM_LVL_OUT_4X, ///< Default zoom level for viewports.
|
||||
ZOOM_LVL_NEWS = ZOOM_LVL_OUT_4X, ///< Default zoom level for the news messages.
|
||||
ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_8X, ///< Default zoom level for the industry view.
|
||||
ZOOM_LVL_TOWN = ZOOM_LVL_OUT_8X, ///< Default zoom level for the town view.
|
||||
ZOOM_LVL_TOWN = ZOOM_LVL_OUT_4X, ///< Default zoom level for the town view.
|
||||
ZOOM_LVL_AIRCRAFT = ZOOM_LVL_OUT_4X, ///< Default zoom level for the aircraft view.
|
||||
ZOOM_LVL_SHIP = ZOOM_LVL_OUT_4X, ///< Default zoom level for the ship view.
|
||||
ZOOM_LVL_TRAIN = ZOOM_LVL_OUT_4X, ///< Default zoom level for the train view.
|
||||
|
Loading…
Reference in New Issue
Block a user