Rearrange storage of reserved tracks for railway tiles
[openttd/fttd.git] / src / gfx_func.h
blob69d2e4570092a5766ecb74a8587c99c9d4eeebce
1 /* $Id$ */
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 */
10 /** @file gfx_func.h Functions related to the gfx engine. */
12 /**
13 * @defgroup dirty Dirty
15 * Handles the repaint of some part of the screen.
17 * Some places in the code are called functions which makes something "dirty".
18 * This has nothing to do with making a Tile or Window darker or less visible.
19 * This term comes from memory caching and is used to define an object must
20 * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever)
21 * are changed which are so extensive the object must be repaint its marked
22 * as "dirty". The video driver repaint this object instead of the whole screen
23 * (this is btw. also possible if needed). This is used to avoid a
24 * flickering of the screen by the video driver constantly repainting it.
26 * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This
27 * rectangle defines the area on the screen which must be repaint. If a new object
28 * needs to be repainted this rectangle is extended to 'catch' the object on the
29 * screen. At some point (which is normally uninteresting for patch writers) this
30 * rectangle is send to the video drivers method
31 * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some
32 * later point (which is uninteresting, too) the video driver
33 * repaints all these saved rectangle instead of the whole screen and drop the
34 * rectangle informations. Then a new round begins by marking objects "dirty".
36 * @see VideoDriver::MakeDirty
37 * @see _invalid_rect
38 * @see _screen
42 #ifndef GFX_FUNC_H
43 #define GFX_FUNC_H
45 #include "gfx_type.h"
46 #include "strings_type.h"
47 #include "string_type.h"
49 void GameLoop();
51 void CreateConsole();
53 extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down
54 extern bool _fullscreen;
55 extern CursorVars _cursor;
56 extern bool _ctrl_pressed; ///< Is Ctrl pressed?
57 extern bool _shift_pressed; ///< Is Shift pressed?
58 extern byte _fast_forward;
60 extern bool _left_button_down;
61 extern bool _left_button_clicked;
62 extern bool _right_button_down;
63 extern bool _right_button_clicked;
65 extern DrawPixelInfo _screen;
66 extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
68 extern int _num_resolutions;
69 extern Dimension _resolutions[32];
70 extern Dimension _cur_resolution;
71 extern Palette _cur_palette; ///< Current palette
73 void HandleKeypress(uint keycode, WChar key);
74 void HandleTextInput(const char *str, bool marked = false, const char *caret = NULL, const char *insert_location = NULL, const char *replacement_end = NULL);
75 void HandleCtrlChanged();
76 void HandleMouseEvents();
77 void CSleep(int milliseconds);
78 void UpdateWindows();
80 void DrawMouseCursor();
81 void ScreenSizeChanged();
82 void GameSizeChanged();
83 void UndrawMouseCursor();
85 /** Size of the buffer used for drawing strings. */
86 static const int DRAW_STRING_BUFFER = 2048;
88 void RedrawScreenRect(int left, int top, int right, int bottom);
89 void GfxScroll(int left, int top, int width, int height, int xo, int yo);
91 Dimension GetSpriteSize(SpriteID sprid, Point *offset = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
92 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
93 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
95 /** How to align the to-be drawn text. */
96 enum StringAlignment {
97 SA_LEFT = 0 << 0, ///< Left align the text.
98 SA_HOR_CENTER = 1 << 0, ///< Horizontally center the text.
99 SA_RIGHT = 2 << 0, ///< Right align the text (must be a single bit).
100 SA_HOR_MASK = 3 << 0, ///< Mask for horizontal alignment.
102 SA_TOP = 0 << 2, ///< Top align the text.
103 SA_VERT_CENTER = 1 << 2, ///< Vertically center the text.
104 SA_BOTTOM = 2 << 2, ///< Bottom align the text.
105 SA_VERT_MASK = 3 << 2, ///< Mask for vertical alignment.
107 SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically.
109 SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages.
111 DECLARE_ENUM_AS_BIT_SET(StringAlignment)
113 int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
114 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);
115 int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
116 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);
118 void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
120 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
121 void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0);
122 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
124 Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
125 Dimension GetStringBoundingBox(StringID strid);
126 int GetStringHeight(const char *str, int maxw, FontSize fontsize = FS_NORMAL);
127 int GetStringHeight(StringID str, int maxw);
128 int GetStringLineCount(StringID str, int maxw);
129 Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
130 Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion);
131 void LoadStringWidthTable(bool monospace = false);
132 Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize = FS_NORMAL);
133 const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize = FS_NORMAL);
135 void DrawDirtyBlocks();
136 void SetDirtyBlocks(int left, int top, int right, int bottom);
137 void MarkWholeScreenDirty();
139 void GfxInitPalettes();
141 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
143 /* window.cpp */
144 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
146 void SetMouseCursor(CursorID cursor, PaletteID pal);
147 void SetAnimatedMouseCursor(const AnimCursor *table);
148 void CursorTick();
149 void UpdateCursorSize();
150 bool ChangeResInGame(int w, int h);
151 void SortResolutions(int count);
152 bool ToggleFullScreen(bool fs);
154 /* gfx.cpp */
155 byte GetCharacterWidth(FontSize size, uint32 key);
156 byte GetDigitWidth(FontSize size = FS_NORMAL);
157 void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
159 int GetCharacterHeight(FontSize size);
161 /** Height of characters in the small (#FS_SMALL) font. */
162 #define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
164 /** Height of characters in the normal (#FS_NORMAL) font. */
165 #define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
167 /** Height of characters in the large (#FS_LARGE) font. */
168 #define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
170 /** Height of characters in the large (#FS_MONO) font. */
171 #define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
173 extern DrawPixelInfo *_cur_dpi;
175 TextColour GetContrastColour(uint8 background);
178 * All 16 colour gradients
179 * 8 colours per gradient from darkest (0) to lightest (7)
181 extern byte _colour_gradient[COLOUR_END][8];
183 extern bool _palette_remap_grf[];
186 * Return the colour for a particular greyscale level.
187 * @param level Intensity, 0 = black, 15 = white
188 * @return colour
190 #define GREY_SCALE(level) (level)
192 static const uint8 PC_BLACK = GREY_SCALE(1); ///< Black palette colour.
193 static const uint8 PC_DARK_GREY = GREY_SCALE(6); ///< Dark grey palette colour.
194 static const uint8 PC_GREY = GREY_SCALE(10); ///< Grey palette colour.
195 static const uint8 PC_WHITE = GREY_SCALE(15); ///< White palette colour.
197 static const uint8 PC_VERY_DARK_RED = 0xB2; ///< Almost-black red palette colour.
198 static const uint8 PC_DARK_RED = 0xB4; ///< Dark red palette colour.
199 static const uint8 PC_RED = 0xB8; ///< Red palette colour.
201 static const uint8 PC_VERY_DARK_BROWN = 0x56; ///< Almost-black brown palette colour.
203 static const uint8 PC_ORANGE = 0xC2; ///< Orange palette colour.
205 static const uint8 PC_YELLOW = 0xBF; ///< Yellow palette colour.
206 static const uint8 PC_LIGHT_YELLOW = 0x44; ///< Light yellow palette colour.
207 static const uint8 PC_VERY_LIGHT_YELLOW = 0x45; ///< Almost-white yellow palette colour.
209 static const uint8 PC_GREEN = 0xD0; ///< Green palette colour.
211 static const uint8 PC_DARK_BLUE = 0x9D; ///< Dark blue palette colour.
212 static const uint8 PC_LIGHT_BLUE = 0x98; ///< Light blue palette colour.
214 #endif /* GFX_FUNC_H */