From 76701c4622cc37b0a5b697ac97b9786986928068 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 25 Nov 2023 20:20:35 +0000 Subject: [PATCH] Add: Function to get largest cargo icon size. --- src/cargotype.cpp | 16 +++++++++++++++- src/cargotype.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cargotype.cpp b/src/cargotype.cpp index 3b72e49647..08c56bc535 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -9,6 +9,7 @@ #include "stdafx.h" #include "cargotype.h" +#include "core/geometry_func.hpp" #include "newgrf_cargo.h" #include "string_func.h" #include "strings_func.h" @@ -70,6 +71,19 @@ void SetupCargoForClimate(LandscapeID l) std::fill(insert, std::end(CargoSpec::array), CargoSpec{}); } +/** + * Get dimensions of largest cargo icon. + * @return Dimensions of largest cargo icon. + */ +Dimension GetLargestCargoIconSize() +{ + Dimension size = {0, 0}; + for (const CargoSpec *cs : _sorted_cargo_specs) { + size = maxdim(size, GetSpriteSize(cs->GetCargoIcon())); + } + return size; +} + /** * Get the cargo ID of a default cargo, if present. * @param l Landscape @@ -179,7 +193,7 @@ static bool CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * c void InitializeSortedCargoSpecs() { _sorted_cargo_specs.clear(); - /* Add each cargo spec to the list. */ + /* Add each cargo spec to the list, and determine the largest cargo icon size. */ for (const CargoSpec *cargo : CargoSpec::Iterate()) { _sorted_cargo_specs.push_back(cargo); } diff --git a/src/cargotype.h b/src/cargotype.h index 7b3674675f..0e786011a2 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -185,6 +185,7 @@ void SetupCargoForClimate(LandscapeID l); CargoID GetCargoIDByLabel(CargoLabel cl); CargoID GetCargoIDByBitnum(uint8_t bitnum); CargoID GetDefaultCargoID(LandscapeID l, CargoType ct); +Dimension GetLargestCargoIconSize(); void InitializeSortedCargoSpecs(); extern std::array _sorted_cargo_types;