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

Function ScrollWindowTo

src/viewport.cpp:2546–2572  ·  view source on GitHub ↗

* Scrolls the viewport in a window to a given location. * @param x Desired x location of the map to scroll to (world coordinate). * @param y Desired y location of the map to scroll to (world coordinate). * @param z Desired z location of the map to scroll to (world coordinate). Use \c -1 to scroll to the height of the map at the \a x, \a y location. * @param w %Window co

Source from the content-addressed store, hash-verified

2544 * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
2545 */
2546bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
2547{
2548 /* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
2549 if (z == -1) {
2550 if ( x >= 0 && x <= (int)Map::SizeX() * (int)TILE_SIZE - 1
2551 && y >= 0 && y <= (int)Map::SizeY() * (int)TILE_SIZE - 1) {
2552 z = GetSlopePixelZ(x, y);
2553 } else {
2554 z = TileHeightOutsideMap(x / (int)TILE_SIZE, y / (int)TILE_SIZE);
2555 }
2556 }
2557
2558 Point pt = MapXYZToViewport(*w->viewport, x, y, z);
2559 w->viewport->CancelFollow(*w);
2560
2561 if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false;
2562
2563 if (instant) {
2564 w->viewport->scrollpos_x = pt.x;
2565 w->viewport->scrollpos_y = pt.y;
2566 RebuildViewportOverlay(w);
2567 }
2568
2569 w->viewport->dest_scrollpos_x = pt.x;
2570 w->viewport->dest_scrollpos_y = pt.y;
2571 return true;
2572}
2573
2574/**
2575 * Scrolls the viewport in a window to a given location.

Callers 4

OnClickMethod · 0.85
ScrollMainWindowToFunction · 0.85
ScrollWindowToTileFunction · 0.85

Calls 5

GetSlopePixelZFunction · 0.85
TileHeightOutsideMapFunction · 0.85
MapXYZToViewportFunction · 0.85
RebuildViewportOverlayFunction · 0.85
CancelFollowMethod · 0.80

Tested by

no test coverage detected