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

Function DrawCommonTileSeqInGUI

src/sprite.cpp:86–124  ·  view source on GitHub ↗

* Draws a tile sprite sequence in the GUI * @param x X position to draw to * @param y Y position to draw to * @param dts Sprite and subsprites to draw * @param orig_offset Sprite-Offset for original sprites * @param newgrf_offset Sprite-Offset for NewGRF defined sprites * @param default_palette The default recolour sprite to use (typically company colour) * @param child_offset_is_unsigned W

Source from the content-addressed store, hash-verified

84 * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned
85 */
86void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
87{
88 Point child_offset = {0, 0};
89
90 bool skip_childs = false;
91 for (const DrawTileSeqStruct &dtss : dts->GetSequence()) {
92 SpriteID image = dtss.image.sprite;
93 PaletteID pal = dtss.image.pal;
94
95 if (skip_childs) {
96 if (!dtss.IsParentSprite()) continue;
97 skip_childs = false;
98 }
99
100 /* TTD sprite 0 means no sprite */
101 if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
102 skip_childs = dtss.IsParentSprite();
103 continue;
104 }
105
106 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
107 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset;
108
109 pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
110
111 if (dtss.IsParentSprite()) {
112 Point pt = RemapCoords(dtss.origin.x, dtss.origin.y, dtss.origin.z);
113 DrawSprite(image, pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y));
114
115 const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
116 child_offset.x = UnScaleGUI(pt.x + spr->x_offs);
117 child_offset.y = UnScaleGUI(pt.y + spr->y_offs);
118 } else {
119 int offs_x = child_offset_is_unsigned ? static_cast<uint8_t>(dtss.origin.x) : dtss.origin.x;
120 int offs_y = child_offset_is_unsigned ? static_cast<uint8_t>(dtss.origin.y) : dtss.origin.y;
121 DrawSprite(image, pal, x + child_offset.x + ScaleSpriteTrad(offs_x), y + child_offset.y + ScaleSpriteTrad(offs_y));
122 }
123 }
124}

Callers 4

DrawRoadStopTileFunction · 0.85
DrawRailTileSeqInGUIFunction · 0.85
DrawOrigTileSeqInGUIFunction · 0.85
DrawNewGRFTileSeqInGUIFunction · 0.85

Calls 10

GBFunction · 0.85
HasBitFunction · 0.85
RemapCoordsFunction · 0.85
DrawSpriteFunction · 0.85
UnScaleGUIFunction · 0.85
GetSpriteFunction · 0.85
ScaleSpriteTradFunction · 0.85
IsParentSpriteMethod · 0.80
GetSequenceMethod · 0.45

Tested by

no test coverage detected