From 65159f4b2283d22b3d059100c9a94d9122f4b984 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 25 May 2023 20:28:31 +0100 Subject: [PATCH] Refactor viewport catchment overlay change handling --- src/viewport.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/viewport.cpp b/src/viewport.cpp index e67e86ecc4..b03bca9af7 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -6563,6 +6563,21 @@ void ResetRailPlacementSnapping() _current_snap_lock.x = -1; } +static void SetWindowDirtyForViewportCatchment() +{ + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); + if (_viewport_highlight_tracerestrict_program != nullptr) InvalidateWindowClassesData(WC_TRACE_RESTRICT); +} + +static void ClearViewportCatchment() +{ + MarkCatchmentTilesDirty(); + _viewport_highlight_station = nullptr; + _viewport_highlight_town = nullptr; + _viewport_highlight_tracerestrict_program = nullptr; +} + /** * Select or deselect station for coverage area highlight. * Selecting a station will deselect a town. @@ -6571,14 +6586,10 @@ void ResetRailPlacementSnapping() */ void SetViewportCatchmentStation(const Station *st, bool sel) { - if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); - if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); + SetWindowDirtyForViewportCatchment(); if (sel && _viewport_highlight_station != st) { - MarkCatchmentTilesDirty(); + ClearViewportCatchment(); _viewport_highlight_station = st; - _viewport_highlight_town = nullptr; - if (_viewport_highlight_tracerestrict_program != nullptr) InvalidateWindowClassesData(WC_TRACE_RESTRICT); - _viewport_highlight_tracerestrict_program = nullptr; MarkCatchmentTilesDirty(); } else if (!sel && _viewport_highlight_station == st) { MarkCatchmentTilesDirty(); @@ -6595,13 +6606,10 @@ void SetViewportCatchmentStation(const Station *st, bool sel) */ void SetViewportCatchmentTown(const Town *t, bool sel) { - if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); - if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + SetWindowDirtyForViewportCatchment(); if (sel && _viewport_highlight_town != t) { - _viewport_highlight_station = nullptr; + ClearViewportCatchment(); _viewport_highlight_town = t; - if (_viewport_highlight_tracerestrict_program != nullptr) InvalidateWindowClassesData(WC_TRACE_RESTRICT); - _viewport_highlight_tracerestrict_program = nullptr; MarkWholeNonMapViewportsDirty(); } else if (!sel && _viewport_highlight_town == t) { _viewport_highlight_town = nullptr; @@ -6612,19 +6620,16 @@ void SetViewportCatchmentTown(const Town *t, bool sel) void SetViewportCatchmentTraceRestrictProgram(const TraceRestrictProgram *prog, bool sel) { - if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); - if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + SetWindowDirtyForViewportCatchment(); if (sel && _viewport_highlight_tracerestrict_program != prog) { - _viewport_highlight_station = nullptr; - _viewport_highlight_town = nullptr; + ClearViewportCatchment(); _viewport_highlight_tracerestrict_program = prog; - InvalidateWindowClassesData(WC_TRACE_RESTRICT); MarkWholeNonMapViewportsDirty(); } else if (!sel && _viewport_highlight_tracerestrict_program == prog) { _viewport_highlight_tracerestrict_program = nullptr; - InvalidateWindowClassesData(WC_TRACE_RESTRICT); MarkWholeNonMapViewportsDirty(); } + if (_viewport_highlight_tracerestrict_program != nullptr) InvalidateWindowClassesData(WC_TRACE_RESTRICT); } int GetSlopeTreeBrightnessAdjust(Slope slope)