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