OpenTTD Source: src/gfx_type.h Source File

OpenTTD Source 13.2.1

gfx_type.h
Go to the documentation of this file.
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 */
7
10 #ifndef GFX_TYPE_H
11 #define GFX_TYPE_H
12
13 #include "core/endian_type.hpp"
14 #include "core/geometry_type.hpp"
15 #include "zoom_type.h"
16
17 typedef uint32 SpriteID;
18 typedef uint32 PaletteID;
19 typedef uint32 CursorID;
20
22 struct PalSpriteID {
23 SpriteID sprite;
24 PaletteID pal;
25 };
26
27 enum WindowKeyCodes {
28 WKC_SHIFT = 0x8000,
29 WKC_CTRL = 0x4000,
30 WKC_ALT = 0x2000,
31 WKC_META = 0x1000,
32
33 WKC_GLOBAL_HOTKEY = 0x0800,
34
35 WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
36
37 /* Special ones */
38 WKC_NONE = 0,
39 WKC_ESC = 1,
40 WKC_BACKSPACE = 2,
41 WKC_INSERT = 3,
42 WKC_DELETE = 4,
43
44 WKC_PAGEUP = 5,
45 WKC_PAGEDOWN = 6,
46 WKC_END = 7,
47 WKC_HOME = 8,
48
49 /* Arrow keys */
50 WKC_LEFT = 9,
51 WKC_UP = 10,
52 WKC_RIGHT = 11,
53 WKC_DOWN = 12,
54
55 /* Return & tab */
56 WKC_RETURN = 13,
57 WKC_TAB = 14,
58
59 /* Space */
60 WKC_SPACE = 32,
61
62 /* Function keys */
63 WKC_F1 = 33,
64 WKC_F2 = 34,
65 WKC_F3 = 35,
66 WKC_F4 = 36,
67 WKC_F5 = 37,
68 WKC_F6 = 38,
69 WKC_F7 = 39,
70 WKC_F8 = 40,
71 WKC_F9 = 41,
72 WKC_F10 = 42,
73 WKC_F11 = 43,
74 WKC_F12 = 44,
75
76 /* Backquote is the key left of "1"
77 * we only store this key here, no matter what character is really mapped to it
78 * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */
79 WKC_BACKQUOTE = 45,
80 WKC_PAUSE = 46,
81
82 /* 0-9 are mapped to 48-57
83 * A-Z are mapped to 65-90
84 * a-z are mapped to 97-122 */
85
86 /* Numerical keyboard */
87 WKC_NUM_DIV = 138,
88 WKC_NUM_MUL = 139,
89 WKC_NUM_MINUS = 140,
90 WKC_NUM_PLUS = 141,
91 WKC_NUM_ENTER = 142,
92 WKC_NUM_DECIMAL = 143,
93
94 /* Other keys */
95 WKC_SLASH = 144,
96 WKC_SEMICOLON = 145,
97 WKC_EQUALS = 146,
98 WKC_L_BRACKET = 147,
99 WKC_BACKSLASH = 148,
100 WKC_R_BRACKET = 149,
101 WKC_SINGLEQUOTE = 150,
102 WKC_COMMA = 151,
103 WKC_PERIOD = 152,
104 WKC_MINUS = 153,
105 };
106
108 struct AnimCursor {
109 static const CursorID LAST = MAX_UVALUE(CursorID);
110 CursorID sprite;
111 byte display_time;
112 };
113
115 struct CursorVars {
116 /* Logical mouse position */
117 Point pos;
118 Point delta;
119 int wheel;
120 bool fix_at;
121
122 /* We need two different vars to keep track of how far the scrollwheel moved.
123 * OSX uses this for scrolling around the map. */
124 int v_wheel;
125 int h_wheel;
126
127 /* Mouse appearance */
128 PalSpriteID sprite_seq[16];
129 Point sprite_pos[16];
130 uint sprite_count;
131 Point total_offs, total_size;
132
133 Point draw_pos, draw_size;
134
135 const AnimCursor *animate_list;
136 const AnimCursor *animate_cur;
137 uint animate_timeout;
138
139 bool visible;
140 bool dirty;
141 bool in_window;
142
143 /* Drag data */
144 bool vehchain;
145
146 void UpdateCursorPositionRelative(int delta_x, int delta_y);
147 bool UpdateCursorPosition(int x, int y);
148 };
149
151 struct DrawPixelInfo {
152 void *dst_ptr;
153 int left, top, width, height;
154 int pitch;
155 ZoomLevel zoom;
156 };
157
159 union Colour {
160 uint32 data;
161 struct {
162 #if defined(__EMSCRIPTEN__)
163 uint8 r, g, b, a;
164 #elif TTD_ENDIAN == TTD_BIG_ENDIAN
165 uint8 a, r, g, b;
166 #else
167 uint8 b, g, r, a;
168 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
169 };
170
178 Colour(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) :
179 #if defined(__EMSCRIPTEN__)
180 r(r), g(g), b(b), a(a)
181 #elif TTD_ENDIAN == TTD_BIG_ENDIAN
182 a(a), r(r), g(g), b(b)
183 #else
184 b(b), g(g), r(r), a(a)
185 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
186 {
187 }
188
193 Colour(uint data = 0) : data(data)
194 {
195 }
196 };
197
198 static_assert(sizeof(Colour) == sizeof(uint32));
199
200
202 enum FontSize {
203 FS_NORMAL,
204 FS_SMALL,
205 FS_LARGE,
206 FS_MONO,
207 FS_END,
208
209 FS_BEGIN = FS_NORMAL,
210 };
211 DECLARE_POSTFIX_INCREMENT(FontSize)
212
213 static inline const char *FontSizeToName(FontSize fs)
214 {
215 static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
216 assert(fs < FS_END);
217 return SIZE_TO_NAME[fs];
218 }
219
225 struct SubSprite {
226 int left, top, right, bottom;
227 };
228
229 enum Colours : byte {
230 COLOUR_BEGIN,
231 COLOUR_DARK_BLUE = COLOUR_BEGIN,
232 COLOUR_PALE_GREEN,
233 COLOUR_PINK,
234 COLOUR_YELLOW,
235 COLOUR_RED,
236 COLOUR_LIGHT_BLUE,
237 COLOUR_GREEN,
238 COLOUR_DARK_GREEN,
239 COLOUR_BLUE,
240 COLOUR_CREAM,
241 COLOUR_MAUVE,
242 COLOUR_PURPLE,
243 COLOUR_ORANGE,
244 COLOUR_BROWN,
245 COLOUR_GREY,
246 COLOUR_WHITE,
247 COLOUR_END,
248 INVALID_COLOUR = 0xFF,
249 };
250 template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 8> {};
251
253 enum TextColour {
254 TC_BEGIN = 0x00,
255 TC_FROMSTRING = 0x00,
256 TC_BLUE = 0x00,
257 TC_SILVER = 0x01,
258 TC_GOLD = 0x02,
259 TC_RED = 0x03,
260 TC_PURPLE = 0x04,
261 TC_LIGHT_BROWN = 0x05,
262 TC_ORANGE = 0x06,
263 TC_GREEN = 0x07,
264 TC_YELLOW = 0x08,
265 TC_DARK_GREEN = 0x09,
266 TC_CREAM = 0x0A,
267 TC_BROWN = 0x0B,
268 TC_WHITE = 0x0C,
269 TC_LIGHT_BLUE = 0x0D,
270 TC_GREY = 0x0E,
271 TC_DARK_BLUE = 0x0F,
272 TC_BLACK = 0x10,
273 TC_END,
274 TC_INVALID = 0xFF,
275
276 TC_IS_PALETTE_COLOUR = 0x100,
277 TC_NO_SHADE = 0x200,
278 TC_FORCED = 0x400,
279
280 TC_COLOUR_MASK = 0xFF,
281 TC_FLAGS_MASK = 0x700,
282 };
283 DECLARE_ENUM_AS_BIT_SET(TextColour)
284
285
286 enum PaletteAnimationSizes {
287 PALETTE_ANIM_SIZE = 28,
288 PALETTE_ANIM_START = 227,
289 };
290
292 enum FillRectMode {
293 FILLRECT_OPAQUE,
294 FILLRECT_CHECKER,
295 FILLRECT_RECOLOUR,
296 };
297
299 enum PaletteType {
300 PAL_DOS,
301 PAL_WINDOWS,
302 PAL_AUTODETECT,
303 MAX_PAL = 2,
304 };
305
307 enum SpriteType : byte {
308 ST_NORMAL = 0,
309 ST_MAPGEN = 1,
310 ST_FONT = 2,
311 ST_RECOLOUR = 3,
312 ST_INVALID = 4,
313 };
314
316 static const uint MILLISECONDS_PER_TICK = 30;
317
319 struct Palette {
320 Colour palette[256];
321 int first_dirty;
322 int count_dirty;
323 };
324
326 enum Support8bpp {
327 S8BPP_NONE = 0,
328 S8BPP_SYSTEM,
329 S8BPP_HARDWARE,
330 };
331
333 enum StringAlignment {
334 SA_LEFT = 0 << 0,
335 SA_HOR_CENTER = 1 << 0,
336 SA_RIGHT = 2 << 0,
337 SA_HOR_MASK = 3 << 0,
338
339 SA_TOP = 0 << 2,
340 SA_VERT_CENTER = 1 << 2,
341 SA_BOTTOM = 2 << 2,
342 SA_VERT_MASK = 3 << 2,
343
344 SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER,
345
346 SA_FORCE = 1 << 4,
347 };
348 DECLARE_ENUM_AS_BIT_SET(StringAlignment)
349
350 #endif /* GFX_TYPE_H */
WKC_SINGLEQUOTE
@ WKC_SINGLEQUOTE
' Single quote
Definition: gfx_type.h:101
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:278
Colour::Colour
Colour(uint data=0)
Create a new colour.
Definition: gfx_type.h:193
CursorVars::UpdateCursorPosition
bool UpdateCursorPosition(int x, int y)
Update cursor position on mouse movement.
Definition: gfx.cpp:1964
PAL_DOS
@ PAL_DOS
Use the DOS palette.
Definition: gfx_type.h:300
Palette::first_dirty
int first_dirty
The first dirty element.
Definition: gfx_type.h:321
SA_HOR_MASK
@ SA_HOR_MASK
Mask for horizontal alignment.
Definition: gfx_type.h:337
CursorVars
Collection of variables for cursor-display and -animation.
Definition: gfx_type.h:115
Colour::data
uint32 data
Conversion of the channel information to a 32 bit number.
Definition: gfx_type.h:160
CursorVars::animate_cur
const AnimCursor * animate_cur
in case of animated cursor, current frame
Definition: gfx_type.h:136
ST_FONT
@ ST_FONT
A sprite used for fonts.
Definition: gfx_type.h:310
CursorVars::sprite_count
uint sprite_count
number of sprites to draw
Definition: gfx_type.h:130
CursorVars::dirty
bool dirty
the rect occupied by the mouse is dirty (redraw)
Definition: gfx_type.h:140
MAX_PAL
@ MAX_PAL
The number of palettes.
Definition: gfx_type.h:303
PALETTE_ANIM_SIZE
@ PALETTE_ANIM_SIZE
number of animated colours
Definition: gfx_type.h:287
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:209
WindowKeyCodes
WindowKeyCodes
Definition: gfx_type.h:27
CursorVars::vehchain
bool vehchain
vehicle chain is dragged
Definition: gfx_type.h:144
CursorVars::visible
bool visible
cursor is visible
Definition: gfx_type.h:139
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:295
CursorVars::animate_list
const AnimCursor * animate_list
in case of animated cursor, list of frames
Definition: gfx_type.h:135
Support8bpp
Support8bpp
Modes for 8bpp support.
Definition: gfx_type.h:326
WKC_SLASH
@ WKC_SLASH
/ Forward slash
Definition: gfx_type.h:95
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
PaletteType
PaletteType
Palettes OpenTTD supports.
Definition: gfx_type.h:299
WKC_BACKSLASH
@ WKC_BACKSLASH
\ Backslash
Definition: gfx_type.h:99
FS_LARGE
@ FS_LARGE
Index of the large font in the font tables.
Definition: gfx_type.h:205
WKC_L_BRACKET
@ WKC_L_BRACKET
[ Left square bracket
Definition: gfx_type.h:98
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:294
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:341
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:333
FillRectMode
FillRectMode
Define the operation GfxFillRect performs.
Definition: gfx_type.h:292
ST_NORMAL
@ ST_NORMAL
The most basic (normal) sprite.
Definition: gfx_type.h:308
CursorVars::UpdateCursorPositionRelative
void UpdateCursorPositionRelative(int delta_x, int delta_y)
Update cursor position based on a relative change.
Definition: gfx.cpp:1950
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:340
Colour::Colour
Colour(uint8 r, uint8 g, uint8 b, uint8 a=0xFF)
Create a new colour.
Definition: gfx_type.h:178
CursorVars::draw_size
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:225
CursorVars::sprite_pos
Point sprite_pos[16]
relative position of individual sprites
Definition: gfx_type.h:129
TTD_BIG_ENDIAN
#define TTD_BIG_ENDIAN
Big endian builds use this for TTD_ENDIAN.
Definition: endian_type.hpp:24
ST_INVALID
@ ST_INVALID
Pseudosprite or other unusable sprite, used only internally.
Definition: gfx_type.h:312
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
geometry_type.hpp
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
WKC_GLOBAL_HOTKEY
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
Definition: gfx_type.h:33
WKC_EQUALS
@ WKC_EQUALS
= Equals
Definition: gfx_type.h:97
CursorID
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:339
S8BPP_NONE
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition: gfx_type.h:327
PAL_AUTODETECT
@ PAL_AUTODETECT
Automatically detect the palette based on the graphics pack.
Definition: gfx_type.h:302
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:320
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
TC_IS_PALETTE_COLOUR
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:276
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
CursorVars::total_size
Point total_size
union of sprite properties
Definition: gfx_type.h:131
AnimCursor::sprite
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
Definition: gfx_type.h:110
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:277
CursorVars::wheel
int wheel
mouse wheel movement
Definition: gfx_type.h:119
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Palette::count_dirty
int count_dirty
The number of dirty elements.
Definition: gfx_type.h:322
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
PALETTE_ANIM_START
@ PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
Definition: gfx_type.h:288
FILLRECT_OPAQUE
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition: gfx_type.h:293
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:159
WKC_R_BRACKET
@ WKC_R_BRACKET
] Right square bracket
Definition: gfx_type.h:100
S8BPP_HARDWARE
@ S8BPP_HARDWARE
Full 8bpp support by OS and hardware.
Definition: gfx_type.h:329
WKC_PERIOD
@ WKC_PERIOD
. Period
Definition: gfx_type.h:103
CursorVars::animate_timeout
uint animate_timeout
in case of animated cursor, number of ticks to show the current cursor
Definition: gfx_type.h:137
SA_VERT_MASK
@ SA_VERT_MASK
Mask for vertical alignment.
Definition: gfx_type.h:342
Colour::a
uint8 a
colour channels in LE order
Definition: gfx_type.h:167
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
SpriteType
SpriteType
Types of sprites that might be loaded.
Definition: gfx_type.h:307
AnimCursor::display_time
byte display_time
Amount of ticks this sprite will be shown.
Definition: gfx_type.h:111
CursorVars::delta
Point delta
relative mouse movement in this tick
Definition: gfx_type.h:118
TC_FLAGS_MASK
@ TC_FLAGS_MASK
Mask to test if TextColour (with flags) is within limits.
Definition: gfx_type.h:281
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:479
WKC_COMMA
@ WKC_COMMA
, Comma
Definition: gfx_type.h:102
endian_type.hpp
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:22
AnimCursor
A single sprite of a list of animated cursors.
Definition: gfx_type.h:108
WKC_SEMICOLON
@ WKC_SEMICOLON
; Semicolon
Definition: gfx_type.h:96
MakeEnumPropsT
Helper template class that makes basic properties of given enumeration type visible from outsize.
Definition: enum_type.hpp:62
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:316
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:344
CursorVars::sprite_seq
PalSpriteID sprite_seq[16]
current image of cursor
Definition: gfx_type.h:128
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:206
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
zoom_type.h
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:311
TC_COLOUR_MASK
@ TC_COLOUR_MASK
Mask to test if TextColour (without flags) is within limits.
Definition: gfx_type.h:280
WKC_MINUS
@ WKC_MINUS
Definition: gfx_type.h:104
PAL_WINDOWS
@ PAL_WINDOWS
Use the Windows palette.
Definition: gfx_type.h:301
PaletteAnimationSizes
PaletteAnimationSizes
Defines a few values that are related to animations using palette changes.
Definition: gfx_type.h:286
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
Palette
Information about the currently used palette.
Definition: gfx_type.h:319
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
ST_MAPGEN
@ ST_MAPGEN
Special sprite for the map generator.
Definition: gfx_type.h:309
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
S8BPP_SYSTEM
@ S8BPP_SYSTEM
No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes.
Definition: gfx_type.h:328