# viewport_func.h File Reference

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

`#include "gfx_type.h"`
`#include "viewport_type.h"`
`#include "vehicle_type.h"`
`#include "strings_type.h"`

Go to the source code of this file.

## Typedefs

typedef void | PlaceProc (TileIndex tile)

## Functions

void | SetSelectionRed (bool)
void | InitViewports ()
void | DeleteWindowViewport (Window *w)
void | AssignWindowViewport (Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom)
ViewPort * | IsPtInWindowViewport (const Window *w, int x, int y)
Point | GetTileBelowCursor ()
void | UpdateViewportPosition (Window *w)
bool | DoZoomInOutWindow (int how, Window *w)
void | ZoomInOrOutToCursorWindow (bool in, Window *w)
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.
static void | MaxZoomInOut (int how, Window *w)
void | OffsetGroundSprite (int x, int y)
| Called when a foundation has been drawn for the current tile.
void | DrawGroundSprite (SpriteID image, SpriteID pal, const SubSprite *sub=NULL)
| Draws a ground sprite for the current tile.
void | DrawGroundSpriteAt (SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub=NULL)
| Draws a ground sprite at a specific world-coordinate.
void | AddSortableSpriteToDraw (SpriteID image, SpriteID pal, int x, int y, int w, int h, int dz, int z, bool transparent=false, int bb_offset_x=0, int bb_offset_y=0, int bb_offset_z=0, const SubSprite *sub=NULL)
| Draw a (transparent) sprite at given coordinates with a given bounding box.
void * | AddStringToDraw (int x, int y, StringID string, uint64 params_1, uint64 params_2)
void | AddChildSpriteScreen (SpriteID image, SpriteID pal, int x, int y, bool transparent=false, const SubSprite *sub=NULL)
| Add a child sprite to a parent sprite.
void | StartSpriteCombine ()
void | EndSpriteCombine ()
void | HandleViewportClicked (const ViewPort *vp, int x, int y)
void | PlaceObject ()
void | SetRedErrorSquare (TileIndex tile)
void | SetTileSelectSize (int w, int h)
void | SetTileSelectBigSize (int ox, int oy, int sx, int sy)
Vehicle * | CheckMouseOverVehicle ()
void | VpSelectTilesWithMethod (int x, int y, ViewportPlaceMethod method)
| Selects tiles while dragging.
void | VpStartPlaceSizing (TileIndex tile, ViewportPlaceMethod method, byte process)
| highlighting tiles while only going over them with the mouse
void | VpSetPresizeRange (TileIndex from, TileIndex to)
| Highlights all tiles between a set of two tiles.
void | VpSetPlaceSizingLimit (int limit)
void | PlaceProc_DemolishArea (TileIndex tile)
void | PlaceProc_LevelLand (TileIndex tile)
void | PlaceProc_BuyLand (TileIndex tile)
bool | GUIPlaceProcDragXY (const WindowEvent *e)
| A central place to handle all X_AND_Y dragged GUI functions.
bool | HandlePlacePushButton (Window *w, int widget, CursorID cursor, ViewportHighlightMode mode, PlaceProc *placeproc)
| This code is shared for the majority of the pushbuttons.
void | ViewportDoDraw (const ViewPort *vp, int left, int top, int right, int bottom)
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 ()
bool | ScrollWindowTo (int x, int y, Window *w, bool instant=false)
bool | ScrollMainWindowToTile (TileIndex tile, bool instant=false)
bool | ScrollMainWindowTo (int x, int y, bool instant=false)

## Variables

PlaceProc * | _place_proc
Point | _tile_fract_coords
TileHighlightData | _thd

## Detailed Description

Functions related to (drawing on) viewports.

Definition in file viewport_func.h.

## 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().

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().

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().

bool GUIPlaceProcDragXY | ( | const WindowEvent * | e | ) |

A central place to handle all X_AND_Y dragged GUI functions.

Parameters:

  | e | WindowEvent variable holding in its higher bits (excluding the lower 4, since that defined the X_Y drag) the type of action to be performed

Returns:
  Returns true if the action was found and handled, and false otherwise. This allows for additional implements that are more local. For example X_Y drag of convertrail which belongs in rail_gui.cpp and not terraform_gui.cpp

Definition at line 111 of file terraform_gui.cpp.

References _ctrl_pressed, CMD_BUILD_CANAL, CMD_CLEAR_AREA, CMD_LEVEL_LAND, CMD_MSG, DoCommandP(), GenerateDesertArea(), and GenerateRockyArea().

Referenced by BuildRailToolbWndProc().

bool HandlePlacePushButton | ( | Window * | w,
|  | int | widget,
|  | CursorID | cursor,
|  | ViewportHighlightMode | mode,
|  | PlaceProc * | placeproc |
| ) |  |  |

This code is shared for the majority of the pushbuttons.

Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters

Parameters:

  | w | Window which called the function
  | widget | ID of the widget (=button) that called this function
  | cursor | How should the cursor image change? E.g. cursor with depot image in it
  | mode | Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground
  | placeproc | Procedure which will be called when someone clicks on the map

Returns:
  true if the button is clicked, false if it's unclicked

Definition at line 125 of file main_gui.cpp.

References SetWindowDirty().

Referenced by BuildRailClick_AutoSignals(), BuildRoadClick_AutoRoad(), BuildRoadClick_X_Dir(), BuildRoadClick_Y_Dir(), and EditorTerraformClick_Dynamite().

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.

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().