diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index d69d6c0e0c..cf78f4db90 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -837,7 +837,7 @@ public: this->InitNested(window_number); NWidgetViewport *nvp = this->GetWidget(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(); } diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 511555ff9e..a102ff684b 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -222,7 +222,7 @@ struct MainWindow : Window ResizeWindow(this, _screen.width, _screen.height); NWidgetViewport *nvp = this->GetWidget(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); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index a4c4c14082..1a12dad803 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -310,7 +310,7 @@ struct NewsWindow : Window { /* Initialize viewport if it exists. */ NWidgetViewport *nvp = this->GetWidget(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; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 6206ffc894..216de7e79a 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -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(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); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index e4fc8aa554..41ac89846c 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2736,7 +2736,7 @@ public: } this->FinishInitNested(window_number); this->owner = v->owner; - this->GetWidget(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), _vehicle_view_zoom_levels[v->type]); + this->GetWidget(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), ScaleZoomGUI(_vehicle_view_zoom_levels[v->type])); this->GetWidget(WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->type; this->GetWidget(WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type; diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 5047f04f3f..6f74237d33 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -57,8 +57,8 @@ public: this->InitNested(window_number); NWidgetViewport *nvp = this->GetWidget(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) { diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index 4fca572242..0d688b49d9 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -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(WID_W_VIEWPORT); - nvp->InitializeViewport(this, this->GetCenterTile(), ZOOM_LVL_VIEWPORT); + nvp->InitializeViewport(this, this->GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_VIEWPORT)); this->OnInvalidateData(0); } diff --git a/src/zoom_func.h b/src/zoom_func.h index 0a5113186f..f72c7abae4 100644 --- a/src/zoom_func.h +++ b/src/zoom_func.h @@ -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). diff --git a/src/zoom_type.h b/src/zoom_type.h index 0945e1cc09..ffa70f7611 100644 --- a/src/zoom_type.h +++ b/src/zoom_type.h @@ -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.