OpenTTD Source: src/viewport_func.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef VIEWPORT_FUNC_H
11#define VIEWPORT_FUNC_H
12
13#include "gfx_type.h"
14#include "sprite.h"
15#include "viewport_type.h"
16#include "window_type.h"
17#include "tile_map.h"
18#include "station_type.h"
19#include "vehicle_type.h"
20
21 static const int TILE_HEIGHT_STEP = 50;
22
23void SetSelectionRed(bool);
24
25void 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();
29void UpdateViewportPosition(Window *w, uint32_t delta_ms);
30
31bool MarkAllViewportsDirty(int left, int top, int right, int bottom);
32
33bool DoZoomInOutWindow(ZoomStateChange how, Window *w);
34void ZoomInOrOutToCursorWindow(bool in, Window * w);
35void ConstrainAllViewportsZoom();
36 Point GetTileZoomCenterWindow(bool in, Window * w);
37void FixTitleGameZoom(int zoom_adjust = 0);
38void 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
51void OffsetGroundSprite(int x, int y);
52
53void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
54void 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);
55void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent = false, const SubSprite *sub = nullptr);
56void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, bool relative = true);
57std::string *ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour);
58
59inline void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, const Coord3D<int32_t> &world, const SpriteBounds &bounds, bool transparent = false, const SubSprite *sub = nullptr)
60{
61 AddSortableSpriteToDraw(image, pal, world.x, world.y, world.z, bounds, transparent, sub);
62}
63
64void StartSpriteCombine();
65void EndSpriteCombine();
66
67bool HandleViewportClicked(const Viewport &vp, int x, int y);
68void SetRedErrorSquare(TileIndex tile);
69void SetTileSelectSize(int w, int h);
70void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
71
72void ViewportDoDraw(const Viewport &vp, int left, int top, int right, int bottom);
73
74bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
75bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
76
77void RebuildViewportOverlay(Window *w);
78
79bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
80bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
81
82void UpdateAllVirtCoords();
83void ClearAllCachedNames();
84
85extern Point _tile_fract_coords;
86
87void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override);
88
95 inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0)
96{
97 MarkTileDirtyByTile(tile, bridge_level_offset, TileHeight(tile));
98}
99
100 Point GetViewportStationMiddle(const Viewport &vp, const Station *st);
101
102struct Station;
103struct Waypoint;
104struct Town;
105
106void SetViewportCatchmentStation(const Station *st, bool sel);
107void SetViewportStationRect(const Station *st, bool sel);
108void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel);
109void SetViewportWaypointRect(const Waypoint *wp, bool sel);
110void SetViewportCatchmentTown(const Town *t, bool sel);
111void MarkCatchmentTilesDirty();
112
113template <class T>
114void SetViewportCatchmentSpecializedStation(const T *st, bool sel);
115
116template <>
117inline void SetViewportCatchmentSpecializedStation(const Station *st, bool sel)
118{
119 SetViewportCatchmentStation(st, sel);
120}
121
122template <>
123inline void SetViewportCatchmentSpecializedStation(const Waypoint *st, bool sel)
124{
125 SetViewportCatchmentWaypoint(st, sel);
126}
127
128#endif /* VIEWPORT_FUNC_H */
EnumBitSet< ViewportStringFlag, uint8_t >
gfx_type.h
Types related to the graphics and/or input devices.
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
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:2094
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:2128
sprite.h
Base for drawing complex sprites.
station_type.h
Types related to stations.
Coord2D< int >
Coord3D
A coordinate with three dimensions.
Definition geometry_type.hpp:43
Coord3D::x
T x
X coordinate.
Definition geometry_type.hpp:44
Coord3D::y
T y
Y coordinate.
Definition geometry_type.hpp:45
Coord3D::z
T z
Z coordinate.
Definition geometry_type.hpp:46
DrawPixelInfo
Data about how and where to blit pixels.
Definition gfx_type.h:157
SpriteBounds
Definition sprite.h:18
Station
Station data structure.
Definition station_base.h:500
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SubSprite
Used to only draw a part of the sprite.
Definition gfx_type.h:278
Town
Town data structure.
Definition town.h:63
ViewportSign
Location information about a sign as seen on the viewport.
Definition viewport_type.h:47
Viewport
Data structure for viewport, display of a part of the world.
Definition viewport_type.h:31
Waypoint
Representation of a waypoint.
Definition waypoint_base.h:23
Window
Data structure for an opened window.
Definition window_gui.h:274
tile_map.h
Map writing/reading functions for tiles.
TileHeight
static uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
vehicle_type.h
Types related to vehicles.
ViewportAddString
std::string * ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour)
Add a string to draw in the current viewport.
Definition viewport.cpp:1330
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant=false)
Scrolls the viewport of the main window to a given location.
Definition viewport.cpp:2592
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition viewport.cpp:2619
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition viewport.cpp:591
SetViewportStationRect
void SetViewportStationRect(const Station *st, bool sel)
Select or deselect station for rectangle area highlight.
Definition viewport.cpp:3736
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition viewport.cpp:764
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:579
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:824
SetViewportCatchmentWaypoint
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
Definition viewport.cpp:3759
SetRedErrorSquare
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition viewport.cpp:2601
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z=-1, bool instant=false)
Scrolls the main window to given coordinates.
Definition smallmap_gui.cpp:2078
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:430
IsPtInWindowViewport
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition viewport.cpp:408
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:2546
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition viewport.cpp:774
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition afterload.cpp:220
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition viewport.cpp:3713
SetViewportCatchmentTown
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
Definition viewport.cpp:3805
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:218
SetViewportWaypointRect
void SetViewportWaypointRect(const Waypoint *wp, bool sel)
Select or deselect waypoint for rectangle area highlight.
Definition viewport.cpp:3782
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:556
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:93
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent=false, const SubSprite *sub=nullptr)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition viewport.cpp:663
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:486
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
Definition viewport.cpp:2581
TILE_HEIGHT_STEP
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Definition viewport_func.h:21
UpdateViewportPosition
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
Definition viewport.cpp:1988
MaxZoomInOut
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition viewport_func.h:46
viewport_type.h
Types related to viewports.
ZoomStateChange
ZoomStateChange
Directions of zooming.
Definition viewport_type.h:80
window_type.h
Types related to windows.
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20