Changeset - r28219:a652c2aea845
[Not reviewed]
master
0 2 0
Peter Nelson - 7 months ago 2023-11-25 20:20:35
peter1138@openttd.org
Add: Function to get largest cargo icon size.
2 files changed with 16 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/cargotype.cpp
Show inline comments
 
@@ -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"
 
@@ -71,6 +72,19 @@ void SetupCargoForClimate(LandscapeID l)
 
}
 

	
 
/**
 
 * 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
 
 * @param ct Default cargo type.
 
@@ -179,7 +193,7 @@ static bool CargoSpecClassSorter(const 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);
 
	}
src/cargotype.h
Show inline comments
 
@@ -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<uint8_t, NUM_CARGO> _sorted_cargo_types;
0 comments (0 inline, 0 general)