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