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

Function UpdateCursorSize

src/gfx.cpp:1618–1649  ·  view source on GitHub ↗

* Update cursor dimension. * Called when changing cursor sprite resp. reloading grfs. */

Source from the content-addressed store, hash-verified

1616 * Called when changing cursor sprite resp. reloading grfs.
1617 */
1618void UpdateCursorSize()
1619{
1620 /* Ignore setting any cursor before the sprites are loaded. */
1621 if (GetMaxSpriteID() == 0) return;
1622
1623 bool first = true;
1624 for (const auto &cs : _cursor.sprites) {
1625 const Sprite *p = GetSprite(GB(cs.image.sprite, 0, SPRITE_WIDTH), SpriteType::Normal);
1626 Point offs, size;
1627 offs.x = UnScaleGUI(p->x_offs) + cs.pos.x;
1628 offs.y = UnScaleGUI(p->y_offs) + cs.pos.y;
1629 size.x = UnScaleGUI(p->width);
1630 size.y = UnScaleGUI(p->height);
1631
1632 if (first) {
1633 /* First sprite sets the total. */
1634 _cursor.total_offs = offs;
1635 _cursor.total_size = size;
1636 first = false;
1637 } else {
1638 /* Additional sprites expand the total. */
1639 int right = std::max(_cursor.total_offs.x + _cursor.total_size.x, offs.x + size.x);
1640 int bottom = std::max(_cursor.total_offs.y + _cursor.total_size.y, offs.y + size.y);
1641 if (offs.x < _cursor.total_offs.x) _cursor.total_offs.x = offs.x;
1642 if (offs.y < _cursor.total_offs.y) _cursor.total_offs.y = offs.y;
1643 _cursor.total_size.x = right - _cursor.total_offs.x;
1644 _cursor.total_size.y = bottom - _cursor.total_offs.y;
1645 }
1646 }
1647
1648 _cursor.dirty = true;
1649}
1650
1651/**
1652 * Switch cursor to different sprite.

Callers 4

SetCursorSpriteFunction · 0.85
AdjustGUIZoomFunction · 0.85
GfxLoadSpritesFunction · 0.85
SetMouseCursorVehicleFunction · 0.85

Calls 4

GetMaxSpriteIDFunction · 0.85
GetSpriteFunction · 0.85
GBFunction · 0.85
UnScaleGUIFunction · 0.85

Tested by

no test coverage detected