Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / gfx_func.h
blob96811587680f33f342e5ca26cba934f964c2e489
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 */
8 /** @file gfx_func.h Functions related to the gfx engine. */
10 /**
11 * @defgroup dirty Dirty
13 * Handles the repaint of some part of the screen.
15 * Some places in the code are called functions which makes something "dirty".
16 * This has nothing to do with making a Tile or Window darker or less visible.
17 * This term comes from memory caching and is used to define an object must
18 * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever)
19 * are changed which are so extensive the object must be repaint its marked
20 * as "dirty". The video driver repaint this object instead of the whole screen
21 * (this is btw. also possible if needed). This is used to avoid a
22 * flickering of the screen by the video driver constantly repainting it.
24 * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This
25 * rectangle defines the area on the screen which must be repaint. If a new object
26 * needs to be repainted this rectangle is extended to 'catch' the object on the
27 * screen. At some point (which is normally uninteresting for patch writers) this
28 * rectangle is send to the video drivers method
29 * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some
30 * later point (which is uninteresting, too) the video driver
31 * repaints all these saved rectangle instead of the whole screen and drop the
32 * rectangle information. Then a new round begins by marking objects "dirty".
34 * @see VideoDriver::MakeDirty
35 * @see _invalid_rect
36 * @see _screen
40 #ifndef GFX_FUNC_H
41 #define GFX_FUNC_H
43 #include "gfx_type.h"
44 #include "strings_type.h"
45 #include "string_type.h"
47 void GameLoop();
49 void CreateConsole();
51 extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down
52 extern bool _fullscreen;
53 extern byte _support8bpp;
54 extern CursorVars _cursor;
55 extern bool _ctrl_pressed; ///< Is Ctrl pressed?
56 extern bool _shift_pressed; ///< Is Shift pressed?
57 extern uint16_t _game_speed;
59 extern bool _left_button_down;
60 extern bool _left_button_clicked;
61 extern bool _right_button_down;
62 extern bool _right_button_clicked;
64 extern DrawPixelInfo _screen;
65 extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
67 extern std::vector<Dimension> _resolutions;
68 extern Dimension _cur_resolution;
69 extern Palette _cur_palette; ///< Current palette
71 void HandleToolbarHotkey(int hotkey);
72 void HandleKeypress(uint keycode, char32_t key);
73 void HandleTextInput(const char *str, bool marked = false, const char *caret = nullptr, const char *insert_location = nullptr, const char *replacement_end = nullptr);
74 void HandleCtrlChanged();
75 void HandleMouseEvents();
76 void UpdateWindows();
77 void ChangeGameSpeed(bool enable_fast_forward);
79 void DrawMouseCursor();
80 void ScreenSizeChanged();
81 void GameSizeChanged();
82 bool AdjustGUIZoom(bool automatic);
83 void UndrawMouseCursor();
85 void RedrawScreenRect(int left, int top, int right, int bottom);
86 void GfxScroll(int left, int top, int width, int height, int xo, int yo);
88 Dimension GetSpriteSize(SpriteID sprid, Point *offset = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
89 Dimension GetScaledSpriteSize(SpriteID sprid); /* widget.cpp */
90 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr);
91 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
92 void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align); /* widget.cpp */
93 std::unique_ptr<uint32_t[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = ZOOM_LVL_GUI);
95 int DrawString(int left, int right, int top, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
96 int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
97 int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
98 int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
100 void DrawCharCentered(char32_t c, const Rect &r, TextColour colour);
102 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
103 void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE);
104 void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0);
105 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
106 void DrawRectOutline(const Rect &r, int colour, int width = 1, int dash = 0);
108 /* Versions of DrawString/DrawStringMultiLine that accept a Rect instead of separate left, right, top and bottom parameters. */
109 inline int DrawString(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL)
111 return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
114 inline int DrawString(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL)
116 return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
119 inline int DrawStringMultiLine(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL)
121 return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
124 inline int DrawStringMultiLine(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL)
126 return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
129 inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FILLRECT_OPAQUE)
131 GfxFillRect(r.left, r.top, r.right, r.bottom, colour, mode);
134 Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize = FS_NORMAL);
135 Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize = FS_NORMAL);
136 uint GetStringListWidth(const StringID *list, FontSize fontsize = FS_NORMAL);
137 int GetStringHeight(std::string_view str, int maxw, FontSize fontsize = FS_NORMAL);
138 int GetStringHeight(StringID str, int maxw);
139 int GetStringLineCount(StringID str, int maxw);
140 Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
141 Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion);
142 void LoadStringWidthTable(bool monospace = false);
143 Point GetCharPosInString(std::string_view str, const char *ch, FontSize start_fontsize = FS_NORMAL);
144 ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize = FS_NORMAL);
146 void DrawDirtyBlocks();
147 void AddDirtyBlock(int left, int top, int right, int bottom);
148 void MarkWholeScreenDirty();
150 void CheckBlitter();
152 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
154 inline bool FillDrawPixelInfo(DrawPixelInfo *n, const Rect &r)
156 return FillDrawPixelInfo(n, r.left, r.top, r.Width(), r.Height());
160 * Determine where to draw a centred object inside a widget.
161 * @param min The top or left coordinate.
162 * @param max The bottom or right coordinate.
163 * @param size The height or width of the object to draw.
164 * @return Offset of where to start drawing the object.
166 inline int CenterBounds(int min, int max, int size)
168 return (min + max - size + 1) / 2;
171 /* window.cpp */
172 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
174 void SetMouseCursorBusy(bool busy);
175 void SetMouseCursor(CursorID cursor, PaletteID pal);
176 void SetAnimatedMouseCursor(const AnimCursor *table);
177 void CursorTick();
178 void UpdateCursorSize();
179 bool ChangeResInGame(int w, int h);
180 void SortResolutions();
181 bool ToggleFullScreen(bool fs);
183 /* gfx.cpp */
184 byte GetCharacterWidth(FontSize size, char32_t key);
185 byte GetDigitWidth(FontSize size = FS_NORMAL);
186 void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
188 int GetCharacterHeight(FontSize size);
190 extern DrawPixelInfo *_cur_dpi;
192 #endif /* GFX_FUNC_H */