OpenTTD
viewport_func.h
Go to the documentation of this file.
1 /* $Id: viewport_func.h 27161 2015-02-22 14:42:34Z frosch $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef VIEWPORT_FUNC_H
13 #define VIEWPORT_FUNC_H
14 
15 #include "gfx_type.h"
16 #include "viewport_type.h"
17 #include "window_type.h"
18 #include "tile_type.h"
19 #include "station_type.h"
20 
21 static const int TILE_HEIGHT_STEP = 50;
22 
23 void SetSelectionRed(bool);
24 
25 void DeleteWindowViewport(Window *w);
26 void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom);
27 ViewPort *IsPtInWindowViewport(const Window *w, int x, int y);
28 Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y, bool clamp_to_map = true);
29 Point GetTileBelowCursor();
31 
32 void MarkAllViewportsDirty(int left, int top, int right, int bottom);
33 
35 void ZoomInOrOutToCursorWindow(bool in, Window * w);
36 Point GetTileZoomCenterWindow(bool in, Window * w);
37 void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out);
38 
45 static inline void MaxZoomInOut(ZoomStateChange how, Window *w)
46 {
47  while (DoZoomInOutWindow(how, w)) {};
48 }
49 
50 void OffsetGroundSprite(int x, int y);
51 
52 void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = NULL, int extra_offs_x = 0, int extra_offs_y = 0);
53 void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub = NULL, int extra_offs_x = 0, int extra_offs_y = 0);
54 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 = NULL);
55 void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = NULL, bool scale = true);
56 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);
57 
58 
59 void StartSpriteCombine();
60 void EndSpriteCombine();
61 
62 bool HandleViewportClicked(const ViewPort *vp, int x, int y);
63 void SetRedErrorSquare(TileIndex tile);
64 void SetTileSelectSize(int w, int h);
65 void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
66 
67 void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom);
68 
69 bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
70 bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
71 
72 void RebuildViewportOverlay(Window *w);
73 
74 bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
75 bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
76 
77 void UpdateAllVirtCoords();
78 
79 extern Point _tile_fract_coords;
80 
81 void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0);
82 
83 void MarkTileDirtyByTileOutsideMap(int x, int y);
84 
85 Point GetViewportStationMiddle(const ViewPort *vp, const Station *st);
86 
87 #endif /* VIEWPORT_FUNC_H */
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
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:506
Data about how and where to blit pixels.
Definition: gfx_type.h:156
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=NULL)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:688
bool ScrollMainWindowToTile(TileIndex tile, bool instant=false)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2268
Types related to windows.
void UpdateViewportPosition(Window *w)
Update the viewport position being displayed.
Definition: viewport.cpp:1787
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:220
Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y, bool clamp_to_map=true)
Translate screen coordinate in a viewport to a tile coordinate.
Definition: viewport.cpp:405
void MarkTileDirtyByTileOutsideMap(int x, int y)
Mark a (virtual) tile outside the map dirty for repaint.
Definition: viewport.cpp:1920
Types related to viewports.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant=false)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2257
Data structure for an opened window.
Definition: window_gui.h:271
Types related to stations.
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:616
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2295
void 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:1872
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:143
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:212
Location information about a sign as seen on the viewport.
Definition: viewport_type.h:48
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub=NULL, 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:581
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent=false, const SubSprite *sub=NULL, bool scale=true)
Add a child sprite to a parent sprite.
Definition: viewport.cpp:843
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
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:2222
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:45
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:1219
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset=0)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1904
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Definition: viewport_func.h:21
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:795
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub=NULL, int extra_offs_x=0, int extra_offs_y=0)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:604
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:24
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
bool ScrollMainWindowTo(int x, int y, int z=-1, bool instant=false)
Scrolls the main window to given coordinates.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2277
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:785
Used to only draw a part of the sprite.
Definition: gfx_type.h:219
Coordinates of a point in 2D.
ZoomStateChange
Directions of zooming.
Definition: viewport_type.h:62
ViewPort * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition: viewport.cpp:385
Types related to tiles.
Station data structure.
Definition: station_base.h:446
Types related to the graphics and/or input devices.