# viewport.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "debug.h"`
`#include "tile_cmd.h"`
`#include "gui.h"`
`#include "spritecache.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "station.h"`
`#include "town.h"`
`#include "signs.h"`
`#include "waypoint.h"`
`#include "variables.h"`
`#include "train.h"`
`#include "roadveh.h"`
`#include "vehicle_gui.h"`
`#include "blitter/factory.hpp"`
`#include "transparency.h"`
`#include "strings_func.h"`
`#include "zoom_func.h"`
`#include "vehicle_func.h"`
`#include "player_func.h"`
`#include "settings_type.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`
`#include "table/autorail.h"`
`#include "table/animcursors.h"`

Go to the source code of this file.

## Data Structures
struct | StringSpriteToDraw
struct | TileSpriteToDraw
struct | ChildScreenSpriteToDraw
struct | ParentSpriteToDraw
struct | ViewportDrawer
## Defines
#define | VIEWPORT_DRAW_MEM (65536 * 2)
#define | LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
## Typedefs
typedef void | OnVehicleClickProc (const Vehicle *v)
## Enumerations
enum | FoundationPart { FOUNDATION_PART_NONE = 0xFF, FOUNDATION_PART_NORMAL = 0, FOUNDATION_PART_HALFTILE = 1, FOUNDATION_PART_END }
## Functions
| assert_compile (lengthof(_viewports)< sizeof(_active_viewports)*8)
| assert_compile (sizeof(LARGEST_SPRITELIST_STRUCT) >=sizeof(StringSpriteToDraw))
| assert_compile (sizeof(LARGEST_SPRITELIST_STRUCT) >=sizeof(TileSpriteToDraw))
| assert_compile (sizeof(LARGEST_SPRITELIST_STRUCT) >=sizeof(ChildScreenSpriteToDraw))
| assert_compile (sizeof(LARGEST_SPRITELIST_STRUCT) >=sizeof(ParentSpriteToDraw))
void | SmallMapCenterOnCurrentPos (Window *w)
static Point | MapXYZToViewport (const ViewPort *vp, uint x, uint y, uint z)
void | InitViewports ()
void | DeleteWindowViewport (Window *w)
void | AssignWindowViewport (Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom)
static void | DoSetViewportPosition (Window *const *wz, int left, int top, int width, int height)
static void | SetViewportPosition (Window *w, int x, int y)
ViewPort * | IsPtInWindowViewport (const Window *w, int x, int y)
static Point | TranslateXYToTileCoord (const ViewPort *vp, int x, int y)
static Point | GetTileFromScreenXY (int x, int y, int zoom_x, int zoom_y)
Point | GetTileBelowCursor ()
Point | GetTileZoomCenterWindow (bool in, Window *w)
void | HandleZoomMessage (Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
| Update the status of the zoom-buttons according to the zoom-level of the viewport.
void | DrawGroundSpriteAt (SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub)
| Draws a ground sprite at a specific world-coordinate.
static void | AddChildSpriteToFoundation (SpriteID image, SpriteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y)
| Adds a child sprite to the active foundation.
void | DrawGroundSprite (SpriteID image, SpriteID pal, const SubSprite *sub)
| Draws a ground sprite for the current tile.
void | OffsetGroundSprite (int x, int y)
| Called when a foundation has been drawn for the current tile.
static void | AddCombinedSprite (SpriteID image, SpriteID pal, int x, int y, byte z, const SubSprite *sub)
| Adds a child sprite to a parent sprite.
void | AddSortableSpriteToDraw (SpriteID image, SpriteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
| Draw a (transparent) sprite at given coordinates with a given bounding box.
void | StartSpriteCombine ()
void | EndSpriteCombine ()
void | AddChildSpriteScreen (SpriteID image, SpriteID pal, int x, int y, bool transparent, const SubSprite *sub)
| Add a child sprite to a parent sprite.
void * | AddStringToDraw (int x, int y, StringID string, uint64 params_1, uint64 params_2)
static void | DrawSelectionSprite (SpriteID image, SpriteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part)
| Draws sprites between ground sprite and everything above.
static void | DrawTileSelectionRect (const TileInfo *ti, SpriteID pal)
| Draws a selection rectangle on a tile.
static bool | IsPartOfAutoLine (int px, int py)
static void | DrawAutorailSelection (const TileInfo *ti, uint autorail_type)
| Draws autorail highlights.
static void | DrawTileSelection (const TileInfo *ti)
| Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
static void | ViewportAddLandscape ()
static void | ViewportAddTownNames (DrawPixelInfo *dpi)
static void | AddStation (const Station *st, StringID str, uint16 width)
static void | ViewportAddStationNames (DrawPixelInfo *dpi)
static void | AddSign (const Sign *si, StringID str, uint16 width)
static void | ViewportAddSigns (DrawPixelInfo *dpi)
static void | AddWaypoint (const Waypoint *wp, StringID str, uint16 width)
static void | ViewportAddWaypoints (DrawPixelInfo *dpi)
void | UpdateViewportSignPos (ViewportSign *sign, int left, int top, StringID str)
static void | ViewportDrawTileSprites (TileSpriteToDraw *ts)
static void | ViewportSortParentSprites (ParentSpriteToDraw *psd[])
static void | ViewportDrawParentSprites (ParentSpriteToDraw *psd[])
static void | ViewportDrawBoundingBoxes (ParentSpriteToDraw *psd[])
| Draws the bounding boxes of all ParentSprites.
static void | ViewportDrawStrings (DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
void | ViewportDoDraw (const ViewPort *vp, int left, int top, int right, int bottom)
static void | ViewportDrawChk (const ViewPort *vp, int left, int top, int right, int bottom)
| Make sure we don't draw a too big area at a time.
static void | ViewportDraw (const ViewPort *vp, int left, int top, int right, int bottom)
void | DrawWindowViewport (const Window *w)
static void | ClampViewportToMap (const ViewPort *vp, int &x, int &y)
void | UpdateViewportPosition (Window *w)
static void | MarkViewportDirty (const ViewPort *vp, int left, int top, int right, int bottom)
| Marks a viewport as dirty for repaint.
void | MarkAllViewportsDirty (int left, int top, int right, int bottom)
| Mark all viewports dirty for repaint.
void | MarkTileDirtyByTile (TileIndex tile)
| Mark a tile given by its index dirty for repaint.
void | MarkTileDirty (int x, int y)
| Mark a tile given by its coordinate dirty for repaint.
static void | SetSelectionTilesDirty ()
| Marks the selected tiles as dirty.
void | SetSelectionRed (bool b)
static bool | CheckClickOnTown (const ViewPort *vp, int x, int y)
static bool | CheckClickOnStation (const ViewPort *vp, int x, int y)
static bool | CheckClickOnSign (const ViewPort *vp, int x, int y)
static bool | CheckClickOnWaypoint (const ViewPort *vp, int x, int y)
static void | CheckClickOnLandscape (const ViewPort *vp, int x, int y)
static void | SafeShowTrainViewWindow (const Vehicle *v)
static void | SafeShowRoadVehViewWindow (const Vehicle *v)
static void | Nop (const Vehicle *v)
void | HandleViewportClicked (const ViewPort *vp, int x, int y)
Vehicle * | CheckMouseOverVehicle ()
void | PlaceObject ()
bool | ScrollWindowTo (int x, int y, Window *w, bool instant)
bool | ScrollMainWindowTo (int x, int y, bool instant)
bool | ScrollMainWindowToTile (TileIndex tile, bool instant)
void | SetRedErrorSquare (TileIndex tile)
void | SetTileSelectSize (int w, int h)
void | SetTileSelectBigSize (int ox, int oy, int sx, int sy)
static HighLightStyle | GetAutorailHT (int x, int y)
| returns the best autorail highlight type from map coordinates
void | UpdateTileSelection ()
| Updates tile highlighting for all cases.
void | VpStartPlaceSizing (TileIndex tile, ViewportPlaceMethod method, byte process)
| highlighting tiles while only going over them with the mouse
void | VpSetPlaceSizingLimit (int limit)
void | VpSetPresizeRange (TileIndex from, TileIndex to)
| Highlights all tiles between a set of two tiles.
static void | VpStartPreSizing ()
static HighLightStyle | Check2x1AutoRail (int mode)
| returns information about the 2x1 piece to be build.
static bool | SwapDirection (HighLightStyle style, TileIndex start_tile, TileIndex end_tile)
| Check if the direction of start and end tile should be swapped based on the dragging-style.
static int | CalcHeightdiff (HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile)
| Calculates height difference between one tile and another Multiplies the result to suit the standard given by minimap - 50 meters high To correctly get the height difference we need the direction we are dragging in, as well as with what kind of tool we are dragging.
static void | CalcRaildirsDrawstyle (TileHighlightData *thd, int x, int y, int method)
| while dragging
void | VpSelectTilesWithMethod (int x, int y, ViewportPlaceMethod method)
| Selects tiles while dragging.
bool | VpHandlePlaceSizingDrag ()
| while dragging
void | SetObjectToPlaceWnd (CursorID icon, SpriteID pal, ViewportHighlightMode mode, Window *w)
void | SetObjectToPlace (CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num)
void | ResetObjectToPlace ()
## Variables
PlaceProc * | _place_proc
Point | _tile_fract_coords
ZoomLevel | _saved_scrollpos_zoom
static ViewPort | _viewports [MAX_NUMBER_OF_WINDOWS-1]
| The maximum number of viewports depends on the maximum number of windows.
static uint32 | _active_viewports
| bitmasked variable where each bit signifies if a viewport is in use or not
static ViewportDrawer * | _cur_vd
TileHighlightData | _thd
static TileInfo * | _cur_ti
static Point | _vp_move_offs
static const HighLightStyle | _autorail_type [6][2]
static OnVehicleClickProc *const | _on_vehicle_click_proc []
static const StringID | measure_strings_length [] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF}

## Detailed Description

Definition in file viewport.cpp.

## Enumeration Type Documentation

enum FoundationPart

Enumerator:

  FOUNDATION_PART_NONE | Neither foundation nor groundsprite drawn yet.
  FOUNDATION_PART_NORMAL | First part (normal foundation or no foundation).
  FOUNDATION_PART_HALFTILE | Second part (halftile foundation).

Definition at line 131 of file viewport.cpp.

## Function Documentation

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

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.

Definition at line 752 of file viewport.cpp.

References MAX_SPRITES, PALETTE_MODIFIER_TRANSPARENT, SetBit(), and SPRITE_MASK.

Referenced by AddChildSpriteToFoundation(), and AddCombinedSprite().

static void AddChildSpriteToFoundation | ( | SpriteID | image,
|  | SpriteID | pal,
|  | const SubSprite * | sub,
|  | FoundationPart | foundation_part,
|  | int | extra_offs_x,
|  | int | extra_offs_y |
| ) |  |  | `[static]`

Adds a child sprite to the active foundation.

The pixel offset of the sprite relative to the ParentSprite is the sum of the offset passed to OffsetGroundSprite() and extra_offs_?.

Parameters:

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

Definition at line 518 of file viewport.cpp.

References AddChildSpriteScreen(), and IsInsideMM().

Referenced by DrawGroundSprite(), and DrawSelectionSprite().

static void AddCombinedSprite | ( | SpriteID | image,
|  | SpriteID | pal,
|  | int | x,
|  | int | y,
|  | byte | z,
|  | const SubSprite * | sub |
| ) |  |  | `[static]`

Adds a child sprite to a parent sprite.

In contrast to "AddChildSpriteScreen()" the sprite position is in world coordinates

Parameters:

  | image | the image to draw.
  | pal | the provided palette.
  | x | position x of the sprite.
  | y | position y of the sprite.
  | z | position z of the sprite.
  | sub | Only draw a part of the sprite.

Definition at line 597 of file viewport.cpp.

References AddChildSpriteScreen(), and SPRITE_MASK.

Referenced by AddSortableSpriteToDraw().

void AddSortableSpriteToDraw | ( | SpriteID | image,
|  | SpriteID | pal,
|  | int | x,
|  | int | y,
|  | int | w,
|  | int | h,
|  | int | dz,
|  | int | z,
|  | bool | transparent,
|  | int | bb_offset_x,
|  | int | bb_offset_y,
|  | int | bb_offset_z,
|  | 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 636 of file viewport.cpp.

References AddCombinedSprite(), max(), MAX_SPRITES, min(), PALETTE_MODIFIER_TRANSPARENT, SetBit(), and SPRITE_MASK.

Referenced by DrawBridgePillars(), DrawBridgeTramBits(), DrawCatenary(), DrawCatenaryOnTunnel(), DrawCatenaryRailway(), DrawRoadDetail(), DrawTile_Town(), DrawTile_TunnelBridge(), DrawTrackFence_NS_1(), DrawTrackFence_NS_2(), DrawTrackFence_WE_1(), DrawTrackFence_WE_2(), and DrawTramCatenary().

static int CalcHeightdiff | ( | HighLightStyle | style,
|  | uint | distance,
|  | TileIndex | start_tile,
|  | TileIndex | end_tile |
| ) |  |  | `[static]`

Calculates height difference between one tile and another Multiplies the result to suit the standard given by minimap - 50 meters high To correctly get the height difference we need the direction we are dragging in, as well as with what kind of tool we are dragging.

For example a horizontal autorail tool that starts in bottom and ends at the top of a tile will need the maximum of SW, S and SE, N corners respectively. This is handled by the lookup table below See _tileoffs_by_dir in map.c for the direction enums if you can't figure out the values yourself.

Parameters:

  | style | HightlightStyle of drag. This includes direction and style (autorail, rect, etc.)
  | distance | amount of tiles dragged, important for horizontal/vertical drags ignored for others
  | start_tile,end_tile | start and end tile of drag operation

Returns:
  height difference between two tiles. Tile measurement tool utilizes this value in its tooltips

Definition at line 2459 of file viewport.cpp.

References HT_DIR_HL, HT_DIR_HU, HT_DIR_MASK, HT_DIR_VL, HT_DIR_VR, HT_DIR_X, HT_DIR_Y, HT_DRAG_MASK, max(), Swap(), SwapDirection(), TILE_ADD, TileHeight(), TileX(), and ToTileIndexDiff().

Referenced by CalcRaildirsDrawstyle(), and VpSelectTilesWithMethod().

static HighLightStyle Check2x1AutoRail | ( | int | mode | ) | `[static]`

returns information about the 2x1 piece to be build.

The lower bits (0-3) are the track type.

Definition at line 2384 of file viewport.cpp.

References HT_DIR_HL, HT_DIR_HU, HT_DIR_VL, HT_DIR_VR, HT_DIR_X, and HT_DIR_Y.

Referenced by CalcRaildirsDrawstyle().

static void DrawAutorailSelection | ( | const TileInfo * | ti,
|  | uint | autorail_type |
| ) |  |  | `[static]`

Draws autorail highlights.

Parameters:

  | *ti | TileInfo Tile that is being drawn
  | autorail_type | Offset into _AutorailTilehSprite[][]

Definition at line 907 of file viewport.cpp.

References DrawSelectionSprite(), FOUNDATION_PART_HALFTILE, FOUNDATION_PART_NORMAL, GetHalftileSlopeCorner(), IsHalftileSlope(), OppositeCorner(), PALETTE_SEL_TILE_RED, RemoveHalftileSlope(), and SlopeWithThreeCornersRaised().

Referenced by DrawTileSelection().

void DrawGroundSprite | ( | SpriteID | image,
|  | SpriteID | pal,
|  | const SubSprite * | sub |
| ) |  |  |

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.

Definition at line 543 of file viewport.cpp.

References AddChildSpriteToFoundation(), DrawGroundSpriteAt(), FOUNDATION_PART_NONE, and FOUNDATION_PART_NORMAL.

Referenced by DrawCanalWater(), DrawRoadBits(), DrawSeaWater(), DrawTile_Town(), DrawTile_TunnelBridge(), and DrawTrackBits().

void DrawGroundSpriteAt | ( | SpriteID | image,
|  | SpriteID | pal,
|  | int32 | x,
|  | int32 | y,
|  | byte | z,
|  | const SubSprite * | sub |
| ) |  |  |

Draws a ground sprite at a specific world-coordinate.

Parameters:

  | image | the image to draw.
  | pal | the provided palette.
  | x | position x of the sprite.
  | y | position y of the sprite.
  | z | position z of the sprite.
  | sub | Only draw a part of the sprite.

Definition at line 480 of file viewport.cpp.

References MAX_SPRITES, and SPRITE_MASK.

Referenced by DrawGroundSprite(), and DrawSelectionSprite().

static void DrawSelectionSprite | ( | SpriteID | image,
|  | SpriteID | pal,
|  | const TileInfo * | ti,
|  | int | z_offset,
|  | FoundationPart | foundation_part |
| ) |  |  | `[static]`

Draws sprites between ground sprite and everything above.

The sprite is either drawn as TileSprite or as ChildSprite of the active foundation.

Parameters:

  | image | the image to draw.
  | pal | the provided palette.
  | ti | TileInfo Tile that is being drawn
  | z_offset | Z offset relative to the groundsprite. Only used for the sprite position, not for sprite sorting.
  | foundation_part | Foundation part the sprite belongs to.

Definition at line 831 of file viewport.cpp.

References AddChildSpriteToFoundation(), and DrawGroundSpriteAt().

Referenced by DrawAutorailSelection(), DrawTileSelection(), and DrawTileSelectionRect().

static void DrawTileSelection | ( | const TileInfo * | ti | ) | `[static]`

Checks if the specified tile is selected and if so draws selection using correct selectionstyle.

Parameters:

  | *ti | TileInfo Tile that is being drawn

Definition at line 941 of file viewport.cpp.

References Delta(), DrawAutorailSelection(), DrawSelectionSprite(), DrawTileSelectionRect(), FOUNDATION_PART_HALFTILE, FOUNDATION_PART_NORMAL, GetHalftileSlopeCorner(), HT_RAIL, IsHalftileSlope(), IsInsideBS(), IsSteepSlope(), PALETTE_SEL_TILE_BLUE, PALETTE_SEL_TILE_RED, PALETTE_TILE_RED_PULSATING, RemoveHalftileSlope(), SLOPE_N, SLOPE_STEEP_N, TILE_HEIGHT, TileX(), TileY(), and ZOOM_LVL_DETAIL.

static void DrawTileSelectionRect | ( | const TileInfo * | ti,
|  | SpriteID | pal |
| ) |  |  | `[static]`

Draws a selection rectangle on a tile.

Parameters:

  | ti | TileInfo Tile that is being drawn
  | pal | Palette to apply.

Definition at line 849 of file viewport.cpp.

References DrawSelectionSprite(), FOUNDATION_PART_HALFTILE, FOUNDATION_PART_NORMAL, GetHalftileSlopeCorner(), IsHalftileSlope(), IsSteepSlope(), OppositeCorner(), SlopeWithOneCornerRaised(), and TILE_HEIGHT.

Referenced by DrawTileSelection().

void HandleZoomMessage | ( | Window * | w,
|  | const ViewPort * | vp,
|  | byte | widget_zoom_in,
|  | byte | 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 460 of file viewport.cpp.

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 564 of file viewport.cpp.

References FOUNDATION_PART_HALFTILE, FOUNDATION_PART_NONE, and FOUNDATION_PART_NORMAL.

static bool SwapDirection | ( | HighLightStyle | style,
|  | TileIndex | start_tile,
|  | TileIndex | end_tile |
| ) |  |  | `[static]`

Check if the direction of start and end tile should be swapped based on the dragging-style.

Default directions are: in the case of a line (HT_RAIL, HT_LINE): DIR_NE, DIR_NW, DIR_N, DIR_E in the case of a rect (HT_RECT, HT_POINT): DIR_S, DIR_E For example dragging a rectangle area from south to north should be swapped to north-south (DIR_S) to obtain the same results with less code. This is what the return value signifies.

Parameters:

  | style | HighLightStyle dragging style
  | start_tile | start tile of drag
  | end_tile | end tile of drag

Returns:
  boolean value which when true means start/end should be swapped

Definition at line 2426 of file viewport.cpp.

References HT_DRAG_MASK, HT_LINE, HT_RAIL, TileX(), and TileY().

Referenced by CalcHeightdiff().

void UpdateTileSelection | ( |  | ) |

Updates tile highlighting for all cases.

Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice, Once for the old and once for the new selection. _thd is TileHighlightData, found in viewport.h Called by MouseLoop() in windows.cpp

Definition at line 2250 of file viewport.cpp.

References GetAutorailHT(), SetSelectionTilesDirty(), Swap(), TILE_SIZE, VHM_NONE, VHM_POINT, VHM_RAIL, VHM_RECT, and VHM_SPECIAL.

static void ViewportDrawBoundingBoxes | ( | ParentSpriteToDraw * | psd[] | ) | `[static]`

Draws the bounding boxes of all ParentSprites.

Parameters:

  | psd | Array of ParentSprites

Definition at line 1456 of file viewport.cpp.

References DrawBox().

static void ViewportDrawChk | ( | const ViewPort * | vp,
|  | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom |
| ) |  |  | `[static]`

Make sure we don't draw a too big area at a time.

If we do, the sprite memory will overflow.

Definition at line 1605 of file viewport.cpp.

void VpSelectTilesWithMethod | ( | int | x,
|  | int | y,
|  | ViewportPlaceMethod | method |
| ) |  |  |

Selects tiles while dragging.

Parameters:

  | x | X coordinate of end of selection
  | y | Y coordinate of end of selection
  | method | modifies the way tiles are selected. Possible methods are VPM_* in viewport.h

Definition at line 2668 of file viewport.cpp.

References abs(), CalcHeightdiff(), CalcRaildirsDrawstyle(), Clamp(), Delta(), DistanceManhattan(), GuiShowTooltipsWithArgs(), HT_DIR_X, HT_DIR_Y, HT_LINE, TILE_SIZE, TileX(), TileY(), VPM_FIX_X, VPM_FIX_Y, VPM_RAILDIRS, VPM_SIGNALDIRS, VPM_X_AND_Y, VPM_X_AND_Y_LIMITED, and VPM_X_OR_Y.

Referenced by BuildRailToolbWndProc().

void VpSetPresizeRange | ( | TileIndex | from,
|  | TileIndex | to |
| ) |  |  |

Highlights all tiles between a set of two tiles.

Used in dock and tunnel placement

Parameters:

  | from | TileIndex of the first tile to highlight
  | to | TileIndex of the last tile to highlight

Definition at line 2362 of file viewport.cpp.

References DistanceManhattan(), GuiShowTooltipsWithArgs(), TILE_SIZE, TileX(), and TileY().

Referenced by BuildRailToolbWndProc().

## Variable Documentation

const HighLightStyle _autorail_type[6][2]`[static]`

Initial value:

     {
      { HT_DIR_X,  HT_DIR_X },
      { HT_DIR_Y,  HT_DIR_Y },
      { HT_DIR_HU, HT_DIR_HL },
      { HT_DIR_HL, HT_DIR_HU },
      { HT_DIR_VL, HT_DIR_VR },
      { HT_DIR_VR, HT_DIR_VL }
    }

Definition at line 890 of file viewport.cpp.

OnVehicleClickProc* const _on_vehicle_click_proc[]`[static]`

Initial value:

     {
      SafeShowTrainViewWindow,
      SafeShowRoadVehViewWindow,
      ShowVehicleViewWindow,
      ShowVehicleViewWindow,
      Nop,
      Nop
    }

Definition at line 2090 of file viewport.cpp.

ViewPort _viewports[MAX_NUMBER_OF_WINDOWS-1]`[static]`

The maximum number of viewports depends on the maximum number of windows.

Technically is could be the maximum number of windows, but there is always at least one window that does not need a viewport. Not having 'support' for that viewport saves some time and memory. For the introduction GUI and create game GUIs there is no need for more than one viewport, however in the normal game and scenario editor one can make a lot of viewports. For the normal game one always has a main toolbar and a status bar, however the statusbar does not exist on the scenario editor.

This means that we can only safely assume that there is one window without viewport.

Definition at line 53 of file viewport.cpp.

Referenced by MarkAllViewportsDirty().