OpenTTD Source  20240917-master-g9ab0a47812
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 
20 static const int TILE_HEIGHT_STEP = 50;
21 
22 void SetSelectionRed(bool);
23 
24 void DeleteWindowViewport(Window *w);
25 void InitializeWindowViewport(Window *w, int x, int y, int width, int height, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
26 Viewport *IsPtInWindowViewport(const Window *w, int x, int y);
27 Point TranslateXYToTileCoord(const Viewport *vp, int x, int y, bool clamp_to_map = true);
28 Point GetTileBelowCursor();
29 void UpdateViewportPosition(Window *w, uint32_t delta_ms);
30 
31 bool MarkAllViewportsDirty(int left, int top, int right, int bottom);
32 
34 void ZoomInOrOutToCursorWindow(bool in, Window * w);
35 void ConstrainAllViewportsZoom();
36 Point GetTileZoomCenterWindow(bool in, Window * w);
37 void FixTitleGameZoom(int zoom_adjust = 0);
38 void HandleZoomMessage(Window *w, const Viewport *vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out);
39 
46 inline void MaxZoomInOut(ZoomStateChange how, Window *w)
47 {
48  while (DoZoomInOutWindow(how, w)) {};
49 }
50 
51 void OffsetGroundSprite(int x, int y);
52 
53 void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
54 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);
55 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);
56 void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, bool relative = true);
57 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);
58 
59 
60 void StartSpriteCombine();
61 void EndSpriteCombine();
62 
63 bool HandleViewportClicked(const Viewport *vp, int x, int y);
64 void SetRedErrorSquare(TileIndex tile);
65 void SetTileSelectSize(int w, int h);
66 void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
67 
68 void ViewportDoDraw(const Viewport *vp, int left, int top, int right, int bottom);
69 
70 bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
71 bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
72 
73 void RebuildViewportOverlay(Window *w);
74 
75 bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
76 bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
77 
78 void UpdateAllVirtCoords();
79 void ClearAllCachedNames();
80 
81 extern Point _tile_fract_coords;
82 
83 void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override);
84 
91 inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0)
92 {
93  MarkTileDirtyByTile(tile, bridge_level_offset, TileHeight(tile));
94 }
95 
96 Point GetViewportStationMiddle(const Viewport *vp, const Station *st);
97 
98 struct Station;
99 struct Waypoint;
100 struct Town;
101 
102 void SetViewportCatchmentStation(const Station *st, bool sel);
103 void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel);
104 void SetViewportCatchmentTown(const Town *t, bool sel);
105 void MarkCatchmentTilesDirty();
106 
107 template<class T>
108 void SetViewportCatchmentSpecializedStation(const T *st, bool sel);
109 
110 template<>
111 inline void SetViewportCatchmentSpecializedStation(const Station *st, bool sel)
112 {
114 }
115 
116 template<>
117 inline void SetViewportCatchmentSpecializedStation(const Waypoint *st, bool sel)
118 {
120 }
121 
122 #endif /* VIEWPORT_FUNC_H */
DrawGroundSprite
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:589
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2501
Station
Station data structure.
Definition: station_base.h:439
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SetRedErrorSquare
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2521
window_type.h
ScrollWindowTo
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2466
AddSortableSpriteToDraw
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:673
SetViewportCatchmentTown
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
Definition: viewport.cpp:3655
Waypoint
Representation of a waypoint.
Definition: waypoint_base.h:23
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
MaxZoomInOut
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:46
ViewportSign
Location information about a sign as seen on the viewport.
Definition: viewport_type.h:38
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:93
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:231
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:19
DrawGroundSpriteAt
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:566
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
SetViewportCatchmentWaypoint
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
Definition: viewport.cpp:3635
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
tile_map.h
AddChildSpriteScreen
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:829
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.
Definition: viewport.cpp:491
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:769
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant=false)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2512
MarkAllViewportsDirty
bool MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
Definition: viewport.cpp:2019
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2539
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3615
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:779
vehicle_type.h
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:222
UpdateViewportPosition
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
Definition: viewport.cpp:1913
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z=-1, bool instant=false)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:2080
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:2054
IsPtInWindowViewport
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition: viewport.cpp:408
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:601
Town
Town data structure.
Definition: town.h:54
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition: tile_map.h:29
TranslateXYToTileCoord
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:432
TILE_HEIGHT_STEP
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Definition: viewport_func.h:20
ViewportAddString
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.
Definition: viewport.cpp:1308
Window
Data structure for an opened window.
Definition: window_gui.h:276
viewport_type.h
gfx_type.h
ZoomStateChange
ZoomStateChange
Directions of zooming.
Definition: viewport_type.h:76
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.
Definition: viewport.cpp:219
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:16
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:157
station_type.h