OpenTTD
viewport_func.h
Go to the documentation of this file.
1 /* $Id$ */
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_map.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 FixTitleGameZoom();
38 void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out);
39 
46 static 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 = NULL, int extra_offs_x = 0, int extra_offs_y = 0);
54 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);
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 = NULL);
56 void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = NULL, bool scale = true);
57 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);
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 
80 extern Point _tile_fract_coords;
81 
82 void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override);
83 
90 static inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0)
91 {
92  MarkTileDirtyByTile(tile, bridge_level_offset, TileHeight(tile));
93 }
94 
95 Point GetViewportStationMiddle(const ViewPort *vp, const Station *st);
96 
97 #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:472
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:654
bool ScrollMainWindowToTile(TileIndex tile, bool instant=false)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2133
Types related to windows.
void UpdateViewportPosition(Window *w)
Update the viewport position being displayed.
Definition: viewport.cpp:1667
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:219
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:413
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:2122
Data structure for an opened window.
Definition: window_gui.h:278
Types related to stations.
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:582
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2160
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:1752
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:144
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:216
Location information about a sign as seen on the viewport.
Definition: viewport_type.h:48
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:1785
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:547
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:809
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:2087
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:46
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:1185
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:761
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:570
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:2142
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:751
Used to only draw a part of the sprite.
Definition: gfx_type.h:219
Coordinates of a point in 2D.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:31
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:389
Map writing/reading functions for tiles.
Station data structure.
Definition: station_base.h:446
Types related to the graphics and/or input devices.