OpenTTD Source
20241108-master-g80f628063a
|
Functions related to (drawing on) viewports. More...
#include "gfx_type.h"
#include "viewport_type.h"
#include "window_type.h"
#include "tile_map.h"
#include "station_type.h"
#include "vehicle_type.h"
Go to the source code of this file.
Functions | |
void | SetSelectionRed (bool) |
void | 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. More... | |
Viewport * | IsPtInWindowViewport (const Window *w, int x, int y) |
Is a xy position inside the viewport of the window? More... | |
Point | TranslateXYToTileCoord (const Viewport *vp, int x, int y, bool clamp_to_map=true) |
Translate screen coordinate in a viewport to underlying tile coordinate. More... | |
Point | GetTileBelowCursor () |
void | UpdateViewportPosition (Window *w, uint32_t delta_ms) |
Update the viewport position being displayed. More... | |
bool | MarkAllViewportsDirty (int left, int top, int right, int bottom) |
Mark all viewports that display an area as dirty (in need of repaint). More... | |
bool | DoZoomInOutWindow (ZoomStateChange how, Window *w) |
Zooms a viewport in a window in or out. More... | |
void | ZoomInOrOutToCursorWindow (bool in, Window *w) |
void | ConstrainAllViewportsZoom () |
Point | GetTileZoomCenterWindow (bool in, Window *w) |
void | FixTitleGameZoom (int zoom_adjust=0) |
void | HandleZoomMessage (Window *w, const Viewport *vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out) |
Update the status of the zoom-buttons according to the zoom-level of the viewport. More... | |
void | MaxZoomInOut (ZoomStateChange how, Window *w) |
Zoom a viewport as far as possible in the given direction. More... | |
void | OffsetGroundSprite (int x, int y) |
Called when a foundation has been drawn for the current tile. More... | |
void | DrawGroundSprite (SpriteID image, PaletteID pal, const SubSprite *sub=nullptr, int extra_offs_x=0, int extra_offs_y=0) |
Draws a ground sprite for the current tile. More... | |
void | DrawGroundSpriteAt (SpriteID image, PaletteID pal, int32_t x, int32_t y, int z, const SubSprite *sub=nullptr, int extra_offs_x=0, int extra_offs_y=0) |
Draws a ground sprite at a specific world-coordinate relative to the current tile. More... | |
void | AddSortableSpriteToDraw (SpriteID image, PaletteID 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=nullptr) |
Draw a (transparent) sprite at given coordinates with a given bounding box. More... | |
void | AddChildSpriteScreen (SpriteID image, PaletteID pal, int x, int y, bool transparent=false, const SubSprite *sub=nullptr, bool scale=true, bool relative=true) |
Add a child sprite to a parent sprite. More... | |
void | ViewportAddString (const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, Colours colour=INVALID_COLOUR) |
Add a string to draw in the viewport. More... | |
void | StartSpriteCombine () |
Starts a block of sprites, which are "combined" into a single bounding box. More... | |
void | EndSpriteCombine () |
Terminates a block of sprites started by StartSpriteCombine. More... | |
bool | HandleViewportClicked (const Viewport *vp, int x, int y) |
void | SetRedErrorSquare (TileIndex tile) |
Set a tile to display a red error square. More... | |
void | SetTileSelectSize (int w, int h) |
Highlight w by h tiles at the cursor. More... | |
void | SetTileSelectBigSize (int ox, int oy, int sx, int sy) |
void | ViewportDoDraw (const Viewport *vp, int left, int top, int right, int bottom) |
bool | ScrollWindowToTile (TileIndex tile, Window *w, bool instant=false) |
Scrolls the viewport in a window to a given location. More... | |
bool | ScrollWindowTo (int x, int y, int z, Window *w, bool instant=false) |
Scrolls the viewport in a window to a given location. More... | |
void | RebuildViewportOverlay (Window *w) |
bool | ScrollMainWindowToTile (TileIndex tile, bool instant=false) |
Scrolls the viewport of the main window to a given location. More... | |
bool | ScrollMainWindowTo (int x, int y, int z=-1, bool instant=false) |
Scrolls the main window to given coordinates. More... | |
void | UpdateAllVirtCoords () |
Update the viewport coordinates of all signs. | |
void | ClearAllCachedNames () |
void | MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset, int tile_height_override) |
Mark a tile given by its index dirty for repaint. More... | |
void | MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset=0) |
Mark a tile given by its index dirty for repaint. More... | |
Point | GetViewportStationMiddle (const Viewport *vp, const Station *st) |
void | SetViewportCatchmentStation (const Station *st, bool sel) |
Select or deselect station for coverage area highlight. More... | |
void | SetViewportCatchmentWaypoint (const Waypoint *wp, bool sel) |
Select or deselect waypoint for coverage area highlight. More... | |
void | SetViewportCatchmentTown (const Town *t, bool sel) |
Select or deselect town for coverage area highlight. More... | |
void | MarkCatchmentTilesDirty () |
template<class T > | |
void | SetViewportCatchmentSpecializedStation (const T *st, bool sel) |
template<> | |
void | SetViewportCatchmentSpecializedStation (const Station *st, bool sel) |
template<> | |
void | SetViewportCatchmentSpecializedStation (const Waypoint *st, bool sel) |
Variables | |
static const int | TILE_HEIGHT_STEP = 50 |
One Z unit tile height difference is displayed as 50m. | |
Point | _tile_fract_coords |
Functions related to (drawing on) viewports.
Definition in file viewport_func.h.
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.
image | the image to draw. |
pal | the provided palette. |
x | sprite x-offset (screen coordinates) relative to parent sprite. |
y | sprite y-offset (screen coordinates) relative to parent sprite. |
transparent | if true, switch the palette between the provided palette and the transparent palette, |
sub | Only draw a part of the sprite. |
scale | if true, scale offsets to base zoom level. |
relative | if true, draw sprite relative to parent sprite offsets. |
Definition at line 827 of file viewport.cpp.
Referenced by DrawCommonTileSeq().
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.
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 671 of file viewport.cpp.
Referenced by DrawCommonTileSeq().
bool DoZoomInOutWindow | ( | ZoomStateChange | how, |
Window * | w | ||
) |
Zooms a viewport in a window in or out.
how | Zooming direction. |
w | Window owning the viewport. |
true
if zooming step could be done, false
if further zooming is not possible. Definition at line 93 of file main_gui.cpp.
References _settings_client, ViewportData::dest_scrollpos_x, ViewportData::dest_scrollpos_y, ClientSettings::gui, Window::InvalidateData(), ViewportData::scrollpos_x, ViewportData::scrollpos_y, Window::viewport, Viewport::virtual_height, Viewport::virtual_left, Viewport::virtual_top, Viewport::virtual_width, Viewport::zoom, ZOOM_IN, GUISettings::zoom_max, GUISettings::zoom_min, ZOOM_NONE, and ZOOM_OUT.
Referenced by DEF_CONSOLE_CMD(), and MaxZoomInOut().
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.
image | the image to draw. |
pal | the provided palette. |
sub | Only draw a part of the sprite. |
extra_offs_x | Pixel X offset for the sprite position. |
extra_offs_y | Pixel Y offset for the sprite position. |
Definition at line 587 of file viewport.cpp.
References DrawGroundSpriteAt().
Referenced by DrawCommonTileSeq(), DrawRoadOverlays(), and DrawSeaWater().
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.
image | the image to draw. |
pal | the provided palette. |
x | position x (world coordinates) of the sprite relative to current tile. |
y | position y (world coordinates) of the sprite relative to current tile. |
z | position z (world coordinates) of the sprite relative to current tile. |
sub | Only draw a part of the sprite. |
extra_offs_x | Pixel X offset for the sprite position. |
extra_offs_y | Pixel Y offset for the sprite position. |
Definition at line 564 of file viewport.cpp.
Referenced by DrawGroundSprite().
void EndSpriteCombine | ( | ) |
Terminates a block of sprites started by StartSpriteCombine.
Take a look there for details.
Definition at line 777 of file viewport.cpp.
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
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 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().
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.
w | Window to use/display the viewport in |
x | Offset of left edge of viewport with respect to left edge window w |
y | Offset of top edge of viewport with respect to top edge window w |
width | Width of the viewport |
height | Height of the viewport |
focus | Either the tile index or vehicle ID to focus. |
zoom | Zoomlevel to display |
Definition at line 222 of file viewport.cpp.
Referenced by NWidgetViewport::InitializeViewport().
Is a xy position inside the viewport of the window?
w | Window to examine its viewport |
x | X coordinate of the xy position |
y | Y coordinate of the xy position |
nullptr
is returned. Definition at line 411 of file viewport.cpp.
|
inline |
Zoom a viewport as far as possible in the given direction.
how | Zooming direction. |
w | Window owning the viewport. |
Definition at line 46 of file viewport_func.h.
References DoZoomInOutWindow().
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.
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 599 of file viewport.cpp.
bool ScrollMainWindowTo | ( | int | x, |
int | y, | ||
int | z, | ||
bool | instant | ||
) |
Scrolls the main window to given coordinates.
x | x coordinate |
y | y coordinate |
z | z coordinate; -1 to scroll to terrain height |
instant | scroll instantly (meaningful only when smooth_scrolling is active) |
Definition at line 2076 of file smallmap_gui.cpp.
Referenced by ScrollMainWindowToTile().
bool ScrollMainWindowToTile | ( | TileIndex | tile, |
bool | instant | ||
) |
Scrolls the viewport of the main window to a given location.
tile | Desired tile to center on. |
instant | Jump to the location instead of slowly moving to it. |
Definition at line 2515 of file viewport.cpp.
References ScrollMainWindowTo(), TILE_SIZE, TileX(), and TileY().
Referenced by CmdScrollViewport(), and StoryBookWindow::OnPageElementClick().
bool ScrollWindowTo | ( | int | x, |
int | y, | ||
int | z, | ||
Window * | w, | ||
bool | instant | ||
) |
Scrolls the viewport in a window to a given location.
x | Desired x location of the map to scroll to (world coordinate). |
y | Desired y location of the map to scroll to (world coordinate). |
z | Desired z location of the map to scroll to (world coordinate). Use -1 to scroll to the height of the map at the x, y location. |
w | Window containing the viewport. |
instant | Jump to the location instead of slowly moving to it. |
Definition at line 2469 of file viewport.cpp.
Referenced by ScrollWindowToTile().
Scrolls the viewport in a window to a given location.
tile | Desired tile to center on. |
w | Window containing the viewport. |
instant | Jump to the location instead of slowly moving to it. |
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().
void SetRedErrorSquare | ( | TileIndex | tile | ) |
Set a tile to display a red error square.
tile | Tile that should show the red error square. |
Definition at line 2524 of file viewport.cpp.
void SetTileSelectSize | ( | int | w, |
int | h | ||
) |
Highlight w by h tiles at the cursor.
w | Width of the highlighted tiles rectangle. |
h | Height of the highlighted tiles rectangle. |
Definition at line 2542 of file viewport.cpp.
Referenced by BuildRailStationWindow::OnPaint(), and ScenarioEditorLandscapeGenerationWindow::OnPaint().
void SetViewportCatchmentStation | ( | const Station * | st, |
bool | sel | ||
) |
Select or deselect station for coverage area highlight.
Selecting a station will deselect a town.
*st | Station in question |
sel | Select or deselect given station |
Definition at line 3618 of file viewport.cpp.
Referenced by BuildAirToolbarWindow::OnPlaceObjectAbort(), and BuildRailToolbarWindow::OnPlaceObjectAbort().
void SetViewportCatchmentTown | ( | const Town * | t, |
bool | sel | ||
) |
Select or deselect town for coverage area highlight.
Selecting a town will deselect a station.
*t | Town in question |
sel | Select or deselect given town |
Definition at line 3658 of file viewport.cpp.
void SetViewportCatchmentWaypoint | ( | const Waypoint * | wp, |
bool | sel | ||
) |
Select or deselect waypoint for coverage area highlight.
Selecting a waypoint will deselect a town.
*wp | Waypoint in question |
sel | Select or deselect given waypoint |
Definition at line 3638 of file viewport.cpp.
Referenced by BuildRailToolbarWindow::OnPlaceObjectAbort().
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 block is terminated by EndSpriteCombine.
You cannot nest "combined" blocks.
Definition at line 767 of file viewport.cpp.
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.
vp | Viewport that contains the (x, y) screen coordinate |
x | Screen x coordinate, distance in pixels from the left edge of viewport frame |
y | Screen y coordinate, distance in pixels from the top edge of viewport frame |
clamp_to_map | Clamp the coordinate outside of the map to the closest, non-void tile within the map |
Definition at line 435 of file viewport.cpp.
void UpdateViewportPosition | ( | Window * | w, |
uint32_t | delta_ms | ||
) |
Update the viewport position being displayed.
w | Window owning the viewport. |
Definition at line 1916 of file viewport.cpp.
References ViewportData::follow_vehicle, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), INVALID_VEHICLE, and Window::viewport.
Referenced by UpdateWindows().
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.
dpi | current viewport area |
small_from | Zoomlevel from when the small font should be used |
sign | sign position and dimension |
string_normal | String for normal and 2x zoom level |
string_small | String for 4x and 8x zoom level |
string_small_shadow | Shadow string for 4x and 8x zoom level; or #STR_NULL if no shadow |
colour | colour 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.