OpenTTD Source 20250318-master-gb98a7ff303
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/enum_type.hpp"
15#include "zoom_type.h"
16
17typedef uint32_t SpriteID;
18typedef uint32_t PaletteID;
19typedef uint32_t CursorID;
20
25
26 auto operator<=>(const PalSpriteID&) const = default;
27};
28
29enum WindowKeyCodes : uint16_t {
30 WKC_SHIFT = 0x8000,
31 WKC_CTRL = 0x4000,
32 WKC_ALT = 0x2000,
33 WKC_META = 0x1000,
34
36
37 WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
38
39 /* Special ones */
40 WKC_NONE = 0,
41 WKC_ESC = 1,
42 WKC_BACKSPACE = 2,
43 WKC_INSERT = 3,
44 WKC_DELETE = 4,
45
46 WKC_PAGEUP = 5,
47 WKC_PAGEDOWN = 6,
48 WKC_END = 7,
49 WKC_HOME = 8,
50
51 /* Arrow keys */
52 WKC_LEFT = 9,
53 WKC_UP = 10,
54 WKC_RIGHT = 11,
55 WKC_DOWN = 12,
56
57 /* Return & tab */
58 WKC_RETURN = 13,
59 WKC_TAB = 14,
60
61 /* Space */
62 WKC_SPACE = 32,
63
64 /* Function keys */
65 WKC_F1 = 33,
66 WKC_F2 = 34,
67 WKC_F3 = 35,
68 WKC_F4 = 36,
69 WKC_F5 = 37,
70 WKC_F6 = 38,
71 WKC_F7 = 39,
72 WKC_F8 = 40,
73 WKC_F9 = 41,
74 WKC_F10 = 42,
75 WKC_F11 = 43,
76 WKC_F12 = 44,
77
78 /* Backquote is the key left of "1"
79 * we only store this key here, no matter what character is really mapped to it
80 * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */
81 WKC_BACKQUOTE = 45,
82 WKC_PAUSE = 46,
83
84 /* 0-9 are mapped to 48-57
85 * A-Z are mapped to 65-90
86 * a-z are mapped to 97-122 */
87
88 /* Numerical keyboard */
89 WKC_NUM_DIV = 138,
90 WKC_NUM_MUL = 139,
91 WKC_NUM_MINUS = 140,
92 WKC_NUM_PLUS = 141,
93 WKC_NUM_ENTER = 142,
94 WKC_NUM_DECIMAL = 143,
95
96 /* Other keys */
97 WKC_SLASH = 144,
99 WKC_EQUALS = 146,
104 WKC_COMMA = 151,
106 WKC_MINUS = 153,
107};
108
111 static const CursorID LAST = std::numeric_limits<CursorID>::max();
113 uint8_t display_time;
114};
115
119
120 constexpr CursorSprite(SpriteID spr, PaletteID pal, int x, int y) : image({spr, pal}), pos({x, y}) {}
121};
122
125 /* Logical mouse position */
128 int wheel;
129 bool fix_at;
130
131 /* 2D wheel scrolling for moving around the map */
132 bool wheel_moved;
133 float v_wheel;
134 float h_wheel;
135
136 /* Mouse appearance */
137 std::vector<CursorSprite> sprites;
138 Point total_offs, total_size;
139
140 Point draw_pos, draw_size;
141
145
146 bool visible;
147 bool dirty;
149
150 /* Drag data */
151 bool vehchain;
152
153 void UpdateCursorPositionRelative(int delta_x, int delta_y);
154 bool UpdateCursorPosition(int x, int y);
155};
156
159 void *dst_ptr;
160 int left, top, width, height;
161 int pitch;
162 ZoomLevel zoom;
163};
164
167 uint32_t data;
168 struct {
169 uint8_t r, g, b, a;
170 };
171
179 constexpr ColourRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) : r(r), g(g), b(b), a(a) { }
180
185 constexpr ColourRGBA(uint data = 0) : data(data) { }
186};
187
190 uint32_t data;
191 struct {
192 uint8_t a, r, g, b;
193 };
194
202 constexpr ColourARGB(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) : a(a), r(r), g(g), b(b) { }
203
208 constexpr ColourARGB(uint data = 0) : data(data) { }
209};
210
213 uint32_t data;
214 struct {
215 uint8_t b, g, r, a;
216 };
217
225 constexpr ColourBGRA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) : b(b), g(g), r(r), a(a) { }
226
231 constexpr ColourBGRA(uint data = 0) : data(data) { }
232};
233
234#if defined(__EMSCRIPTEN__)
235using Colour = ColourRGBA;
236#else
237using Colour = std::conditional_t<std::endian::native == std::endian::little, ColourBGRA, ColourARGB>;
238#endif /* defined(__EMSCRIPTEN__) */
239
240static_assert(sizeof(Colour) == sizeof(uint32_t));
241
242
254
255inline const char *FontSizeToName(FontSize fs)
256{
257 static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
258 assert(fs < FS_END);
259 return SIZE_TO_NAME[fs];
260}
261
267struct SubSprite {
268 int left, top, right, bottom;
269};
270
271enum Colours : uint8_t {
272 COLOUR_BEGIN,
273 COLOUR_DARK_BLUE = COLOUR_BEGIN,
274 COLOUR_PALE_GREEN,
275 COLOUR_PINK,
276 COLOUR_YELLOW,
277 COLOUR_RED,
278 COLOUR_LIGHT_BLUE,
279 COLOUR_GREEN,
280 COLOUR_DARK_GREEN,
281 COLOUR_BLUE,
282 COLOUR_CREAM,
283 COLOUR_MAUVE,
284 COLOUR_PURPLE,
285 COLOUR_ORANGE,
286 COLOUR_BROWN,
287 COLOUR_GREY,
288 COLOUR_WHITE,
289 COLOUR_END,
290 INVALID_COLOUR = 0xFF,
291};
294
295
296enum TextColour : uint16_t {
297 TC_BEGIN = 0x00,
298 TC_FROMSTRING = 0x00,
299 TC_BLUE = 0x00,
300 TC_SILVER = 0x01,
301 TC_GOLD = 0x02,
302 TC_RED = 0x03,
303 TC_PURPLE = 0x04,
304 TC_LIGHT_BROWN = 0x05,
305 TC_ORANGE = 0x06,
306 TC_GREEN = 0x07,
307 TC_YELLOW = 0x08,
308 TC_DARK_GREEN = 0x09,
309 TC_CREAM = 0x0A,
310 TC_BROWN = 0x0B,
311 TC_WHITE = 0x0C,
312 TC_LIGHT_BLUE = 0x0D,
313 TC_GREY = 0x0E,
314 TC_DARK_BLUE = 0x0F,
315 TC_BLACK = 0x10,
316 TC_END,
317 TC_INVALID = 0xFF,
318
320 TC_NO_SHADE = 0x200,
321 TC_FORCED = 0x400,
322
325};
327
328/* A few values that are related to animations using palette changes */
329static constexpr uint8_t PALETTE_ANIM_SIZE = 28;
330static constexpr uint8_t PALETTE_ANIM_START = 227;
331
338
340enum PaletteType : uint8_t {
343};
344
346enum class SpriteType : uint8_t {
347 Normal = 0,
348 MapGen = 1,
349 Font = 2,
350 Recolour = 3,
351 Invalid = 4,
352};
353
359static const uint MILLISECONDS_PER_TICK = 27;
360
362struct Palette {
363 Colour palette[256];
366};
367
374
376enum StringAlignment : uint8_t {
377 SA_LEFT = 0 << 0,
378 SA_HOR_CENTER = 1 << 0,
379 SA_RIGHT = 2 << 0,
380 SA_HOR_MASK = 3 << 0,
381
382 SA_TOP = 0 << 2,
383 SA_VERT_CENTER = 1 << 2,
384 SA_BOTTOM = 2 << 2,
385 SA_VERT_MASK = 3 << 2,
386
388
389 SA_FORCE = 1 << 4,
390};
392
393#endif /* GFX_TYPE_H */
Container with information about a font.
Definition gfx_layout.h:75
Type (helpers) for enums.
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:70
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
Definition enum_type.hpp:80
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:63
All geometry types in OpenTTD.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
Support8bpp
Modes for 8bpp support.
Definition gfx_type.h:369
@ S8BPP_HARDWARE
Full 8bpp support by OS and hardware.
Definition gfx_type.h:372
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition gfx_type.h:370
@ S8BPP_SYSTEM
No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes.
Definition gfx_type.h:371
SpriteType
Types of sprites that might be loaded.
Definition gfx_type.h:346
@ Recolour
Recolour sprite.
@ MapGen
Special sprite for the map generator.
@ Invalid
Pseudosprite or other unusable sprite, used only internally.
@ Normal
The most basic (normal) sprite.
static constexpr uint8_t PALETTE_ANIM_SIZE
number of animated colours
Definition gfx_type.h:329
FontSize
Available font sizes.
Definition gfx_type.h:244
@ FS_MONO
Index of the monospaced font in the font tables.
Definition gfx_type.h:248
@ FS_SMALL
Index of the small font in the font tables.
Definition gfx_type.h:246
@ FS_BEGIN
First font.
Definition gfx_type.h:251
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:245
@ FS_LARGE
Index of the large font in the font tables.
Definition gfx_type.h:247
uint32_t CursorID
The number of the cursor (sprite)
Definition gfx_type.h:19
StringAlignment
How to align the to-be drawn text.
Definition gfx_type.h:376
@ SA_TOP
Top align the text.
Definition gfx_type.h:382
@ SA_LEFT
Left align the text.
Definition gfx_type.h:377
@ SA_HOR_MASK
Mask for horizontal alignment.
Definition gfx_type.h:380
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:379
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:378
@ SA_VERT_MASK
Mask for vertical alignment.
Definition gfx_type.h:385
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:389
@ SA_BOTTOM
Bottom align the text.
Definition gfx_type.h:384
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:387
@ SA_VERT_CENTER
Vertically center the text.
Definition gfx_type.h:383
PaletteType
Palettes OpenTTD supports.
Definition gfx_type.h:340
@ PAL_DOS
Use the DOS palette.
Definition gfx_type.h:341
@ PAL_WINDOWS
Use the Windows palette.
Definition gfx_type.h:342
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
static constexpr uint8_t PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
Definition gfx_type.h:330
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:296
@ TC_FORCED
Ignore colour changes from strings.
Definition gfx_type.h:321
@ TC_FLAGS_MASK
Mask to test if TextColour (with flags) is within limits.
Definition gfx_type.h:324
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition gfx_type.h:320
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition gfx_type.h:319
@ TC_COLOUR_MASK
Mask to test if TextColour (without flags) is within limits.
Definition gfx_type.h:323
FillRectMode
Define the operation GfxFillRect performs.
Definition gfx_type.h:333
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:335
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition gfx_type.h:334
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition gfx_type.h:336
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition gfx_type.h:359
WindowKeyCodes
Definition gfx_type.h:29
@ WKC_BACKSLASH
\ Backslash
Definition gfx_type.h:101
@ WKC_MINUS
Definition gfx_type.h:106
@ WKC_COMMA
, Comma
Definition gfx_type.h:104
@ WKC_PERIOD
. Period
Definition gfx_type.h:105
@ WKC_EQUALS
= Equals
Definition gfx_type.h:99
@ WKC_SLASH
/ Forward slash
Definition gfx_type.h:97
@ WKC_SINGLEQUOTE
' Single quote
Definition gfx_type.h:103
@ WKC_R_BRACKET
] Right square bracket
Definition gfx_type.h:102
@ WKC_L_BRACKET
[ Left square bracket
Definition gfx_type.h:100
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
Definition gfx_type.h:35
@ WKC_SEMICOLON
; Semicolon
Definition gfx_type.h:98
A single sprite of a list of animated cursors.
Definition gfx_type.h:110
uint8_t display_time
Amount of ticks this sprite will be shown.
Definition gfx_type.h:113
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
Definition gfx_type.h:112
Point pos
Relative position.
Definition gfx_type.h:118
PalSpriteID image
Image.
Definition gfx_type.h:117
Collection of variables for cursor-display and -animation.
Definition gfx_type.h:124
bool visible
cursor is visible
Definition gfx_type.h:146
bool UpdateCursorPosition(int x, int y)
Update cursor position on mouse movement.
Definition gfx.cpp:1699
uint animate_timeout
in case of animated cursor, number of ticks to show the current cursor
Definition gfx_type.h:144
std::vector< CursorSprite > sprites
Sprites comprising cursor.
Definition gfx_type.h:137
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition gfx_type.h:129
const AnimCursor * animate_list
in case of animated cursor, list of frames
Definition gfx_type.h:142
Point pos
logical mouse position
Definition gfx_type.h:126
void UpdateCursorPositionRelative(int delta_x, int delta_y)
Update cursor position based on a relative change.
Definition gfx.cpp:1685
bool vehchain
vehicle chain is dragged
Definition gfx_type.h:151
bool in_window
mouse inside this window, determines drawing logic
Definition gfx_type.h:148
int wheel
mouse wheel movement
Definition gfx_type.h:128
const AnimCursor * animate_cur
in case of animated cursor, current frame
Definition gfx_type.h:143
Point total_size
union of sprite properties
Definition gfx_type.h:138
bool dirty
the rect occupied by the mouse is dirty (redraw)
Definition gfx_type.h:147
Point draw_size
position and size bounding-box for drawing
Definition gfx_type.h:140
Point delta
relative mouse movement in this tick
Definition gfx_type.h:127
Data about how and where to blit pixels.
Definition gfx_type.h:158
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
Information about the currently used palette.
Definition gfx_type.h:362
int first_dirty
The first dirty element.
Definition gfx_type.h:364
int count_dirty
The number of dirty elements.
Definition gfx_type.h:365
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition gfx_type.h:363
Coordinates of a point in 2D.
Used to only draw a part of the sprite.
Definition gfx_type.h:267
Packed colour union to access the alpha, red, green, and blue channels from a 32 bit number for big-e...
Definition gfx_type.h:189
uint32_t data
Conversion of the channel information to a 32 bit number.
Definition gfx_type.h:190
constexpr ColourARGB(uint data=0)
Create a new colour.
Definition gfx_type.h:208
constexpr ColourARGB(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
Create a new colour.
Definition gfx_type.h:202
uint8_t b
colour channels in BE order
Definition gfx_type.h:192
Packed colour union to access the alpha, red, green, and blue channels from a 32 bit number for littl...
Definition gfx_type.h:212
constexpr ColourBGRA(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
Create a new colour.
Definition gfx_type.h:225
uint32_t data
Conversion of the channel information to a 32 bit number.
Definition gfx_type.h:213
uint8_t a
colour channels in LE order
Definition gfx_type.h:215
constexpr ColourBGRA(uint data=0)
Create a new colour.
Definition gfx_type.h:231
Packed colour union to access the alpha, red, green, and blue channels from a 32 bit number for Emscr...
Definition gfx_type.h:166
uint8_t a
colour channels as used in browsers
Definition gfx_type.h:169
uint32_t data
Conversion of the channel information to a 32 bit number.
Definition gfx_type.h:167
constexpr ColourRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
Create a new colour.
Definition gfx_type.h:179
constexpr ColourRGBA(uint data=0)
Create a new colour.
Definition gfx_type.h:185
Types related to zooming in and out.
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:16