OpenTTD Source: src/viewport_func.h File Reference

OpenTTD Source 15.0-RC2

Functions | Variables
viewport_func.h File Reference

Functions related to (drawing on) viewports. More...

`#include "gfx_type.h"`
`#include "sprite.h"`
`#include "viewport_type.h"`
`#include "window_type.h"`
`#include "tile_map.h"`
`#include "station_type.h"`
`#include "vehicle_type.h"`

Go to the source code of this file.

## Functions
void | SetSelectionRed (bool)
void | InitializeWindowViewport (Window *w, int x, int y, int width, int height, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
| Initialize viewport of the window for use.
Viewport * | IsPtInWindowViewport (const Window *w, int x, int y)
| Is a xy position inside the viewport of the window?
Point | TranslateXYToTileCoord (const Viewport &vp, int x, int y, bool clamp_to_map=true)
| Translate screen coordinate in a viewport to underlying tile coordinate.
Point | GetTileBelowCursor ()
void | UpdateViewportPosition (Window *w, uint32_t delta_ms)
| Update the viewport position being displayed.
bool | MarkAllViewportsDirty (int left, int top, int right, int bottom)
| Mark all viewports that display an area as dirty (in need of repaint).
bool | DoZoomInOutWindow (ZoomStateChange how, Window *w)
| Zooms a viewport in a window in or out.
void | ZoomInOrOutToCursorWindow (bool in, Window *w)
void | ConstrainAllViewportsZoom ()
Point | GetTileZoomCenterWindow (bool in, Window *w)
void | FixTitleGameZoom (int zoom_adjust=0)
void | HandleZoomMessage (Window *w, const Viewport &vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out)
| Update the status of the zoom-buttons according to the zoom-level of the viewport.
void | MaxZoomInOut (ZoomStateChange how, Window *w)
| Zoom a viewport as far as possible in the given direction.
void | OffsetGroundSprite (int x, int y)
| Called when a foundation has been drawn for the current tile.
void | DrawGroundSprite (SpriteID image, PaletteID pal, const SubSprite *sub=nullptr, int extra_offs_x=0, int extra_offs_y=0)
| Draws a ground sprite for the current tile.
void | DrawGroundSpriteAt (SpriteID image, PaletteID pal, int32_t x, int32_t y, int z, const SubSprite *sub=nullptr, int extra_offs_x=0, int extra_offs_y=0)
| Draws a ground sprite at a specific world-coordinate relative to the current tile.
void | AddSortableSpriteToDraw (SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent=false, const SubSprite *sub=nullptr)
| Draw a (transparent) sprite at given coordinates with a given bounding box.
void | AddChildSpriteScreen (SpriteID image, PaletteID pal, int x, int y, bool transparent=false, const SubSprite *sub=nullptr, bool scale=true, bool relative=true)
| Add a child sprite to a parent sprite.
std::string * | ViewportAddString (const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour)
| Add a string to draw in the current viewport.
void | AddSortableSpriteToDraw (SpriteID image, PaletteID pal, const Coord3D< int32_t > &world, const SpriteBounds &bounds, bool transparent=false, const SubSprite *sub=nullptr)
void | StartSpriteCombine ()
| Starts a block of sprites, which are "combined" into a single bounding box.
void | EndSpriteCombine ()
| Terminates a block of sprites started by StartSpriteCombine.
bool | HandleViewportClicked (const Viewport &vp, int x, int y)
void | SetRedErrorSquare (TileIndex tile)
| Set a tile to display a red error square.
void | SetTileSelectSize (int w, int h)
| Highlight w by h tiles at the cursor.
void | SetTileSelectBigSize (int ox, int oy, int sx, int sy)
void | ViewportDoDraw (const Viewport &vp, int left, int top, int right, int bottom)
bool | ScrollWindowToTile (TileIndex tile, Window *w, bool instant=false)
| Scrolls the viewport in a window to a given location.
bool | ScrollWindowTo (int x, int y, int z, Window *w, bool instant=false)
| Scrolls the viewport in a window to a given location.
void | RebuildViewportOverlay (Window *w)
bool | ScrollMainWindowToTile (TileIndex tile, bool instant=false)
| Scrolls the viewport of the main window to a given location.
bool | ScrollMainWindowTo (int x, int y, int z=-1, bool instant=false)
| Scrolls the main window to given coordinates.
void | UpdateAllVirtCoords ()
| Update the viewport coordinates of all signs.
void | ClearAllCachedNames ()
void | MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset, int tile_height_override)
| Mark a tile given by its index dirty for repaint.
void | MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset=0)
| Mark a tile given by its index dirty for repaint.
Point | GetViewportStationMiddle (const Viewport &vp, const Station *st)
void | SetViewportCatchmentStation (const Station *st, bool sel)
| Select or deselect station for coverage area highlight.
void | SetViewportStationRect (const Station *st, bool sel)
| Select or deselect station for rectangle area highlight.
void | SetViewportCatchmentWaypoint (const Waypoint *wp, bool sel)
| Select or deselect waypoint for coverage area highlight.
void | SetViewportWaypointRect (const Waypoint *wp, bool sel)
| Select or deselect waypoint for rectangle area highlight.
void | SetViewportCatchmentTown (const Town *t, bool sel)
| Select or deselect town for coverage area highlight.
void | MarkCatchmentTilesDirty ()
template<class T >
void | SetViewportCatchmentSpecializedStation (const T *st, bool sel)
template<>
void | SetViewportCatchmentSpecializedStation (const Station *st, bool sel)
template<>
void | SetViewportCatchmentSpecializedStation (const Waypoint *st, bool sel)

## Variables
static const int | TILE_HEIGHT_STEP = 50
| One Z unit tile height difference is displayed as 50m.
Point | _tile_fract_coords

## Detailed Description

Functions related to (drawing on) viewports.

Definition in file viewport_func.h.

## Function Documentation

## ◆ AddChildSpriteScreen()

void AddChildSpriteScreen | ( | SpriteID | image,
|  | PaletteID | pal,
|  | int | x,
|  | int | y,
|  | bool | transparent,
|  | const SubSprite * | sub,
|  | bool | scale,
|  | bool | relative
| ) |  |

Add a child sprite to a parent sprite.

Parameters

  image | the image to draw.
  pal | the provided palette.
  x | sprite x-offset (screen coordinates) relative to parent sprite.
  y | sprite y-offset (screen coordinates) relative to parent sprite.
  transparent | if true, switch the palette between the provided palette and the transparent palette,
  sub | Only draw a part of the sprite.
  scale | if true, scale offsets to base zoom level.
  relative | if true, draw sprite relative to parent sprite offsets.

Definition at line 824 of file viewport.cpp.

References LAST_CHILD_NONE, LAST_CHILD_PARENT, ViewportDrawer::last_foundation_child, MAX_SPRITES, ChildScreenSpriteToDraw::next, PALETTE_MODIFIER_TRANSPARENT, PALETTE_TO_TRANSPARENT, SetBit(), SPRITE_MASK, and ChildScreenSpriteToDraw::sub.

Referenced by AddChildSpriteToFoundation(), AddCombinedSprite(), and DrawCommonTileSeq().

## ◆ AddSortableSpriteToDraw() [1/2]

void AddSortableSpriteToDraw | ( | SpriteID | image,
|  | PaletteID | pal,
|  | const Coord3D< int32_t > & | world,
|  | const SpriteBounds & | bounds,
|  | bool | transparent = `false`,
|  | const SubSprite * | sub = `nullptr`
| ) |  |
| inline

Definition at line 59 of file viewport_func.h.

## ◆ AddSortableSpriteToDraw() [2/2]

void AddSortableSpriteToDraw | ( | SpriteID | image,
|  | PaletteID | pal,
|  | int | x,
|  | int | y,
|  | int | z,
|  | const SpriteBounds & | bounds,
|  | bool | transparent,
|  | const SubSprite * | sub
| ) |  |

Draw a (transparent) sprite at given coordinates with a given bounding box.

The bounding box extends from (x + bb_offset_x, y + bb_offset_y, z + bb_offset_z) to (x + w - 1, y + h - 1, z + dz - 1), both corners included. Bounding boxes with bb_offset_x == w or bb_offset_y == h or bb_offset_z == dz are allowed and produce thin slices.

Note
  Bounding boxes are normally specified with bb_offset_x = bb_offset_y = bb_offset_z = 0. The extent of the bounding box in negative direction is defined by the sprite offset in the grf file. However if modifying the sprite offsets is not suitable (e.g. when using existing graphics), the bounding box can be tuned by bb_offset.

Precondition
  w >= bb_offset_x, h >= bb_offset_y, dz >= bb_offset_z. Else w, h or dz are ignored.

Parameters

  image | the image to combine and draw,
  pal | the provided palette,
  x | position X (world) of the sprite,
  y | position Y (world) of the sprite,
  w | bounding box extent towards positive X (world),
  h | bounding box extent towards positive Y (world),
  dz | bounding box extent towards positive Z (world),
  z | position Z (world) of the sprite,
  transparent | if true, switch the palette between the provided palette and the transparent palette,
  bb_offset_x | bounding box extent towards negative X (world),
  bb_offset_y | bounding box extent towards negative Y (world),
  bb_offset_z | bounding box extent towards negative Z (world)
  sub | Only draw a part of the sprite.

Definition at line 663 of file viewport.cpp.

References AddCombinedSprite(), ViewportDrawer::combine_sprites, SpriteBounds::extent, ParentSpriteToDraw::first_child, Sprite::height, ParentSpriteToDraw::image, LAST_CHILD_NONE, LAST_CHILD_PARENT, ParentSpriteToDraw::left, MAX_SPRITES, Normal, SpriteBounds::offset, SpriteBounds::origin, ParentSpriteToDraw::pal, PALETTE_MODIFIER_TRANSPARENT, PALETTE_TO_TRANSPARENT, RemapCoords(), SetBit(), SPRITE_COMBINE_ACTIVE, SPRITE_COMBINE_PENDING, SPRITE_MASK, ParentSpriteToDraw::sub, ParentSpriteToDraw::top, Sprite::width, Coord2D< T >::x, Coord3D< T >::x, ParentSpriteToDraw::x, Sprite::x_offs, ParentSpriteToDraw::xmax, ParentSpriteToDraw::xmin, Coord2D< T >::y, Coord3D< T >::y, ParentSpriteToDraw::y, Sprite::y_offs, ParentSpriteToDraw::ymax, ParentSpriteToDraw::ymin, Coord3D< T >::z, ParentSpriteToDraw::zmax, and ParentSpriteToDraw::zmin.

Referenced by DoDrawVehicle(), DrawBridgeMiddle(), DrawBridgeRoadBits(), DrawCommonTileSeq(), DrawCustomStationFoundations(), DrawFoundation(), DrawPillar(), DrawRailCatenary(), DrawRailCatenaryOnBridge(), DrawRailCatenaryOnTunnel(), DrawRailCatenaryRailway(), DrawRoadDetail(), DrawRoadTypeCatenary(), DrawTile_Town(), DrawTile_TunnelBridge(), DrawTrackFence(), and DrawWaterTileStruct().

## ◆ ClearAllCachedNames()

void ClearAllCachedNames | ( |  | ) |

Definition at line 229 of file afterload.cpp.

## ◆ ConstrainAllViewportsZoom()

void ConstrainAllViewportsZoom | ( |  | ) |

Definition at line 2108 of file viewport.cpp.

## ◆ DoZoomInOutWindow()

bool DoZoomInOutWindow | ( | ZoomStateChange | how,
|  | Window * | w
| ) |  |

Zooms a viewport in a window in or out.

Parameters

  how | Zooming direction.
  w | Window owning the viewport.

Returns
  Returns `true` if zooming step could be done, `false` if further zooming is not possible.

Note
  No button handling or what so ever is done.

Definition at line 93 of file main_gui.cpp.

References _settings_client, ViewportData::dest_scrollpos_x, ViewportData::dest_scrollpos_y, ClientSettings::gui, Window::InvalidateData(), ViewportData::scrollpos_x, ViewportData::scrollpos_y, Window::viewport, Viewport::virtual_height, Viewport::virtual_width, Viewport::zoom, ZOOM_IN, GUISettings::zoom_max, GUISettings::zoom_min, ZOOM_NONE, and ZOOM_OUT.

Referenced by ConZoomToLevel(), MaxZoomInOut(), ExtraViewportWindow::OnClick(), IndustryViewWindow::OnMouseWheel(), MainWindow::OnMouseWheel(), TownViewWindow::OnMouseWheel(), and VehicleViewWindow::OnMouseWheel().

## ◆ DrawGroundSprite()

void DrawGroundSprite | ( | SpriteID | image,
|  | PaletteID | pal,
|  | const SubSprite * | sub,
|  | int | extra_offs_x,
|  | int | extra_offs_y
| ) |  |

Draws a ground sprite for the current tile.

If the current tile is drawn on top of a foundation the sprite is added as child sprite to the "foundation"-ParentSprite.

Parameters

  image | the image to draw.
  pal | the provided palette.
  sub | Only draw a part of the sprite.
  extra_offs_x | Pixel X offset for the sprite position.
  extra_offs_y | Pixel Y offset for the sprite position.

Definition at line 579 of file viewport.cpp.

References DrawGroundSpriteAt().

Referenced by DrawCommonTileSeq(), DrawRoadBits(), DrawRoadGroundSprites(), DrawRoadOverlays(), DrawSeaWater(), DrawTile_Road(), DrawTile_Town(), DrawTile_TunnelBridge(), DrawTileLayout(), DrawTrackBits(), DrawWaterLock(), and DrawWaterSprite().

## ◆ DrawGroundSpriteAt()

void DrawGroundSpriteAt | ( | SpriteID | image,
|  | PaletteID | pal,
|  | int32_t | x,
|  | int32_t | y,
|  | int | z,
|  | const SubSprite * | sub,
|  | int | extra_offs_x,
|  | int | extra_offs_y
| ) |  |

Draws a ground sprite at a specific world-coordinate relative to the current tile.

If the current tile is drawn on top of a foundation the sprite is added as child sprite to the "foundation"-ParentSprite.

Parameters

  image | the image to draw.
  pal | the provided palette.
  x | position x (world coordinates) of the sprite relative to current tile.
  y | position y (world coordinates) of the sprite relative to current tile.
  z | position z (world coordinates) of the sprite relative to current tile.
  sub | Only draw a part of the sprite.
  extra_offs_x | Pixel X offset for the sprite position.
  extra_offs_y | Pixel Y offset for the sprite position.

Definition at line 556 of file viewport.cpp.

References AddChildSpriteToFoundation(), AddTileSpriteToDraw(), ViewportDrawer::foundation, ViewportDrawer::foundation_part, FOUNDATION_PART_NONE, FOUNDATION_PART_NORMAL, RemapCoords(), Coord2D< T >::x, Coord3D< T >::x, Coord2D< T >::y, Coord3D< T >::y, and Coord3D< T >::z.

Referenced by DrawGroundSprite(), and DrawRoadBits().

## ◆ EndSpriteCombine()

void EndSpriteCombine | ( |  | ) |

Terminates a block of sprites started by StartSpriteCombine.

Take a look there for details.

Definition at line 774 of file viewport.cpp.

References ViewportDrawer::combine_sprites, and SPRITE_COMBINE_NONE.

Referenced by DoDrawVehicle(), DrawBridgeMiddle(), DrawBridgeRoadBits(), and DrawTile_TunnelBridge().

## ◆ FixTitleGameZoom()

void FixTitleGameZoom | ( | int | zoom_adjust = `0` | ) |

Definition at line 158 of file main_gui.cpp.

## ◆ GetTileBelowCursor()

Point GetTileBelowCursor | ( |  | ) |

Definition at line 456 of file viewport.cpp.

## ◆ GetTileZoomCenterWindow()

Point GetTileZoomCenterWindow | ( | bool | in,
|  | Window * | w
| ) |  |

Definition at line 462 of file viewport.cpp.

## ◆ GetViewportStationMiddle()

Point GetViewportStationMiddle | ( | const Viewport & | vp,
|  | const Station * | st
| ) |  |

Definition at line 3578 of file viewport.cpp.

## ◆ HandleViewportClicked()

bool HandleViewportClicked | ( | const Viewport & | vp,
|  | int | x,
|  | int | y
| ) |  |

Definition at line 2495 of file viewport.cpp.

## ◆ HandleZoomMessage()

void HandleZoomMessage | ( | Window * | w,
|  | const Viewport & | vp,
|  | WidgetID | widget_zoom_in,
|  | WidgetID | widget_zoom_out
| ) |  |

Update the status of the zoom-buttons according to the zoom-level of the viewport.

This will update their status and invalidate accordingly

Parameters

  w | Window pointer to the window that has the zoom buttons
  vp | pointer to the viewport whose zoom-level the buttons represent
  widget_zoom_in | widget index for window with zoom-in button
  widget_zoom_out | widget index for window with zoom-out button

Definition at line 486 of file viewport.cpp.

References _settings_client, ClientSettings::gui, Window::SetWidgetDirty(), Window::SetWidgetDisabledState(), Viewport::zoom, GUISettings::zoom_max, and GUISettings::zoom_min.

Referenced by MainToolbarWindow::OnInvalidateData(), ScenarioEditorToolbarWindow::OnInvalidateData(), and ExtraViewportWindow::OnInvalidateData().

## ◆ InitializeWindowViewport()

void InitializeWindowViewport | ( | Window * | w,
|  | int | x,
|  | int | y,
|  | int | width,
|  | int | height,
|  | std::variant< TileIndex, VehicleID > | focus,
|  | ZoomLevel | zoom
| ) |  |

Initialize viewport of the window for use.

Parameters

  w | Window to use/display the viewport in
  x | Offset of left edge of viewport with respect to left edge window w
  y | Offset of top edge of viewport with respect to top edge window w
  width | Width of the viewport
  height | Height of the viewport
  focus | Either the tile index or vehicle ID to focus.
  zoom | Zoomlevel to display

Definition at line 218 of file viewport.cpp.

References _settings_client, Clamp(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Get(), GetMainWindow(), GetSlopePixelZ(), ClientSettings::gui, INVALID_TILE, Window::left, ScaleByZoom(), TILE_SIZE, TileX(), TileY(), Window::top, Window::viewport, Coord2D< T >::x, Vehicle::x_pos, Coord2D< T >::y, Vehicle::y_pos, Vehicle::z_pos, GUISettings::zoom_max, and GUISettings::zoom_min.

Referenced by NWidgetViewport::InitializeViewport().

## ◆ IsPtInWindowViewport()

Viewport * IsPtInWindowViewport | ( | const Window * | w,
|  | int | x,
|  | int | y
| ) |  |

Is a xy position inside the viewport of the window?

Parameters

  w | Window to examine its viewport
  x | X coordinate of the xy position
  y | Y coordinate of the xy position

Returns
  Pointer to the viewport if the xy position is in the viewport of the window, otherwise `nullptr` is returned.

Definition at line 408 of file viewport.cpp.

References Viewport::height, IsInsideMM(), Viewport::left, Viewport::top, Window::viewport, and Viewport::width.

Referenced by HandleAutoscroll(), and TooltipsWindow::OnMouseLoop().

## ◆ MarkCatchmentTilesDirty()

void MarkCatchmentTilesDirty | ( |  | ) |

Definition at line 3647 of file viewport.cpp.

## ◆ MaxZoomInOut()

void MaxZoomInOut | ( | ZoomStateChange | how,
|  | Window * | w
| ) |  |
| inline

Zoom a viewport as far as possible in the given direction.

Parameters

  how | Zooming direction.
  w | Window owning the viewport.

Precondition
  how should not be ZOOM_NONE.

Definition at line 46 of file viewport_func.h.

References DoZoomInOutWindow().

Referenced by MainWindow::OnHotkey().

## ◆ OffsetGroundSprite()

void OffsetGroundSprite | ( | int | x,
|  | int | y
| ) |  |

Called when a foundation has been drawn for the current tile.

Successive ground sprites for the current tile will be drawn as child sprites of the "foundation"-ParentSprite, not as TileSprites.

Parameters

  x | sprite x-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.
  y | sprite y-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.

Definition at line 591 of file viewport.cpp.

References ViewportDrawer::foundation, ViewportDrawer::foundation_offset, ViewportDrawer::foundation_part, FOUNDATION_PART_HALFTILE, FOUNDATION_PART_NONE, FOUNDATION_PART_NORMAL, LAST_CHILD_NONE, ViewportDrawer::last_foundation_child, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by DrawFoundation().

## ◆ RebuildViewportOverlay()

void RebuildViewportOverlay | ( | Window * | w | ) |

Definition at line 2527 of file viewport.cpp.

## ◆ ScrollMainWindowTo()

bool ScrollMainWindowTo | ( | int | x,
|  | int | y,
|  | int | z,
|  | bool | instant
| ) |  |

Scrolls the main window to given coordinates.

Parameters

  x | x coordinate
  y | y coordinate
  z | z coordinate; -1 to scroll to terrain height
  instant | scroll instantly (meaningful only when smooth_scrolling is active)

Returns
  did the viewport position change?

Definition at line 2078 of file smallmap_gui.cpp.

References FindWindowById(), GetMainWindow(), ScrollWindowTo(), SmallMapWindow::SmallMapCenterOnCurrentPos(), and WC_SMALLMAP.

Referenced by HandleViewportScroll(), NewsWindow::OnClick(), VehicleViewWindow::OnClick(), MainWindow::OnHotkey(), and ScrollMainWindowToTile().

## ◆ ScrollMainWindowToTile()

bool ScrollMainWindowToTile | ( | TileIndex | tile,
|  | bool | instant
| ) |  |

Scrolls the viewport of the main window to a given location.

Parameters

  tile | Desired tile to center on.
  instant | Jump to the location instead of slowly moving to it.

Returns
  Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).

Definition at line 2592 of file viewport.cpp.

References ScrollMainWindowTo(), TILE_SIZE, TileX(), and TileY().

Referenced by CmdScrollViewport(), ConScrollToTile(), StationViewWindow::DrawEntries(), GenerateWorld(), GoalListWindow::HandleClick(), CompanyWindow::OnClick(), DepotWindow::OnClick(), IndustryViewWindow::OnClick(), IndustryDirectoryWindow::OnClick(), LandInfoWindow::OnClick(), NewsWindow::OnClick(), OrdersWindow::OnClick(), SignListWindow::OnClick(), SignWindow::OnClick(), CompanyStationsWindow::OnClick(), StationViewWindow::OnClick(), TownViewWindow::OnClick(), TownDirectoryWindow::OnClick(), VehicleViewWindow::OnClick(), WaypointWindow::OnClick(), and StoryBookWindow::OnPageElementClick().

## ◆ ScrollWindowTo()

bool ScrollWindowTo | ( | int | x,
|  | int | y,
|  | int | z,
|  | Window * | w,
|  | bool | instant
| ) |  |

Scrolls the viewport in a window to a given location.

Parameters

  x | Desired x location of the map to scroll to (world coordinate).
  y | Desired y location of the map to scroll to (world coordinate).
  z | Desired z location of the map to scroll to (world coordinate). Use `-1` to scroll to the height of the map at the x, y location.
  w | Window containing the viewport.
  instant | Jump to the location instead of slowly moving to it.

Returns
  Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).

Definition at line 2546 of file viewport.cpp.

References GetSlopePixelZ(), Map::SizeX(), Map::SizeY(), TILE_SIZE, TileHeightOutsideMap(), Window::viewport, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by SmallMapWindow::OnClick(), ScrollMainWindowTo(), and ScrollWindowToTile().

## ◆ ScrollWindowToTile()

bool ScrollWindowToTile | ( | TileIndex | tile,
|  | Window * | w,
|  | bool | instant
| ) |  |

Scrolls the viewport in a window to a given location.

Parameters

  tile | Desired tile to center on.
  w | Window containing the viewport.
  instant | Jump to the location instead of slowly moving to it.

Returns
  Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).

Definition at line 2581 of file viewport.cpp.

References ScrollWindowTo(), TILE_SIZE, TileX(), and TileY().

Referenced by WaypointWindow::OnInvalidateData(), IndustryViewWindow::OnResize(), NewsWindow::OnResize(), TownViewWindow::OnResize(), and WaypointWindow::OnResize().

## ◆ SetRedErrorSquare()

void SetRedErrorSquare | ( | TileIndex | tile | ) |

Set a tile to display a red error square.

Parameters

  tile | Tile that should show the red error square.

Definition at line 2601 of file viewport.cpp.

References INVALID_TILE, MarkTileDirtyByTile(), and TileHighlightData::redsq.

Referenced by CcBuildRailTunnel(), CcBuildRoadTunnel(), and ErrmsgWindow::Close().

## ◆ SetSelectionRed()

void SetSelectionRed | ( | bool | b | ) |

Definition at line 2256 of file viewport.cpp.

## ◆ SetTileSelectBigSize()

void SetTileSelectBigSize | ( | int | ox,
|  | int | oy,
|  | int | sx,
|  | int | sy
| ) |  |

Definition at line 2627 of file viewport.cpp.

## ◆ SetTileSelectSize()

void SetTileSelectSize | ( | int | w,
|  | int | h
| ) |  |

Highlight w by h tiles at the cursor.

Parameters

  w | Width of the highlighted tiles rectangle.
  h | Height of the highlighted tiles rectangle.

Definition at line 2619 of file viewport.cpp.

References TileHighlightData::new_outersize, TileHighlightData::new_size, TILE_SIZE, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by BuildRailClick_Remove(), CompanyWindow::OnClick(), BuildDocksStationWindow::OnPaint(), BuildRailStationWindow::OnPaint(), BuildRoadStationWindow::OnPaint(), ScenarioEditorLandscapeGenerationWindow::OnPaint(), SetObjectToPlace(), and VpHandlePlaceSizingDrag().

## ◆ SetViewportCatchmentSpecializedStation() [1/2]

template<>

void SetViewportCatchmentSpecializedStation | ( | const Station * | st,
|  | bool | sel
| ) |  |
| inline

Definition at line 117 of file viewport_func.h.

## ◆ SetViewportCatchmentSpecializedStation() [2/2]

template<>

void SetViewportCatchmentSpecializedStation | ( | const Waypoint * | st,
|  | bool | sel
| ) |  |
| inline

Definition at line 123 of file viewport_func.h.

## ◆ SetViewportCatchmentStation()

void SetViewportCatchmentStation | ( | const Station * | st,
|  | bool | sel
| ) |  |

Select or deselect station for coverage area highlight.

Selecting a station will deselect a town.

Parameters

  *st | Station in question
  sel | Select or deselect given station

Definition at line 3713 of file viewport.cpp.

References _viewport_highlight_station, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, SetWindowDirty(), and WC_STATION_VIEW.

Referenced by BuildAirToolbarWindow::Close(), BuildDocksToolbarWindow::Close(), BuildRailToolbarWindow::Close(), BuildRoadToolbarWindow::Close(), StationViewWindow::Close(), BuildAirportWindow::OnClick(), BuildDocksStationWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildRoadStationWindow::OnClick(), StationViewWindow::OnClick(), BuildAirToolbarWindow::OnPlaceObjectAbort(), BuildDocksToolbarWindow::OnPlaceObjectAbort(), BuildRailToolbarWindow::OnPlaceObjectAbort(), and BuildRoadToolbarWindow::OnPlaceObjectAbort().

## ◆ SetViewportCatchmentTown()

void SetViewportCatchmentTown | ( | const Town * | t,
|  | bool | sel
| ) |  |

Select or deselect town for coverage area highlight.

Selecting a town will deselect a station.

Parameters

  *t | Town in question
  sel | Select or deselect given town

Definition at line 3805 of file viewport.cpp.

References _viewport_highlight_town, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, MarkWholeScreenDirty(), SetWindowDirty(), and WC_TOWN_VIEW.

Referenced by TownViewWindow::Close(), and TownViewWindow::OnClick().

## ◆ SetViewportCatchmentWaypoint()

void SetViewportCatchmentWaypoint | ( | const Waypoint * | wp,
|  | bool | sel
| ) |  |

Select or deselect waypoint for coverage area highlight.

Selecting a waypoint will deselect a town.

Parameters

  *wp | Waypoint in question
  sel | Select or deselect given waypoint

Definition at line 3759 of file viewport.cpp.

References _viewport_highlight_waypoint, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, SetWindowDirty(), and WC_WAYPOINT_VIEW.

Referenced by CcMoveWaypointName(), BuildRailToolbarWindow::Close(), WaypointWindow::Close(), WaypointWindow::OnClick(), and BuildRailToolbarWindow::OnPlaceObjectAbort().

## ◆ SetViewportStationRect()

void SetViewportStationRect | ( | const Station * | st,
|  | bool | sel
| ) |  |

Select or deselect station for rectangle area highlight.

Selecting a station will deselect a town.

Parameters

  *st | Station in question
  sel | Select or deselect given station

Definition at line 3736 of file viewport.cpp.

References _viewport_highlight_station_rect, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, SetWindowDirty(), and WC_STATION_VIEW.

Referenced by CcMoveStationName(), QueryStringWindow::Close(), QueryStringWindow::OnClick(), StationViewWindow::OnClick(), WaypointWindow::OnClick(), and QueryStringWindow::OnPlaceObjectAbort().

## ◆ SetViewportWaypointRect()

void SetViewportWaypointRect | ( | const Waypoint * | wp,
|  | bool | sel
| ) |  |

Select or deselect waypoint for rectangle area highlight.

Selecting a waypoint will deselect a town.

Parameters

  *wp | Waypoint in question
  sel | Select or deselect given waypoint

Definition at line 3782 of file viewport.cpp.

References _viewport_highlight_waypoint_rect, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, SetWindowDirty(), and WC_WAYPOINT_VIEW.

Referenced by QueryStringWindow::Close(), QueryStringWindow::OnClick(), StationViewWindow::OnClick(), WaypointWindow::OnClick(), and QueryStringWindow::OnPlaceObjectAbort().

## ◆ StartSpriteCombine()

void StartSpriteCombine | ( |  | ) |

Starts a block of sprites, which are "combined" into a single bounding box.

Subsequent calls to AddSortableSpriteToDraw will be drawn into the same bounding box. That is: The first sprite that is not clipped by the viewport defines the bounding box, and the following sprites will be child sprites to that one.

That implies:

- The drawing order is definite. No other sprites will be sorted between those of the block.
- You have to provide a valid bounding box for all sprites, as you won't know which one is the first non-clipped one. Preferable you use the same bounding box for all.
- You cannot use AddChildSpriteScreen inside the block, as its result will be indefinite.

The block is terminated by EndSpriteCombine.

You cannot nest "combined" blocks.

Definition at line 764 of file viewport.cpp.

References ViewportDrawer::combine_sprites, SPRITE_COMBINE_NONE, and SPRITE_COMBINE_PENDING.

Referenced by DoDrawVehicle(), DrawBridgeMiddle(), DrawBridgeRoadBits(), and DrawTile_TunnelBridge().

## ◆ TranslateXYToTileCoord()

Point TranslateXYToTileCoord | ( | const Viewport & | vp,
|  | int | x,
|  | int | y,
|  | bool | clamp_to_map
| ) |  |

Translate screen coordinate in a viewport to underlying tile coordinate.

Returns exact point of the map that is visible in the given place of the viewport (3D perspective), height of tiles and foundations matter.

Parameters

  vp | Viewport that contains the (x, y) screen coordinate
  x | Screen x coordinate, distance in pixels from the left edge of viewport frame
  y | Screen y coordinate, distance in pixels from the top edge of viewport frame
  clamp_to_map | Clamp the coordinate outside of the map to the closest, non-void tile within the map

Returns
  Tile coordinate or (-1, -1) if given x or y is not within viewport frame

Definition at line 430 of file viewport.cpp.

References Viewport::height, InverseRemapCoords2(), IsInsideBS(), Viewport::left, ScaleByZoom(), Viewport::top, Viewport::virtual_left, Viewport::virtual_top, Viewport::width, and Viewport::zoom.

## ◆ UpdateAllVirtCoords()

void UpdateAllVirtCoords | ( |  | ) |

Update the viewport coordinates of all signs.

Definition at line 220 of file afterload.cpp.

References UpdateAllSignVirtCoords(), UpdateAllStationVirtCoords(), and UpdateAllTownVirtCoords().

Referenced by AdjustGUIZoom(), InitializeWindowsAndCaches(), GameOptionsWindow::OnClick(), GameOptionsWindow::OnDropdownSelect(), and MainWindow::OnHotkey().

## ◆ UpdateViewportPosition()

void UpdateViewportPosition | ( | Window * | w,
|  | uint32_t | delta_ms
| ) |  |

Update the viewport position being displayed.

Parameters

  w | Window owning the viewport.
  delta_ms | Milliseconds since the last update.

Definition at line 1988 of file viewport.cpp.

References _settings_client, abs(), ClampSmoothScroll(), ClampViewportToMap(), ViewportData::dest_scrollpos_x, ViewportData::dest_scrollpos_y, ViewportData::follow_vehicle, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Get(), ClientSettings::gui, ViewportData::scrollpos_x, ViewportData::scrollpos_y, GUISettings::smooth_scroll, Window::viewport, Coord2D< T >::x, Vehicle::x_pos, Coord2D< T >::y, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by SelectGameWindow::OnRealtimeTick(), and UpdateWindows().

## ◆ ViewportAddString()

std::string * ViewportAddString | ( | const DrawPixelInfo * | dpi,
|  | const ViewportSign * | sign,
|  | ViewportStringFlags | flags,
|  | Colours | colour
| ) |  |

Add a string to draw in the current viewport.

Parameters

  dpi | current viewport area
  sign | sign position and dimension
  flags | ViewportStringFlags to control the string's appearance.
  colour | colour of the sign background; or INVALID_COLOUR if transparent

Returns
  Pointer to std::string to filled with sign, or nullptr if string would be outside the viewport bounds.

Definition at line 1330 of file viewport.cpp.

References AddStringToDraw(), ViewportSign::center, FS_NORMAL, FS_SMALL, GetCharacterHeight(), ScaleByZoom(), WidgetDimensions::scaled, Small, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), ViewportSign::top, ViewportSign::width_normal, and ViewportSign::width_small.

Referenced by ViewportAddSignStrings(), ViewportAddStationStrings(), and ViewportAddTownStrings().

## ◆ ViewportDoDraw()

void ViewportDoDraw | ( | const Viewport & | vp,
|  | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom
| ) |  |

Definition at line 1811 of file viewport.cpp.

## ◆ ZoomInOrOutToCursorWindow()

void ZoomInOrOutToCursorWindow | ( | bool | in,
|  | Window * | w
| ) |  |

Definition at line 142 of file main_gui.cpp.

## Variable Documentation

## ◆ _tile_fract_coords

Point _tile_fract_coords
| extern

Definition at line 104 of file viewport.cpp.

## ◆ TILE_HEIGHT_STEP

const int TILE_HEIGHT_STEP = 50
| static

One Z unit tile height difference is displayed as 50m.

Definition at line 21 of file viewport_func.h.

Referenced by CalcHeightdiff(), DoBuildLock(), SmallMapWindow::DrawWidget(), IsStationBridgeAboveOk(), and SmallMapWindow::OnInit().