OpenTTD Source 20250612-master-gb012d9e3dc
viewport_func.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef VIEWPORT_FUNC_H
11#define VIEWPORT_FUNC_H
12
13#include "gfx_type.h"
14#include "viewport_type.h"
15#include "window_type.h"
16#include "tile_map.h"
17#include "station_type.h"
18#include "vehicle_type.h"
19
20static const int TILE_HEIGHT_STEP = 50;
21
22void SetSelectionRed(bool);
23
24void InitializeWindowViewport(Window *w, int x, int y, int width, int height, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
25Viewport *IsPtInWindowViewport(const Window *w, int x, int y);
26Point TranslateXYToTileCoord(const Viewport &vp, int x, int y, bool clamp_to_map = true);
27Point GetTileBelowCursor();
28void UpdateViewportPosition(Window *w, uint32_t delta_ms);
29
30bool MarkAllViewportsDirty(int left, int top, int right, int bottom);
31
33void ZoomInOrOutToCursorWindow(bool in, Window * w);
34void ConstrainAllViewportsZoom();
35Point GetTileZoomCenterWindow(bool in, Window * w);
36void FixTitleGameZoom(int zoom_adjust = 0);
37void HandleZoomMessage(Window *w, const Viewport &vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out);
38
46{
47 while (DoZoomInOutWindow(how, w)) {};
48}
49
50void OffsetGroundSprite(int x, int y);
51
52void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
53void 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);
54void 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);
55void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, bool relative = true);
56std::string *ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour);
57
58
60void EndSpriteCombine();
61
62bool HandleViewportClicked(const Viewport &vp, int x, int y);
64void SetTileSelectSize(int w, int h);
65void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
66
67void ViewportDoDraw(const Viewport &vp, int left, int top, int right, int bottom);
68
69bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
70bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
71
72void RebuildViewportOverlay(Window *w);
73
74bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
75bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
76
78void ClearAllCachedNames();
79
80extern Point _tile_fract_coords;
81
82void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override);
83
90inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0)
91{
92 MarkTileDirtyByTile(tile, bridge_level_offset, TileHeight(tile));
93}
94
95Point GetViewportStationMiddle(const Viewport &vp, const Station *st);
96
97struct Station;
98struct Waypoint;
99struct Town;
100
101void SetViewportCatchmentStation(const Station *st, bool sel);
102void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel);
103void SetViewportCatchmentTown(const Town *t, bool sel);
104void MarkCatchmentTilesDirty();
105
106template <class T>
107void SetViewportCatchmentSpecializedStation(const T *st, bool sel);
108
109template <>
110inline void SetViewportCatchmentSpecializedStation(const Station *st, bool sel)
111{
113}
114
115template <>
116inline void SetViewportCatchmentSpecializedStation(const Waypoint *st, bool sel)
117{
119}
120
121#endif /* VIEWPORT_FUNC_H */
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
bool MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Types related to stations.
Data about how and where to blit pixels.
Definition gfx_type.h:158
Coordinates of a point in 2D.
Station data structure.
Used to only draw a part of the sprite.
Definition gfx_type.h:273
Town data structure.
Definition town.h:52
Location information about a sign as seen on the viewport.
Data structure for viewport, display of a part of the world.
Representation of a waypoint.
Data structure for an opened window.
Definition window_gui.h:273
Map writing/reading functions for tiles.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
Types related to vehicles.
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.
Definition viewport.cpp:663
std::string * ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour)
Add a string to draw in the current viewport.
bool ScrollMainWindowToTile(TileIndex tile, bool instant=false)
Scrolls the viewport of the main window to a given location.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition viewport.cpp:591
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition viewport.cpp:759
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.
Definition viewport.cpp:579
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.
Definition viewport.cpp:819
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
bool ScrollMainWindowTo(int x, int y, int z=-1, bool instant=false)
Scrolls the main window to given coordinates.
Point TranslateXYToTileCoord(const Viewport &vp, int x, int y, bool clamp_to_map=true)
Translate screen coordinate in a viewport to underlying tile coordinate.
Definition viewport.cpp:430
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition viewport.cpp:408
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition viewport.cpp:769
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
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.
Definition viewport.cpp:218
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.
Definition viewport.cpp:556
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:93
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.
Definition viewport.cpp:486
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Types related to viewports.
ZoomStateChange
Directions of zooming.
Types related to windows.
int WidgetID
Widget ID.
Definition window_type.h:20
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:16