OpenTTD Source: src/viewport_func.h Source File

OpenTTD Source 1.11.0-RC1

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
19 static const int TILE_HEIGHT_STEP = 50;
20
21 void SetSelectionRed(bool);
22
23 void DeleteWindowViewport(Window *w);
24 void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom);
25 Viewport *IsPtInWindowViewport(const Window *w, int x, int y);
26 Point TranslateXYToTileCoord(const Viewport *vp, int x, int y, bool clamp_to_map = true);
27 Point GetTileBelowCursor();
28 void UpdateViewportPosition(Window *w);
29
30 bool MarkAllViewportsDirty(int left, int top, int right, int bottom);
31
32 bool DoZoomInOutWindow(ZoomStateChange how, Window *w);
33 void ZoomInOrOutToCursorWindow(bool in, Window * w);
34 Point GetTileZoomCenterWindow(bool in, Window * w);
35 void FixTitleGameZoom();
36 void HandleZoomMessage(Window *w, const Viewport *vp, byte widget_zoom_in, byte widget_zoom_out);
37
44 static inline void MaxZoomInOut(ZoomStateChange how, Window *w)
45 {
46 while (DoZoomInOutWindow(how, w)) {};
47 }
48
49 void OffsetGroundSprite(int x, int y);
50
51 void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
52 void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
53 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);
54 void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true);
55 void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2 = 0, Colours colour = INVALID_COLOUR);
56
57
58 void StartSpriteCombine();
59 void EndSpriteCombine();
60
61 bool HandleViewportClicked(const Viewport *vp, int x, int y);
62 void SetRedErrorSquare(TileIndex tile);
63 void SetTileSelectSize(int w, int h);
64 void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
65
66 void ViewportDoDraw(const Viewport *vp, int left, int top, int right, int bottom);
67
68 bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
69 bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
70
71 void RebuildViewportOverlay(Window *w);
72
73 bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
74 bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
75
76 void UpdateAllVirtCoords();
77 void ClearAllCachedNames();
78
79 extern Point _tile_fract_coords;
80
81 void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override);
82
89 static inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0)
90 {
91 MarkTileDirtyByTile(tile, bridge_level_offset, TileHeight(tile));
92 }
93
94 Point GetViewportStationMiddle(const Viewport *vp, const Station *st);
95
96 struct Station;
97 struct Town;
98
99 void SetViewportCatchmentStation(const Station *st, bool sel);
100 void SetViewportCatchmentTown(const Town *t, bool sel);
101
102 #endif /* VIEWPORT_FUNC_H */
MaxZoomInOut
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:44
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
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:576
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2432
Station
Station data structure.
Definition: station_base.h:450
SetRedErrorSquare
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2452
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:2397
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:660
SetViewportCatchmentTown
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
Definition: viewport.cpp:3544
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
InitializeWindowViewport
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom)
Initialize viewport of the window for use.
Definition: viewport.cpp:222
ViewportSign
Location information about a sign as seen on the viewport.
Definition: viewport_type.h:46
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:91
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:222
UpdateViewportPosition
void UpdateViewportPosition(Window *w)
Update the viewport position being displayed.
Definition: viewport.cpp:1859
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
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)
Add a child sprite to a parent sprite.
Definition: viewport.cpp:814
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
HandleZoomMessage
void HandleZoomMessage(Window *w, const Viewport *vp, byte widget_zoom_in, byte widget_zoom_out)
Update the status of the zoom-buttons according to the zoom-level of the viewport.
Definition: viewport.cpp:478
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:756
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant=false)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2443
DrawGroundSpriteAt
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 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:553
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:1948
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2470
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3522
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:766
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:217
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z=-1, bool instant=false)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:1869
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:1985
IsPtInWindowViewport
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition: viewport.cpp:395
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:588
Town
Town data structure.
Definition: town.h:50
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:419
TILE_HEIGHT_STEP
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Definition: viewport_func.h:19
Window
Data structure for an opened window.
Definition: window_gui.h:276
ViewportAddString
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2=0, Colours colour=INVALID_COLOUR)
Add a string to draw in the viewport.
Definition: viewport.cpp:1289
viewport_type.h
gfx_type.h
ZoomStateChange
ZoomStateChange
Directions of zooming.
Definition: viewport_type.h:80
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
station_type.h