2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-01-09 09:45:45 +00:00
|
|
|
/** @file viewport_func.h Functions related to (drawing on) viewports. */
|
|
|
|
|
|
|
|
#ifndef VIEWPORT_FUNC_H
|
|
|
|
#define VIEWPORT_FUNC_H
|
|
|
|
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "gfx_type.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_type.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "window_type.h"
|
2019-01-13 19:56:10 +00:00
|
|
|
#include "tile_map.h"
|
2013-05-19 14:49:25 +00:00
|
|
|
#include "station_type.h"
|
2015-08-02 18:37:42 +00:00
|
|
|
#include "vehicle_base.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2018-05-10 22:10:04 +00:00
|
|
|
struct TileInfo;
|
2022-11-09 22:24:31 +00:00
|
|
|
struct ViewportDrawerDynamic;
|
2018-05-10 22:10:04 +00:00
|
|
|
|
2010-05-07 20:39:00 +00:00
|
|
|
static const int TILE_HEIGHT_STEP = 50; ///< One Z unit tile height difference is displayed as 50m.
|
|
|
|
|
2008-01-09 09:45:45 +00:00
|
|
|
void SetSelectionRed(bool);
|
2023-06-05 18:37:14 +00:00
|
|
|
void SetSelectionPalette(PaletteID);
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2020-10-01 20:17:06 +00:00
|
|
|
void ClearViewportCache(Viewport *vp);
|
2020-10-13 20:33:59 +00:00
|
|
|
void ClearViewportLandPixelCache(Viewport *vp);
|
2020-10-01 20:17:06 +00:00
|
|
|
void ClearViewportCaches();
|
2008-01-09 09:45:45 +00:00
|
|
|
void DeleteWindowViewport(Window *w);
|
2024-01-07 16:41:53 +00:00
|
|
|
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32_t follow_flags, ZoomLevel zoom);
|
2020-06-29 01:38:29 +00:00
|
|
|
Viewport *IsPtInWindowViewport(const Window *w, int x, int y);
|
|
|
|
Point TranslateXYToTileCoord(const Viewport *vp, int x, int y, bool clamp_to_map = true);
|
2008-01-09 09:45:45 +00:00
|
|
|
Point GetTileBelowCursor();
|
2023-09-18 19:25:05 +00:00
|
|
|
void UpdateNextViewportPosition(Window *w);
|
|
|
|
void ApplyNextViewportPosition(Window *w);
|
2020-08-27 17:31:09 +00:00
|
|
|
void UpdateViewportSizeZoom(Viewport *vp);
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2020-10-01 17:50:31 +00:00
|
|
|
void MarkViewportDirty(Viewport * const vp, int left, int top, int right, int bottom, ViewportMarkDirtyFlags flags);
|
|
|
|
void MarkAllViewportsDirty(int left, int top, int right, int bottom, ViewportMarkDirtyFlags flags = VMDF_NONE);
|
2015-08-02 18:37:42 +00:00
|
|
|
void MarkAllViewportMapsDirty(int left, int top, int right, int bottom);
|
2020-10-01 22:11:15 +00:00
|
|
|
void MarkAllViewportMapLandscapesDirty();
|
|
|
|
void MarkWholeNonMapViewportsDirty();
|
2020-09-18 17:58:16 +00:00
|
|
|
void MarkAllViewportOverlayStationLinksDirty(const Station *st);
|
2020-10-01 17:50:31 +00:00
|
|
|
void MarkViewportLineDirty(Viewport * const vp, const Point from_pt, const Point to_pt, const int block_radius, ViewportMarkDirtyFlags flags);
|
2020-10-01 22:11:15 +00:00
|
|
|
void MarkTileLineDirty(const TileIndex from_tile, const TileIndex to_tile, ViewportMarkDirtyFlags flags);
|
2023-05-06 18:14:39 +00:00
|
|
|
void MarkDirtyFocusedRoutePaths(const Vehicle *veh);
|
2023-05-07 10:48:17 +00:00
|
|
|
void CheckMarkDirtyViewportRoutePaths(const Vehicle *veh);
|
|
|
|
void CheckMarkDirtyViewportRoutePaths();
|
|
|
|
void AddFixedViewportRoutePath(VehicleID veh);
|
|
|
|
void RemoveFixedViewportRoutePath(VehicleID veh);
|
|
|
|
void ChangeFixedViewportRoutePath(VehicleID from, VehicleID to);
|
2009-07-08 08:30:35 +00:00
|
|
|
|
2010-05-13 08:56:01 +00:00
|
|
|
bool DoZoomInOutWindow(ZoomStateChange how, Window *w);
|
2008-01-09 09:45:45 +00:00
|
|
|
void ZoomInOrOutToCursorWindow(bool in, Window * w);
|
2023-01-29 08:28:24 +00:00
|
|
|
void ConstrainAllViewportsZoom();
|
2008-01-09 09:45:45 +00:00
|
|
|
Point GetTileZoomCenterWindow(bool in, Window * w);
|
2021-04-09 18:39:56 +00:00
|
|
|
void FixTitleGameZoom(int zoom_adjust = 0);
|
2023-12-29 19:11:59 +00:00
|
|
|
void HandleZoomMessage(Window *w, const Viewport *vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out);
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2010-11-20 14:15:02 +00:00
|
|
|
/**
|
|
|
|
* Zoom a viewport as far as possible in the given direction.
|
|
|
|
* @param how Zooming direction.
|
|
|
|
* @param w Window owning the viewport.
|
|
|
|
* @pre \a how should not be #ZOOM_NONE.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void MaxZoomInOut(ZoomStateChange how, Window *w)
|
2008-01-09 09:45:45 +00:00
|
|
|
{
|
|
|
|
while (DoZoomInOutWindow(how, w)) {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffsetGroundSprite(int x, int y);
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
|
2024-01-07 16:41:53 +00:00
|
|
|
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);
|
2019-04-10 21:07:06 +00:00
|
|
|
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);
|
2022-12-28 16:01:23 +00:00
|
|
|
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, ChildScreenSpritePositionMode position_mode = ChildScreenSpritePositionMode::Relative);
|
2024-01-07 16:41:53 +00:00
|
|
|
void ViewportAddString(ViewportDrawerDynamic *vdd, const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64_t params_1, uint64_t params_2 = 0, Colours colour = INVALID_COLOUR);
|
2008-01-09 09:45:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
void StartSpriteCombine();
|
|
|
|
void EndSpriteCombine();
|
|
|
|
|
2021-02-05 11:56:08 +00:00
|
|
|
enum HandleViewportClickedResult {
|
|
|
|
HVCR_DENY,
|
|
|
|
HVCR_SCROLL_ONLY,
|
|
|
|
HVCR_ALLOW,
|
|
|
|
};
|
|
|
|
|
2015-08-02 18:37:42 +00:00
|
|
|
bool HandleViewportDoubleClicked(Window *w, int x, int y);
|
2021-02-05 11:56:08 +00:00
|
|
|
HandleViewportClickedResult HandleViewportClicked(const Viewport *vp, int x, int y, bool double_click);
|
2008-01-09 09:45:45 +00:00
|
|
|
void SetRedErrorSquare(TileIndex tile);
|
|
|
|
void SetTileSelectSize(int w, int h);
|
|
|
|
void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
void ViewportDoDraw(Viewport *vp, int left, int top, int right, int bottom, uint8_t display_flags);
|
2022-11-09 22:24:31 +00:00
|
|
|
void ViewportDoDrawProcessAllPending();
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2010-10-23 20:39:21 +00:00
|
|
|
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant = false);
|
2009-03-15 15:25:18 +00:00
|
|
|
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2018-05-26 01:15:51 +00:00
|
|
|
void UpdateActiveScrollingViewport(Window *w);
|
|
|
|
|
2018-05-26 08:07:37 +00:00
|
|
|
void RebuildViewportOverlay(Window *w, bool incremental);
|
2013-05-19 14:49:25 +00:00
|
|
|
|
2008-01-09 09:45:45 +00:00
|
|
|
bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
|
2009-03-15 15:25:18 +00:00
|
|
|
bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2009-12-13 19:33:07 +00:00
|
|
|
void UpdateAllVirtCoords();
|
2019-05-12 17:03:57 +00:00
|
|
|
void ClearAllCachedNames();
|
2009-12-13 19:33:07 +00:00
|
|
|
|
2008-01-09 09:45:45 +00:00
|
|
|
extern Point _tile_fract_coords;
|
|
|
|
|
2020-10-01 17:50:31 +00:00
|
|
|
void MarkTileDirtyByTile(const TileIndex tile, ViewportMarkDirtyFlags flags, int bridge_level_offset, int tile_height_override);
|
2011-02-07 22:29:47 +00:00
|
|
|
|
2019-01-13 19:56:10 +00:00
|
|
|
/**
|
|
|
|
* Mark a tile given by its index dirty for repaint.
|
|
|
|
* @param tile The tile to mark dirty.
|
2020-10-01 17:50:31 +00:00
|
|
|
* @param flags To tell if an update is relevant or not (for example, animations in map mode are not).
|
2019-01-13 19:56:10 +00:00
|
|
|
* @param bridge_level_offset Height of bridge on tile to also mark dirty. (Height level relative to north corner.)
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2024-01-07 15:00:16 +00:00
|
|
|
inline void MarkTileDirtyByTile(TileIndex tile, ViewportMarkDirtyFlags flags = VMDF_NONE, int bridge_level_offset = 0)
|
2019-01-13 19:56:10 +00:00
|
|
|
{
|
2020-10-01 17:50:31 +00:00
|
|
|
MarkTileDirtyByTile(tile, flags, bridge_level_offset, TileHeight(tile));
|
2019-01-13 19:56:10 +00:00
|
|
|
}
|
2014-09-21 17:27:37 +00:00
|
|
|
|
2020-10-01 17:50:31 +00:00
|
|
|
void MarkTileGroundDirtyByTile(TileIndex tile, ViewportMarkDirtyFlags flags);
|
2020-02-20 00:16:51 +00:00
|
|
|
|
2020-10-01 22:11:15 +00:00
|
|
|
void ChangeRenderMode(Viewport *vp, bool down);
|
2015-08-02 18:37:42 +00:00
|
|
|
|
2020-06-29 01:38:29 +00:00
|
|
|
Point GetViewportStationMiddle(const Viewport *vp, const Station *st);
|
2013-05-19 14:49:25 +00:00
|
|
|
|
2015-08-02 18:37:42 +00:00
|
|
|
void ShowTooltipForTile(Window *w, const TileIndex tile);
|
|
|
|
|
2020-03-02 01:49:15 +00:00
|
|
|
void ViewportMapStoreTunnel(const TileIndex tile, const TileIndex tile_south, const int tunnel_z, const bool insert_sorted);
|
2015-11-11 19:18:32 +00:00
|
|
|
void ViewportMapClearTunnelCache();
|
2020-03-02 01:49:15 +00:00
|
|
|
void ViewportMapInvalidateTunnelCacheByTile(const TileIndex tile, const Axis axis);
|
|
|
|
void ViewportMapBuildTunnelCache();
|
2015-11-11 19:18:32 +00:00
|
|
|
|
2018-05-10 22:10:04 +00:00
|
|
|
void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal);
|
2022-12-26 22:29:51 +00:00
|
|
|
void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part, int extra_offs_x = 0, int extra_offs_y = 0, const SubSprite *sub = nullptr);
|
2018-05-10 22:10:04 +00:00
|
|
|
|
2023-05-25 21:34:54 +00:00
|
|
|
struct Waypoint;
|
2019-07-08 15:19:07 +00:00
|
|
|
struct Town;
|
2022-06-11 22:29:37 +00:00
|
|
|
struct TraceRestrictProgram;
|
2019-02-22 18:14:06 +00:00
|
|
|
void SetViewportCatchmentStation(const Station *st, bool sel);
|
2023-05-25 21:34:54 +00:00
|
|
|
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel);
|
2019-03-30 16:59:43 +00:00
|
|
|
void SetViewportCatchmentTown(const Town *t, bool sel);
|
2022-06-11 22:29:37 +00:00
|
|
|
void SetViewportCatchmentTraceRestrictProgram(const TraceRestrictProgram *prog, bool sel);
|
2019-02-22 18:14:06 +00:00
|
|
|
|
2023-05-25 21:34:54 +00:00
|
|
|
template<class T>
|
|
|
|
void SetViewportCatchmentSpecializedStation(const T *st, bool sel);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void SetViewportCatchmentSpecializedStation(const Station *st, bool sel)
|
|
|
|
{
|
|
|
|
SetViewportCatchmentStation(st, sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void SetViewportCatchmentSpecializedStation(const Waypoint *st, bool sel)
|
|
|
|
{
|
|
|
|
SetViewportCatchmentWaypoint(st, sel);
|
|
|
|
}
|
|
|
|
|
2020-10-01 17:50:31 +00:00
|
|
|
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height, ViewportMarkDirtyFlags flags = VMDF_NONE);
|
|
|
|
void MarkBridgeDirty(TileIndex tile, ViewportMarkDirtyFlags flags = VMDF_NONE);
|
|
|
|
void MarkBridgeOrTunnelDirty(TileIndex tile, ViewportMarkDirtyFlags flags = VMDF_NONE);
|
|
|
|
void MarkBridgeOrTunnelDirtyOnReservationChange(TileIndex tile, ViewportMarkDirtyFlags flags = VMDF_NONE);
|
|
|
|
|
2023-06-24 22:29:44 +00:00
|
|
|
bool IsViewportMouseHoverActive();
|
|
|
|
|
2008-01-09 09:45:45 +00:00
|
|
|
#endif /* VIEWPORT_FUNC_H */
|