OpenTTD Source 20241224-master-gf74b0cf984
viewport.cpp File Reference

Handling of all viewports. More...

#include "stdafx.h"
#include "core/backup_type.hpp"
#include "landscape.h"
#include "viewport_func.h"
#include "station_base.h"
#include "waypoint_base.h"
#include "town.h"
#include "signs_base.h"
#include "signs_func.h"
#include "vehicle_base.h"
#include "vehicle_gui.h"
#include "blitter/factory.hpp"
#include "strings_func.h"
#include "zoom_func.h"
#include "vehicle_func.h"
#include "company_func.h"
#include "waypoint_func.h"
#include "window_func.h"
#include "tilehighlight_func.h"
#include "window_gui.h"
#include "linkgraph/linkgraph_gui.h"
#include "viewport_kdtree.h"
#include "town_kdtree.h"
#include "viewport_sprite_sorter.h"
#include "bridge_map.h"
#include "company_base.h"
#include "command_func.h"
#include "network/network_func.h"
#include "framerate_type.h"
#include "viewport_cmd.h"
#include <forward_list>
#include <stack>
#include "table/strings.h"
#include "table/string_colours.h"
#include "safeguards.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  ViewportDrawer
 Data structure storing rendering information. More...
 
struct  ViewportSSCSS
 Helper class for getting the best sprite sorter. More...
 

Typedefs

typedef std::vector< TileSpriteToDrawTileSpriteToDrawVector
 
typedef std::vector< StringSpriteToDrawStringSpriteToDrawVector
 
typedef std::vector< ParentSpriteToDrawParentSpriteToDrawVector
 
typedef std::vector< ChildScreenSpriteToDrawChildScreenSpriteToDrawVector
 

Enumerations

enum  FoundationPart { FOUNDATION_PART_NONE = 0xFF , FOUNDATION_PART_NORMAL = 0 , FOUNDATION_PART_HALFTILE = 1 , FOUNDATION_PART_END }
 Enumeration of multi-part foundations. More...
 
enum  SpriteCombineMode { SPRITE_COMBINE_NONE , SPRITE_COMBINE_PENDING , SPRITE_COMBINE_ACTIVE }
 Mode of "sprite combining". More...
 
enum  TileHighlightType { THT_NONE , THT_WHITE , THT_BLUE , THT_RED }
 

Functions

static bool MarkViewportDirty (const Viewport *vp, int left, int top, int right, int bottom)
 Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.
 
static Point MapXYZToViewport (const Viewport *vp, int x, int y, int z)
 
void DeleteWindowViewport (Window *w)
 
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.
 
static void DoSetViewportPosition (Window::IteratorToFront it, int left, int top, int width, int height)
 
static void SetViewportPosition (Window *w, int x, int y)
 
ViewportIsPtInWindowViewport (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)
 Translate screen coordinate in a viewport to underlying tile coordinate.
 
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, WidgetID widget_zoom_in, WidgetID widget_zoom_out)
 Update the status of the zoom-buttons according to the zoom-level of the viewport.
 
static void AddTileSpriteToDraw (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)
 Schedules a tile sprite for drawing.
 
static void AddChildSpriteToFoundation (SpriteID image, PaletteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y)
 Adds a child sprite to the active foundation.
 
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.
 
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.
 
void OffsetGroundSprite (int x, int y)
 Called when a foundation has been drawn for the current tile.
 
static void AddCombinedSprite (SpriteID image, PaletteID pal, int x, int y, int z, const SubSprite *sub)
 Adds a child sprite to a parent sprite.
 
void AddSortableSpriteToDraw (SpriteID image, PaletteID 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 ()
 Starts a block of sprites, which are "combined" into a single bounding box.
 
void EndSpriteCombine ()
 Terminates a block of sprites started by StartSpriteCombine.
 
static bool IsInRangeInclusive (int begin, int end, int check)
 Check if the parameter "check" is inside the interval between begin and end, including both begin and end.
 
bool IsInsideRotatedRectangle (int x, int y)
 Checks whether a point is inside the selected a diagonal rectangle given by _thd.size and _thd.pos.
 
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.
 
static void AddStringToDraw (int x, int y, StringID string, Colours colour, uint16_t width)
 
static void DrawSelectionSprite (SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part, int extra_offs_x=0, int extra_offs_y=0)
 Draws sprites between ground sprite and everything above.
 
static void DrawTileSelectionRect (const TileInfo *ti, PaletteID 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 TileHighlightType GetTileHighlightType (TileIndex t)
 Get tile highlight type of coverage area for a given tile.
 
static void DrawTileHighlightType (const TileInfo *ti, TileHighlightType tht)
 Draw tile highlight for coverage area highlight.
 
static void HighlightTownLocalAuthorityTiles (const TileInfo *ti)
 Highlights tiles insede local authority of selected towns.
 
static void DrawTileSelection (const TileInfo *ti)
 Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
 
static int GetViewportY (Point tile)
 Returns the y coordinate in the viewport coordinate system where the given tile is painted.
 
static void ViewportAddLandscape ()
 Add the landscape to the viewport, i.e.
 
void ViewportAddString (const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, Colours colour)
 Add a string to draw in the viewport.
 
static Rect ExpandRectWithViewportSignMargins (Rect r, ZoomLevel zoom)
 
static void ViewportAddKdtreeSigns (DrawPixelInfo *dpi)
 
static void ViewportDrawTileSprites (const TileSpriteToDrawVector *tstdv)
 
static bool ViewportSortParentSpritesChecker ()
 This fallback sprite checker always exists.
 
static void ViewportSortParentSprites (ParentSpriteToSortVector *psdv)
 Sort parent sprites pointer array replicating the way original sorter did it.
 
static void ViewportDrawParentSprites (const ParentSpriteToSortVector *psd, const ChildScreenSpriteToDrawVector *csstdv)
 
static void ViewportDrawBoundingBoxes (const ParentSpriteToSortVector *psd)
 Draws the bounding boxes of all ParentSprites.
 
static void ViewportDrawDirtyBlocks ()
 Draw/colour the blocks that have been redrawn.
 
static void ViewportDrawStrings (ZoomLevel zoom, const StringSpriteToDrawVector *sstdv)
 
void ViewportDoDraw (const Viewport *vp, int left, int top, int right, int bottom)
 
static void ViewportDraw (const Viewport *vp, int left, int top, int right, int bottom)
 
static void ClampViewportToMap (const Viewport *vp, int *scroll_x, int *scroll_y)
 Ensure that a given viewport has a valid scroll position.
 
static void ClampSmoothScroll (uint32_t delta_ms, int64_t delta_hi, int64_t delta_lo, int &delta_hi_clamped, int &delta_lo_clamped)
 Clamp the smooth scroll to a maxmimum speed and distance based on time elapsed.
 
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).
 
void ConstrainAllViewportsZoom ()
 
void MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset, int tile_height_override)
 Mark a tile given by its index dirty for repaint.
 
static void SetSelectionTilesDirty ()
 Marks the selected tiles as dirty.
 
void SetSelectionRed (bool b)
 
static bool CheckClickOnViewportSign (const Viewport *vp, int x, int y, const ViewportSign *sign)
 Test whether a sign is below the mouse.
 
static bool CheckClickOnViewportSign (const Viewport *vp, int x, int y)
 Check whether any viewport sign was clicked, and dispatch the click.
 
void RebuildViewportKdtree ()
 
static bool CheckClickOnLandscape (const Viewport *vp, int x, int y)
 
static void PlaceObject ()
 
bool HandleViewportClicked (const Viewport *vp, int x, int y)
 
void RebuildViewportOverlay (Window *w)
 
bool ScrollWindowTo (int x, int y, int z, Window *w, bool instant)
 Scrolls the viewport in a window to a given location.
 
bool ScrollWindowToTile (TileIndex tile, Window *w, bool instant)
 Scrolls the viewport in a window to a given location.
 
bool ScrollMainWindowToTile (TileIndex tile, bool instant)
 Scrolls the viewport of the main window to a given location.
 
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)
 
static HighLightStyle GetAutorailHT (int x, int y)
 returns the best autorail highlight type from map coordinates
 
void UpdateTileSelection ()
 Updates tile highlighting for all cases.
 
static void ShowMeasurementTooltips (StringID str, uint paramcount)
 Displays the measurement tooltips when selecting multiple tiles.
 
static void HideMeasurementTooltips ()
 
void VpStartPlaceSizing (TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
 highlighting tiles while only going over them with the mouse
 
void VpStartDragging (ViewportDragDropSelectionProcess process)
 Drag over the map while holding the left mouse down.
 
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.
 
static void CheckUnderflow (int &test, int &other, int mult)
 Check for underflowing the map.
 
static void CheckOverflow (int &test, int &other, int max, int mult)
 Check for overflowing the map.
 
static void CalcRaildirsDrawstyle (int x, int y, int method)
 while dragging
 
void VpSelectTilesWithMethod (int x, int y, ViewportPlaceMethod method)
 Selects tiles while dragging.
 
EventState VpHandlePlaceSizingDrag ()
 Handle the mouse while dragging for placement/resizing.
 
void SetObjectToPlaceWnd (CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
 Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc.
 
void SetObjectToPlace (CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
 Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc.
 
void ResetObjectToPlace ()
 Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
 
Point GetViewportStationMiddle (const Viewport *vp, const Station *st)
 
void InitializeSpriteSorter ()
 Choose the "best" sprite sorter and set _vp_sprite_sorter.
 
CommandCost CmdScrollViewport (DoCommandFlag flags, TileIndex tile, ViewportScrollTarget target, uint32_t ref)
 Scroll players main viewport.
 
void MarkCatchmentTilesDirty ()
 
static void SetWindowDirtyForViewportCatchment ()
 
static void ClearViewportCatchment ()
 
void SetViewportCatchmentStation (const Station *st, bool sel)
 Select or deselect station for coverage area highlight.
 
void SetViewportCatchmentWaypoint (const Waypoint *wp, bool sel)
 Select or deselect waypoint for coverage area highlight.
 
void SetViewportCatchmentTown (const Town *t, bool sel)
 Select or deselect town for coverage area highlight.
 

Variables

Point _tile_fract_coords
 
ViewportSignKdtree _viewport_sign_kdtree {}
 
static int _viewport_sign_maxwidth = 0
 
static const int MAX_TILE_EXTENT_LEFT = ZOOM_BASE * TILE_PIXELS
 Maximum left extent of tile relative to north corner.
 
static const int MAX_TILE_EXTENT_RIGHT = ZOOM_BASE * TILE_PIXELS
 Maximum right extent of tile relative to north corner.
 
static const int MAX_TILE_EXTENT_TOP = ZOOM_BASE * MAX_BUILDING_PIXELS
 Maximum top extent of tile relative to north corner (not considering bridges).
 
static const int MAX_TILE_EXTENT_BOTTOM = ZOOM_BASE * (TILE_PIXELS + 2 * TILE_HEIGHT)
 Maximum bottom extent of tile relative to north corner (worst case: SLOPE_STEEP_N).
 
constexpr int LAST_CHILD_NONE = -1
 There is no last_child to fill.
 
constexpr int LAST_CHILD_PARENT = -2
 Fill last_child of the most recent parent sprite.
 
static ViewportDrawer _vd
 
TileHighlightData _thd
 
static TileInfo _cur_ti
 
bool _draw_bounding_boxes = false
 
bool _draw_dirty_blocks = false
 
uint _dirty_block_colour = 0
 
static VpSpriteSorter _vp_sprite_sorter = nullptr
 
static Point _vp_move_offs
 
static const HighLightStyle _autorail_type [6][2]
 
const Station_viewport_highlight_station
 Currently selected station for coverage area highlight.
 
const Waypoint_viewport_highlight_waypoint
 Currently selected waypoint for coverage area highlight.
 
const Town_viewport_highlight_town
 Currently selected town for coverage area highlight.
 
static const StringID measure_strings_length [] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF}
 
static ViewportSSCSS _vp_sprite_sorters []
 List of sorters ordered from best to worst.
 

Detailed Description

Handling of all viewports.

* The in-game coordinate system looks like this *
*                                               *
*                    ^ Z                        *
*                    |                          *
*                    |                          *
*                    |                          *
*                    |                          *
*                 /     \                       *
*              /           \                    *
*           /                 \                 *
*        /                       \              *
*   X <                             > Y         *
* 

Definition in file viewport.cpp.

Typedef Documentation

◆ ChildScreenSpriteToDrawVector

typedef std::vector<ChildScreenSpriteToDraw> ChildScreenSpriteToDrawVector

Definition at line 162 of file viewport.cpp.

◆ ParentSpriteToDrawVector

typedef std::vector<ParentSpriteToDraw> ParentSpriteToDrawVector

Definition at line 161 of file viewport.cpp.

◆ StringSpriteToDrawVector

typedef std::vector<StringSpriteToDraw> StringSpriteToDrawVector

Definition at line 160 of file viewport.cpp.

◆ TileSpriteToDrawVector

typedef std::vector<TileSpriteToDraw> TileSpriteToDrawVector

Definition at line 159 of file viewport.cpp.

Enumeration Type Documentation

◆ FoundationPart

Enumeration of multi-part foundations.

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

◆ SpriteCombineMode

Mode of "sprite combining".

See also
StartSpriteCombine
Enumerator
SPRITE_COMBINE_NONE 

Every AddSortableSpriteToDraw start its own bounding box.

SPRITE_COMBINE_PENDING 

Sprite combining will start with the next unclipped sprite.

SPRITE_COMBINE_ACTIVE 

Sprite combining is active. AddSortableSpriteToDraw outputs child sprites.

Definition at line 153 of file viewport.cpp.

◆ TileHighlightType

enum TileHighlightType

Definition at line 998 of file viewport.cpp.

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
imagethe image to draw.
palthe provided palette.
xsprite x-offset (screen coordinates) relative to parent sprite.
ysprite y-offset (screen coordinates) relative to parent sprite.
transparentif true, switch the palette between the provided palette and the transparent palette,
subOnly draw a part of the sprite.
scaleif true, scale offsets to base zoom level.
relativeif true, draw sprite relative to parent sprite offsets.

Definition at line 827 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().

◆ AddChildSpriteToFoundation()

static void AddChildSpriteToFoundation ( SpriteID  image,
PaletteID  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
imagethe image to draw.
palthe provided palette.
subOnly draw a part of the sprite.
foundation_partFoundation part.
extra_offs_xPixel X offset for the sprite position.
extra_offs_yPixel Y offset for the sprite position.

Definition at line 540 of file viewport.cpp.

References AddChildSpriteScreen(), ViewportDrawer::foundation, ViewportDrawer::foundation_offset, IsInsideMM(), and ViewportDrawer::last_foundation_child.

Referenced by DrawGroundSpriteAt(), and DrawSelectionSprite().

◆ AddCombinedSprite()

static void AddCombinedSprite ( SpriteID  image,
PaletteID  pal,
int  x,
int  y,
int  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
imagethe image to draw.
palthe provided palette.
xposition x of the sprite.
yposition y of the sprite.
zposition z of the sprite.
subOnly draw a part of the sprite.

Definition at line 631 of file viewport.cpp.

References AddChildSpriteScreen(), Sprite::height, ParentSpriteToDraw::left, Normal, RemapCoords(), SPRITE_MASK, ParentSpriteToDraw::top, Sprite::width, Sprite::x_offs, and Sprite::y_offs.

Referenced by AddSortableSpriteToDraw().

◆ AddSortableSpriteToDraw()

void AddSortableSpriteToDraw ( SpriteID  image,
PaletteID  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
imagethe image to combine and draw,
palthe provided palette,
xposition X (world) of the sprite,
yposition Y (world) of the sprite,
wbounding box extent towards positive X (world),
hbounding box extent towards positive Y (world),
dzbounding box extent towards positive Z (world),
zposition Z (world) of the sprite,
transparentif true, switch the palette between the provided palette and the transparent palette,
bb_offset_xbounding box extent towards negative X (world),
bb_offset_ybounding box extent towards negative Y (world),
bb_offset_zbounding box extent towards negative Z (world)
subOnly draw a part of the sprite.

Definition at line 671 of file viewport.cpp.

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

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

◆ AddStringToDraw()

static void AddStringToDraw ( int  x,
int  y,
StringID  string,
Colours  colour,
uint16_t  width 
)
static

Definition at line 864 of file viewport.cpp.

◆ AddTileSpriteToDraw()

static void AddTileSpriteToDraw ( 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 
)
static

Schedules a tile sprite for drawing.

Parameters
imagethe image to draw.
palthe provided palette.
xposition x (world coordinates) of the sprite.
yposition y (world coordinates) of the sprite.
zposition z (world coordinates) of the sprite.
subOnly draw a part of the sprite.
extra_offs_xPixel X offset for the sprite position.
extra_offs_yPixel Y offset for the sprite position.

Definition at line 515 of file viewport.cpp.

References MAX_SPRITES, RemapCoords(), SPRITE_MASK, TileSpriteToDraw::sub, TileSpriteToDraw::x, and TileSpriteToDraw::y.

Referenced by DrawGroundSpriteAt(), and DrawSelectionSprite().

◆ CalcHeightdiff()

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 TILE_HEIGHT_STEP.

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.cpp for the direction enums if you can't figure out the values yourself.

Parameters
styleHighlighting style of the drag. This includes direction and style (autorail, rect, etc.)
distanceNumber of tiles dragged, important for horizontal/vertical drags, ignored for others.
start_tileStart tile of the drag operation.
end_tileEnd tile of the drag operation.
Returns
Height difference between two tiles. The tile measurement tool utilizes this value in its tooltip.

Definition at line 2884 of file viewport.cpp.

References DIR_S, DIR_SE, DIR_SW, HT_DIR_END, HT_DIR_HL, HT_DIR_HU, HT_DIR_MASK, HT_DIR_VL, HT_DIR_VR, HT_DIR_X, HT_DIR_Y, HT_DRAG_MASK, HT_POINT, HT_RECT, Swap(), SwapDirection(), TILE_HEIGHT_STEP, TileAdd(), TileAddByDir(), TileHeight(), TileX(), and ToTileIndexDiff().

Referenced by CalcRaildirsDrawstyle(), and VpSelectTilesWithMethod().

◆ CalcRaildirsDrawstyle()

◆ Check2x1AutoRail()

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

References HT_DIR_HL, HT_DIR_HU, HT_DIR_VL, HT_DIR_VR, HT_DIR_X, HT_DIR_Y, TileHighlightData::selend, and TILE_UNIT_MASK.

Referenced by CalcRaildirsDrawstyle().

◆ CheckClickOnLandscape()

static bool CheckClickOnLandscape ( const Viewport vp,
int  x,
int  y 
)
static

Definition at line 2389 of file viewport.cpp.

◆ CheckClickOnViewportSign() [1/2]

static bool CheckClickOnViewportSign ( const Viewport vp,
int  x,
int  y 
)
static

Check whether any viewport sign was clicked, and dispatch the click.

Parameters
vpthe clicked viewport
xX position of click
yY position of click
Returns
true if the sign was hit

Definition at line 2217 of file viewport.cpp.

References _display_opt, DO_SHOW_COMPETITOR_SIGNS, DO_SHOW_SIGNS, DO_SHOW_STATION_NAMES, DO_SHOW_TOWN_NAMES, DO_SHOW_WAYPOINT_NAMES, Kdtree< T, TxyFunc, CoordT, DistT >::FindContained(), HasBit(), IsInvisibilitySet(), Viewport::left, ScaleByZoom(), TO_SIGNS, Viewport::top, Viewport::virtual_left, Viewport::virtual_top, and Viewport::zoom.

◆ CheckClickOnViewportSign() [2/2]

static bool CheckClickOnViewportSign ( const Viewport vp,
int  x,
int  y,
const ViewportSign sign 
)
static

Test whether a sign is below the mouse.

Parameters
vpthe clicked viewport
xX position of click
yY position of click
signthe sign to check
Returns
true if the sign was hit

Definition at line 2199 of file viewport.cpp.

References ViewportSign::center, FS_NORMAL, FS_SMALL, GetCharacterHeight(), ScaleByZoom(), WidgetDimensions::scaled, ViewportSign::top, ViewportSign::width_normal, ViewportSign::width_small, Viewport::zoom, and ZOOM_LVL_OUT_4X.

◆ CheckOverflow()

static void CheckOverflow ( int &  test,
int &  other,
int  max,
int  mult 
)
static

Check for overflowing the map.

Parameters
testthe variable to test for overflowing
otherthe other variable to update to keep the line
maxthe maximum value for the test variable
multthe constant to multiply the difference by for other

Definition at line 2988 of file viewport.cpp.

Referenced by CalcRaildirsDrawstyle().

◆ CheckUnderflow()

static void CheckUnderflow ( int &  test,
int &  other,
int  mult 
)
static

Check for underflowing the map.

Parameters
testthe variable to test for underflowing
otherthe other variable to update to keep the line
multthe constant to multiply the difference by for other

Definition at line 2973 of file viewport.cpp.

Referenced by CalcRaildirsDrawstyle().

◆ ClampSmoothScroll()

static void ClampSmoothScroll ( uint32_t  delta_ms,
int64_t  delta_hi,
int64_t  delta_lo,
int &  delta_hi_clamped,
int &  delta_lo_clamped 
)
static

Clamp the smooth scroll to a maxmimum speed and distance based on time elapsed.

Every 30ms, we move 1/4th of the distance, to give a smooth movement experience. But we never go over the max_scroll speed.

Parameters
delta_msTime elapsed since last update.
delta_hiThe distance to move in highest dimension (can't be zero).
delta_loThe distance to move in lowest dimension.
[out]delta_hi_clampedThe clamped distance to move in highest dimension.
[out]delta_lo_clampedThe clamped distance to move in lowest dimension.

A tile is 64 pixels in width at 1x zoom; viewport coordinates are in 4x zoom.

Definition at line 1889 of file viewport.cpp.

References Clamp(), Map::ScaleBySize1D(), and TILE_PIXELS.

Referenced by UpdateViewportPosition().

◆ ClampViewportToMap()

static void ClampViewportToMap ( const Viewport vp,
int *  scroll_x,
int *  scroll_y 
)
inlinestatic

Ensure that a given viewport has a valid scroll position.

There must be a visible piece of the map in the center of the viewport. If there isn't, the viewport will be scrolled to nearest such location.

Parameters
vpThe viewport.
[in,out]scroll_xViewport X scroll.
[in,out]scroll_yViewport Y scroll.

Definition at line 1857 of file viewport.cpp.

References InverseRemapCoords2(), RemapCoords2(), Viewport::virtual_height, and Viewport::virtual_width.

Referenced by UpdateViewportPosition().

◆ ClearViewportCatchment()

static void ClearViewportCatchment ( )
static

Definition at line 3604 of file viewport.cpp.

◆ CmdScrollViewport()

CommandCost CmdScrollViewport ( DoCommandFlag  flags,
TileIndex  tile,
ViewportScrollTarget  target,
uint32_t  ref 
)

Scroll players main viewport.

Parameters
flagstype of operation
tiletile to center viewport on
targetViewportScrollTarget of scroll target
refcompany or client id depending on the target
Returns
the cost of this operation or an error

Definition at line 3549 of file viewport.cpp.

References _current_company, _local_company, _network_own_client_id, CMD_ERROR, DC_EXEC, OWNER_DEITY, ResetObjectToPlace(), ScrollMainWindowToTile(), VST_CLIENT, VST_COMPANY, and VST_EVERYONE.

◆ ConstrainAllViewportsZoom()

void ConstrainAllViewportsZoom ( )

Definition at line 2037 of file viewport.cpp.

◆ DeleteWindowViewport()

void DeleteWindowViewport ( Window w)

Definition at line 206 of file viewport.cpp.

◆ DoSetViewportPosition()

static void DoSetViewportPosition ( Window::IteratorToFront  it,
int  left,
int  top,
int  width,
int  height 
)
static

Definition at line 280 of file viewport.cpp.

◆ DrawAutorailSelection()

static void DrawAutorailSelection ( const TileInfo ti,
uint  autorail_type 
)
static

Draws autorail highlights.

Parameters
*tiTileInfo Tile that is being drawn
autorail_typeOffset into _AutorailTilehSprite[][]

Definition at line 968 of file viewport.cpp.

References DrawSelectionSprite(), FOUNDATION_PART_HALFTILE, FOUNDATION_PART_NORMAL, GetHalftileSlopeCorner(), IsHalftileSlope(), TileHighlightData::make_square_red, OppositeCorner(), PALETTE_SEL_TILE_RED, RemoveHalftileSlope(), SlopeWithThreeCornersRaised(), and TileInfo::tileh.

Referenced by DrawTileSelection().

◆ 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
imagethe image to draw.
palthe provided palette.
subOnly draw a part of the sprite.
extra_offs_xPixel X offset for the sprite position.
extra_offs_yPixel Y offset for the sprite position.

Definition at line 587 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
imagethe image to draw.
palthe provided palette.
xposition x (world coordinates) of the sprite relative to current tile.
yposition y (world coordinates) of the sprite relative to current tile.
zposition z (world coordinates) of the sprite relative to current tile.
subOnly draw a part of the sprite.
extra_offs_xPixel X offset for the sprite position.
extra_offs_yPixel Y offset for the sprite position.

Definition at line 564 of file viewport.cpp.

References AddChildSpriteToFoundation(), AddTileSpriteToDraw(), ViewportDrawer::foundation, ViewportDrawer::foundation_part, FOUNDATION_PART_NONE, FOUNDATION_PART_NORMAL, RemapCoords(), TileInfo::x, TileInfo::y, and TileInfo::z.

Referenced by DrawGroundSprite(), and DrawRoadBits().

◆ DrawSelectionSprite()

static void DrawSelectionSprite ( SpriteID  image,
PaletteID  pal,
const TileInfo ti,
int  z_offset,
FoundationPart  foundation_part,
int  extra_offs_x = 0,
int  extra_offs_y = 0 
)
static

Draws sprites between ground sprite and everything above.

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

Parameters
imagethe image to draw.
palthe provided palette.
tiTileInfo Tile that is being drawn
z_offsetZ offset relative to the groundsprite. Only used for the sprite position, not for sprite sorting.
foundation_partFoundation part the sprite belongs to.
extra_offs_xPixel X offset for the sprite position.
extra_offs_yPixel Y offset for the sprite position.

Definition at line 890 of file viewport.cpp.

References AddChildSpriteToFoundation(), AddTileSpriteToDraw(), ViewportDrawer::foundation, TileInfo::x, TileInfo::y, and TileInfo::z.

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

◆ DrawTileHighlightType()

static void DrawTileHighlightType ( const TileInfo ti,
TileHighlightType  tht 
)
static

Draw tile highlight for coverage area highlight.

Parameters
*tiTileInfo Tile that is being drawn
thtHighlight type to draw.

Definition at line 1050 of file viewport.cpp.

References DrawTileSelectionRect(), PALETTE_SEL_TILE_BLUE, and PALETTE_SEL_TILE_RED.

Referenced by DrawTileSelection().

◆ DrawTileSelection()

◆ DrawTileSelectionRect()

static void DrawTileSelectionRect ( const TileInfo ti,
PaletteID  pal 
)
static

◆ EndSpriteCombine()

void EndSpriteCombine ( )

Terminates a block of sprites started by StartSpriteCombine.

Take a look there for details.

Definition at line 777 of file viewport.cpp.

References ViewportDrawer::combine_sprites, and SPRITE_COMBINE_NONE.

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

◆ ExpandRectWithViewportSignMargins()

static Rect ExpandRectWithViewportSignMargins ( Rect  r,
ZoomLevel  zoom 
)
static

Definition at line 1342 of file viewport.cpp.

◆ GetAutorailHT()

static HighLightStyle GetAutorailHT ( int  x,
int  y 
)
static

returns the best autorail highlight type from map coordinates

Definition at line 2559 of file viewport.cpp.

References HT_RAIL, and TILE_UNIT_MASK.

Referenced by CalcRaildirsDrawstyle(), and UpdateTileSelection().

◆ GetTileBelowCursor()

Point GetTileBelowCursor ( )

Definition at line 464 of file viewport.cpp.

◆ GetTileFromScreenXY()

static Point GetTileFromScreenXY ( int  x,
int  y,
int  zoom_x,
int  zoom_y 
)
static

Definition at line 450 of file viewport.cpp.

◆ GetTileHighlightType()

static TileHighlightType GetTileHighlightType ( TileIndex  t)
static

◆ GetTileZoomCenterWindow()

Point GetTileZoomCenterWindow ( bool  in,
Window w 
)

Definition at line 470 of file viewport.cpp.

◆ GetViewportStationMiddle()

Point GetViewportStationMiddle ( const Viewport vp,
const Station st 
)

Definition at line 3503 of file viewport.cpp.

◆ GetViewportY()

static int GetViewportY ( Point  tile)
static

Returns the y coordinate in the viewport coordinate system where the given tile is painted.

Parameters
tileAny tile.
Returns
The viewport y coordinate where the tile is painted.

Definition at line 1180 of file viewport.cpp.

References TILE_PIXELS, and TilePixelHeightOutsideMap().

Referenced by ViewportAddLandscape().

◆ HandleViewportClicked()

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

Definition at line 2418 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
wWindow pointer to the window that has the zoom buttons
vppointer to the viewport whose zoom-level the buttons represent
widget_zoom_inwidget index for window with zoom-in button
widget_zoom_outwidget index for window with zoom-out button

Definition at line 494 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().

◆ HideMeasurementTooltips()

static void HideMeasurementTooltips ( )
static

Definition at line 2716 of file viewport.cpp.

◆ HighlightTownLocalAuthorityTiles()

◆ InitializeSpriteSorter()

void InitializeSpriteSorter ( )

Choose the "best" sprite sorter and set _vp_sprite_sorter.

Definition at line 3530 of file viewport.cpp.

References _vp_sprite_sorters.

Referenced by openttd_main().

◆ 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
wWindow to use/display the viewport in
xOffset of left edge of viewport with respect to left edge window w
yOffset of top edge of viewport with respect to top edge window w
widthWidth of the viewport
heightHeight of the viewport
focusEither the tile index or vehicle ID to focus.
zoomZoomlevel to display

Definition at line 222 of file viewport.cpp.

References _settings_client, Clamp(), ViewportData::dest_scrollpos_x, ViewportData::dest_scrollpos_y, ViewportData::follow_vehicle, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), GetMainWindow(), GetSlopePixelZ(), ClientSettings::gui, Viewport::height, INVALID_TILE, INVALID_VEHICLE, Viewport::left, Window::left, ScaleByZoom(), ViewportData::scrollpos_x, ViewportData::scrollpos_y, TILE_SIZE, TileX(), TileY(), Viewport::top, Window::top, Window::viewport, Viewport::virtual_height, Viewport::virtual_left, Viewport::virtual_top, Viewport::virtual_width, Viewport::width, Vehicle::x_pos, Vehicle::y_pos, Vehicle::z_pos, Viewport::zoom, GUISettings::zoom_max, and GUISettings::zoom_min.

Referenced by NWidgetViewport::InitializeViewport().

◆ IsInRangeInclusive()

static bool IsInRangeInclusive ( int  begin,
int  end,
int  check 
)
static

Check if the parameter "check" is inside the interval between begin and end, including both begin and end.

Note
Whether begin or end is the biggest does not matter. This method will account for that.
Parameters
beginThe begin of the interval.
endThe end of the interval.
checkThe value to check.

Definition at line 792 of file viewport.cpp.

References Swap().

Referenced by IsInsideRotatedRectangle().

◆ IsInsideRotatedRectangle()

bool IsInsideRotatedRectangle ( int  x,
int  y 
)

Checks whether a point is inside the selected a diagonal rectangle given by _thd.size and _thd.pos.

Parameters
xThe x coordinate of the point to be checked.
yThe y coordinate of the point to be checked.
Returns
True if the point is inside the rectangle, else false.

Definition at line 804 of file viewport.cpp.

References IsInRangeInclusive(), TileHighlightData::pos, and TileHighlightData::size.

Referenced by DrawTileSelection().

◆ IsPartOfAutoLine()

static bool IsPartOfAutoLine ( int  px,
int  py 
)
static

Definition at line 931 of file viewport.cpp.

◆ IsPtInWindowViewport()

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

Is a xy position inside the viewport of the window?

Parameters
wWindow to examine its viewport
xX coordinate of the xy position
yY 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 411 of file viewport.cpp.

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

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

◆ MapXYZToViewport()

static Point MapXYZToViewport ( const Viewport vp,
int  x,
int  y,
int  z 
)
static

Definition at line 198 of file viewport.cpp.

◆ MarkCatchmentTilesDirty()

void MarkCatchmentTilesDirty ( )

Definition at line 3572 of file viewport.cpp.

◆ 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
xsprite x-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.
ysprite y-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.

Definition at line 599 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, and ViewportDrawer::last_foundation_child.

Referenced by DrawFoundation().

◆ PlaceObject()

static void PlaceObject ( )
static

Definition at line 2397 of file viewport.cpp.

◆ RebuildViewportKdtree()

void RebuildViewportKdtree ( )

Definition at line 2361 of file viewport.cpp.

◆ RebuildViewportOverlay()

void RebuildViewportOverlay ( Window w)

Definition at line 2450 of file viewport.cpp.

◆ ResetObjectToPlace()

◆ ScrollMainWindowToTile()

bool ScrollMainWindowToTile ( TileIndex  tile,
bool  instant 
)

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

Parameters
tileDesired tile to center on.
instantJump 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 2515 of file viewport.cpp.

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

Referenced by CmdScrollViewport(), DEF_CONSOLE_CMD(), 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
xDesired x location of the map to scroll to (world coordinate).
yDesired y location of the map to scroll to (world coordinate).
zDesired 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.
wWindow containing the viewport.
instantJump 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 2469 of file viewport.cpp.

References ViewportData::dest_scrollpos_x, ViewportData::dest_scrollpos_y, ViewportData::follow_vehicle, GetSlopePixelZ(), INVALID_VEHICLE, ViewportData::scrollpos_x, ViewportData::scrollpos_y, Map::SizeX(), Map::SizeY(), TILE_SIZE, TileHeightOutsideMap(), and Window::viewport.

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
tileDesired tile to center on.
wWindow containing the viewport.
instantJump 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 2504 of file viewport.cpp.

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

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

◆ SetObjectToPlace()

void SetObjectToPlace ( CursorID  icon,
PaletteID  pal,
HighLightStyle  mode,
WindowClass  window_class,
WindowNumber  window_num 
)

Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc.

Parameters
iconNew shape of the mouse cursor.
palPalette to use.
modeMode to perform.
window_classWindow class of the window requesting the mode change.
window_numNumber of the window in its class requesting the mode change.

Definition at line 3450 of file viewport.cpp.

References _animcursors, _special_mouse_mode, ANIMCURSOR_FLAG, TileHighlightData::drawstyle, TileHighlightData::GetCallbackWnd(), HT_DRAG, HT_DRAG_MASK, HT_NONE, HT_SPECIAL, TileHighlightData::make_square_red, Window::OnPlaceObjectAbort(), TileHighlightData::place_mode, SetAnimatedMouseCursor(), SetMouseCursor(), SetSelectionTilesDirty(), SetTileSelectSize(), WC_INVALID, TileHighlightData::window_class, TileHighlightData::window_number, WSM_DRAGDROP, and WSM_NONE.

Referenced by _GenerateWorld(), GenerateWorld(), HandlePlacePushButton(), ResetObjectToPlace(), SetObjectToPlaceWnd(), and BuildTreesWindow::UpdateMode().

◆ SetObjectToPlaceWnd()

void SetObjectToPlaceWnd ( CursorID  icon,
PaletteID  pal,
HighLightStyle  mode,
Window w 
)

Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc.

Parameters
iconNew shape of the mouse cursor.
palPalette to use.
modeMode to perform.
wWindow requesting the mode change.

Definition at line 3435 of file viewport.cpp.

References SetObjectToPlace(), Window::window_class, and Window::window_number.

Referenced by DepotWindow::DepotClick(), CompanyWindow::OnClick(), DepotWindow::OnClick(), VehicleGroupWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnClick(), RefitWindow::OnClick(), StoryBookWindow::OnPageElementClick(), and OrdersWindow::OrderClick_Goto().

◆ SetRedErrorSquare()

void SetRedErrorSquare ( TileIndex  tile)

Set a tile to display a red error square.

Parameters
tileTile that should show the red error square.

Definition at line 2524 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 2185 of file viewport.cpp.

◆ SetTileSelectBigSize()

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

Definition at line 2550 of file viewport.cpp.

◆ SetTileSelectSize()

void SetTileSelectSize ( int  w,
int  h 
)

Highlight w by h tiles at the cursor.

Parameters
wWidth of the highlighted tiles rectangle.
hHeight of the highlighted tiles rectangle.

Definition at line 2542 of file viewport.cpp.

References TileHighlightData::new_outersize, TileHighlightData::new_size, and TILE_SIZE.

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

◆ SetViewportCatchmentStation()

◆ SetViewportCatchmentTown()

void SetViewportCatchmentTown ( const Town t,
bool  sel 
)

Select or deselect town for coverage area highlight.

Selecting a town will deselect a station.

Parameters
*tTown in question
selSelect or deselect given town

Definition at line 3658 of file viewport.cpp.

References _viewport_highlight_town, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::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
*wpWaypoint in question
selSelect or deselect given waypoint

Definition at line 3638 of file viewport.cpp.

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

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

◆ SetViewportPosition()

static void SetViewportPosition ( Window w,
int  x,
int  y 
)
static

Definition at line 346 of file viewport.cpp.

◆ SetWindowDirtyForViewportCatchment()

static void SetWindowDirtyForViewportCatchment ( )
static

Definition at line 3597 of file viewport.cpp.

◆ ShowMeasurementTooltips()

static void ShowMeasurementTooltips ( StringID  str,
uint  paramcount 
)
inlinestatic

Displays the measurement tooltips when selecting multiple tiles.

Parameters
strString to be displayed
paramcountnumber of params to deal with

Definition at line 2710 of file viewport.cpp.

References _settings_client, TileHighlightData::GetCallbackWnd(), ClientSettings::gui, GuiShowTooltips(), and GUISettings::measure_tooltip.

Referenced by CalcRaildirsDrawstyle(), VpSelectTilesWithMethod(), and VpSetPresizeRange().

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

References ViewportDrawer::combine_sprites, SPRITE_COMBINE_NONE, and SPRITE_COMBINE_PENDING.

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

◆ SwapDirection()

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
styleHighLightStyle dragging style
start_tilestart tile of drag
end_tileend tile of drag
Returns
boolean value which when true means start/end should be swapped

Definition at line 2850 of file viewport.cpp.

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

Referenced by CalcHeightdiff().

◆ 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
vpViewport that contains the (x, y) screen coordinate
xScreen x coordinate, distance in pixels from the left edge of viewport frame
yScreen y coordinate, distance in pixels from the top edge of viewport frame
clamp_to_mapClamp 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 435 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.

◆ UpdateTileSelection()

void UpdateTileSelection ( )

◆ UpdateViewportPosition()

◆ ViewportAddKdtreeSigns()

static void ViewportAddKdtreeSigns ( DrawPixelInfo dpi)
static

Definition at line 1357 of file viewport.cpp.

◆ ViewportAddLandscape()

◆ ViewportAddString()

void ViewportAddString ( const DrawPixelInfo dpi,
ZoomLevel  small_from,
const ViewportSign sign,
StringID  string_normal,
StringID  string_small,
StringID  string_small_shadow,
Colours  colour 
)

Add a string to draw in the viewport.

Parameters
dpicurrent viewport area
small_fromZoomlevel from when the small font should be used
signsign position and dimension
string_normalString for normal and 2x zoom level
string_smallString for 4x and 8x zoom level
string_small_shadowShadow string for 4x and 8x zoom level; or #STR_NULL if no shadow
colourcolour of the sign background; or INVALID_COLOUR if transparent

Definition at line 1311 of file viewport.cpp.

References ViewportSign::center, FS_NORMAL, FS_SMALL, GetCharacterHeight(), ScaleByZoom(), WidgetDimensions::scaled, ViewportSign::top, ViewportSign::width_normal, and ViewportSign::width_small.

◆ ViewportDoDraw()

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

Definition at line 1740 of file viewport.cpp.

◆ ViewportDraw()

static void ViewportDraw ( const Viewport vp,
int  left,
int  top,
int  right,
int  bottom 
)
inlinestatic

Definition at line 1807 of file viewport.cpp.

◆ ViewportDrawBoundingBoxes()

static void ViewportDrawBoundingBoxes ( const ParentSpriteToSortVector *  psd)
static

Draws the bounding boxes of all ParentSprites.

Parameters
psdArray of ParentSprites

Definition at line 1673 of file viewport.cpp.

References DrawBox(), and RemapCoords().

◆ ViewportDrawDirtyBlocks()

static void ViewportDrawDirtyBlocks ( )
static

Draw/colour the blocks that have been redrawn.

Definition at line 1691 of file viewport.cpp.

References _string_colourmap, BlitterFactory::GetCurrentBlitter(), Blitter::MoveTo(), Blitter::SetPixel(), and UnScaleByZoom().

◆ ViewportDrawParentSprites()

static void ViewportDrawParentSprites ( const ParentSpriteToSortVector *  psd,
const ChildScreenSpriteToDrawVector *  csstdv 
)
static

Definition at line 1651 of file viewport.cpp.

◆ ViewportDrawStrings()

static void ViewportDrawStrings ( ZoomLevel  zoom,
const StringSpriteToDrawVector *  sstdv 
)
static

Definition at line 1710 of file viewport.cpp.

◆ ViewportDrawTileSprites()

static void ViewportDrawTileSprites ( const TileSpriteToDrawVector *  tstdv)
static

Definition at line 1517 of file viewport.cpp.

◆ ViewportSortParentSprites()

static void ViewportSortParentSprites ( ParentSpriteToSortVector *  psdv)
static

Sort parent sprites pointer array replicating the way original sorter did it.

Definition at line 1531 of file viewport.cpp.

◆ ViewportSortParentSpritesChecker()

static bool ViewportSortParentSpritesChecker ( )
static

This fallback sprite checker always exists.

Definition at line 1525 of file viewport.cpp.

◆ VpHandlePlaceSizingDrag()

◆ VpSelectTilesWithMethod()

◆ VpSetPlaceSizingLimit()

void VpSetPlaceSizingLimit ( int  limit)

Definition at line 2767 of file viewport.cpp.

◆ VpSetPresizeRange()

void VpSetPresizeRange ( TileIndex  from,
TileIndex  to 
)

Highlights all tiles between a set of two tiles.

Used in dock and tunnel placement

Parameters
fromTileIndex of the first tile to highlight
toTileIndex of the last tile to highlight

Definition at line 2777 of file viewport.cpp.

References DistanceManhattan(), HT_RECT, TileHighlightData::next_drawstyle, TileHighlightData::selend, TileHighlightData::selstart, SetDParam(), ShowMeasurementTooltips(), TILE_SIZE, TileX(), and TileY().

Referenced by BuildRailToolbarWindow::OnPlacePresize(), BuildRoadToolbarWindow::OnPlacePresize(), and BuildDocksToolbarWindow::OnPlacePresize().

◆ VpStartDragging()

◆ VpStartPlaceSizing()

◆ VpStartPreSizing()

static void VpStartPreSizing ( )
static

Definition at line 2796 of file viewport.cpp.

Variable Documentation

◆ _autorail_type

const HighLightStyle _autorail_type[6][2]
static
Initial value:
= {
}
@ HT_DIR_HL
horizontal lower
@ HT_DIR_HU
horizontal upper
@ HT_DIR_X
X direction.
@ HT_DIR_VL
vertical left
@ HT_DIR_VR
vertical right
@ HT_DIR_Y
Y direction.

Definition at line 951 of file viewport.cpp.

◆ _cur_ti

TileInfo _cur_ti
static

Definition at line 192 of file viewport.cpp.

◆ _dirty_block_colour

uint _dirty_block_colour = 0

Definition at line 195 of file viewport.cpp.

◆ _draw_bounding_boxes

bool _draw_bounding_boxes = false

Definition at line 193 of file viewport.cpp.

◆ _draw_dirty_blocks

bool _draw_dirty_blocks = false

Definition at line 194 of file viewport.cpp.

◆ _thd

Definition at line 191 of file viewport.cpp.

◆ _tile_fract_coords

Point _tile_fract_coords

Definition at line 102 of file viewport.cpp.

◆ _vd

ViewportDrawer _vd
static

Definition at line 189 of file viewport.cpp.

◆ _viewport_highlight_station

const Station* _viewport_highlight_station

Currently selected station for coverage area highlight.

Definition at line 1005 of file viewport.cpp.

Referenced by GetTileHighlightType(), StationViewWindow::OnPaint(), and SetViewportCatchmentStation().

◆ _viewport_highlight_town

const Town* _viewport_highlight_town

Currently selected town for coverage area highlight.

Definition at line 1007 of file viewport.cpp.

Referenced by GetTileHighlightType(), TownViewWindow::OnPaint(), and SetViewportCatchmentTown().

◆ _viewport_highlight_waypoint

const Waypoint* _viewport_highlight_waypoint

Currently selected waypoint for coverage area highlight.

Definition at line 1006 of file viewport.cpp.

Referenced by GetTileHighlightType(), WaypointWindow::OnPaint(), and SetViewportCatchmentWaypoint().

◆ _viewport_sign_kdtree

ViewportSignKdtree _viewport_sign_kdtree {}

Definition at line 105 of file viewport.cpp.

◆ _viewport_sign_maxwidth

int _viewport_sign_maxwidth = 0
static

Definition at line 106 of file viewport.cpp.

◆ _vp_move_offs

Point _vp_move_offs
static

Definition at line 278 of file viewport.cpp.

◆ _vp_sprite_sorter

VpSpriteSorter _vp_sprite_sorter = nullptr
static

Definition at line 196 of file viewport.cpp.

◆ _vp_sprite_sorters

ViewportSSCSS _vp_sprite_sorters[]
static
Initial value:
= {
}
static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
Sort parent sprites pointer array replicating the way original sorter did it.
static bool ViewportSortParentSpritesChecker()
This fallback sprite checker always exists.

List of sorters ordered from best to worst.

Definition at line 3522 of file viewport.cpp.

Referenced by InitializeSpriteSorter().

◆ LAST_CHILD_NONE

constexpr int LAST_CHILD_NONE = -1
constexpr

There is no last_child to fill.

Definition at line 164 of file viewport.cpp.

Referenced by AddChildSpriteScreen(), AddSortableSpriteToDraw(), OffsetGroundSprite(), and ViewportAddLandscape().

◆ LAST_CHILD_PARENT

constexpr int LAST_CHILD_PARENT = -2
constexpr

Fill last_child of the most recent parent sprite.

Definition at line 165 of file viewport.cpp.

Referenced by AddChildSpriteScreen(), and AddSortableSpriteToDraw().

◆ MAX_TILE_EXTENT_BOTTOM

const int MAX_TILE_EXTENT_BOTTOM = ZOOM_BASE * (TILE_PIXELS + 2 * TILE_HEIGHT)
static

Maximum bottom extent of tile relative to north corner (worst case: SLOPE_STEEP_N).

Definition at line 112 of file viewport.cpp.

Referenced by MarkTileDirtyByTile(), and ViewportAddLandscape().

◆ MAX_TILE_EXTENT_LEFT

const int MAX_TILE_EXTENT_LEFT = ZOOM_BASE * TILE_PIXELS
static

Maximum left extent of tile relative to north corner.

Definition at line 109 of file viewport.cpp.

Referenced by MarkTileDirtyByTile().

◆ MAX_TILE_EXTENT_RIGHT

const int MAX_TILE_EXTENT_RIGHT = ZOOM_BASE * TILE_PIXELS
static

Maximum right extent of tile relative to north corner.

Definition at line 110 of file viewport.cpp.

Referenced by MarkTileDirtyByTile().

◆ MAX_TILE_EXTENT_TOP

const int MAX_TILE_EXTENT_TOP = ZOOM_BASE * MAX_BUILDING_PIXELS
static

Maximum top extent of tile relative to north corner (not considering bridges).

Definition at line 111 of file viewport.cpp.

Referenced by MarkTileDirtyByTile(), and ViewportAddLandscape().

◆ measure_strings_length

const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF}
static

Definition at line 2965 of file viewport.cpp.