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/>.
8 /** @file viewport_func.h Functions related to (drawing on) viewports. */
10 #ifndef VIEWPORT_FUNC_H
11 #define VIEWPORT_FUNC_H
14 #include "viewport_type.h"
15 #include "window_type.h"
17 #include "station_type.h"
18 #include "vehicle_type.h"
20 static const int TILE_HEIGHT_STEP
= 50; ///< One Z unit tile height difference is displayed as 50m.
22 void SetSelectionRed(bool);
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
);
31 bool MarkAllViewportsDirty(int left
, int top
, int right
, int bottom
);
33 bool DoZoomInOutWindow(ZoomStateChange how
, Window
*w
);
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
);
41 * Zoom a viewport as far as possible in the given direction.
42 * @param how Zooming direction.
43 * @param w Window owning the viewport.
44 * @pre \a how should not be #ZOOM_NONE.
46 inline void MaxZoomInOut(ZoomStateChange how
, Window
*w
)
48 while (DoZoomInOutWindow(how
, w
)) {};
51 void OffsetGroundSprite(int x
, int y
);
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
);
60 void StartSpriteCombine();
61 void EndSpriteCombine();
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
);
68 void ViewportDoDraw(const Viewport
*vp
, int left
, int top
, int right
, int bottom
);
70 bool ScrollWindowToTile(TileIndex tile
, Window
*w
, bool instant
= false);
71 bool ScrollWindowTo(int x
, int y
, int z
, Window
*w
, bool instant
= false);
73 void RebuildViewportOverlay(Window
*w
);
75 bool ScrollMainWindowToTile(TileIndex tile
, bool instant
= false);
76 bool ScrollMainWindowTo(int x
, int y
, int z
= -1, bool instant
= false);
78 void UpdateAllVirtCoords();
79 void ClearAllCachedNames();
81 extern Point _tile_fract_coords
;
83 void MarkTileDirtyByTile(TileIndex tile
, int bridge_level_offset
, int tile_height_override
);
86 * Mark a tile given by its index dirty for repaint.
87 * @param tile The tile to mark dirty.
88 * @param bridge_level_offset Height of bridge on tile to also mark dirty. (Height level relative to north corner.)
91 inline void MarkTileDirtyByTile(TileIndex tile
, int bridge_level_offset
= 0)
93 MarkTileDirtyByTile(tile
, bridge_level_offset
, TileHeight(tile
));
96 Point
GetViewportStationMiddle(const Viewport
*vp
, const Station
*st
);
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();
108 void SetViewportCatchmentSpecializedStation(const T
*st
, bool sel
);
111 inline void SetViewportCatchmentSpecializedStation(const Station
*st
, bool sel
)
113 SetViewportCatchmentStation(st
, sel
);
117 inline void SetViewportCatchmentSpecializedStation(const Waypoint
*st
, bool sel
)
119 SetViewportCatchmentWaypoint(st
, sel
);
122 #endif /* VIEWPORT_FUNC_H */