MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetMaxTreeSpriteSize

Function GetMaxTreeSpriteSize

src/tree_gui.cpp:53–74  ·  view source on GitHub ↗

* Calculate the maximum size of all tree sprites * @return Dimension of the largest tree sprite */

Source from the content-addressed store, hash-verified

51 * @return Dimension of the largest tree sprite
52 */
53static Dimension GetMaxTreeSpriteSize()
54{
55 const uint16_t base = _tree_base_by_landscape[to_underlying(_settings_game.game_creation.landscape)];
56 const uint16_t count = _tree_count_by_landscape[to_underlying(_settings_game.game_creation.landscape)];
57
58 Dimension size, this_size;
59 Point offset;
60 /* Avoid to use it uninitialized */
61 size.width = ScaleGUITrad(32); // default width - WD_FRAMERECT_LEFT
62 size.height = ScaleGUITrad(39); // default height - BUTTON_BOTTOM_OFFSET
63 offset.x = 0;
64 offset.y = 0;
65
66 for (int i = base; i < base + count; i++) {
67 if (i >= (int)lengthof(tree_sprites)) return size;
68 this_size = GetSpriteSize(tree_sprites[i].sprite, &offset);
69 size.width = std::max<int>(size.width, 2 * std::max<int>(this_size.width, -offset.x));
70 size.height = std::max<int>(size.height, std::max<int>(this_size.height, -offset.y));
71 }
72
73 return size;
74}
75
76
77/**

Callers 1

UpdateWidgetSizeMethod · 0.85

Calls 3

to_underlyingFunction · 0.85
GetSpriteSizeFunction · 0.85
ScaleGUITradFunction · 0.70

Tested by

no test coverage detected