OpenTTD
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 {
25 };
26 
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,
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);
112 };
113 
115 struct CursorVars {
116  /* Logical mouse position */
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];
131  Point total_offs, total_size;
132 
133  Point draw_pos, draw_size;
134 
138 
139  bool visible;
140  bool dirty;
141  bool in_window;
142 
143  /* Drag data */
144  bool vehchain;
145 
146  bool UpdateCursorPosition(int x, int y, bool queued_warp);
147 
148 private:
149  bool queued_warp;
150  Point last_position;
151 };
152 
155  void *dst_ptr;
156  int left, top, width, height;
157  int pitch;
158  ZoomLevel zoom;
159 };
160 
162 union Colour {
163  uint32 data;
164  struct {
165 #if TTD_ENDIAN == TTD_BIG_ENDIAN
166  uint8 a, r, g, b;
167 #else
168  uint8 b, g, r, a;
169 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
170  };
171 
179  Colour(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) :
180 #if TTD_ENDIAN == TTD_BIG_ENDIAN
181  a(a), r(r), g(g), b(b)
182 #else
183  b(b), g(g), r(r), a(a)
184 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
185  {
186  }
187 
192  Colour(uint data = 0) : data(data)
193  {
194  }
195 };
196 
197 assert_compile(sizeof(Colour) == sizeof(uint32));
198 
199 
201 enum FontSize {
206  FS_END,
207 
209 };
211 
212 
217 struct SubSprite {
218  int left, top, right, bottom;
219 };
220 
221 enum Colours {
222  COLOUR_BEGIN,
223  COLOUR_DARK_BLUE = COLOUR_BEGIN,
224  COLOUR_PALE_GREEN,
225  COLOUR_PINK,
226  COLOUR_YELLOW,
227  COLOUR_RED,
228  COLOUR_LIGHT_BLUE,
229  COLOUR_GREEN,
230  COLOUR_DARK_GREEN,
231  COLOUR_BLUE,
232  COLOUR_CREAM,
233  COLOUR_MAUVE,
234  COLOUR_PURPLE,
235  COLOUR_ORANGE,
236  COLOUR_BROWN,
237  COLOUR_GREY,
238  COLOUR_WHITE,
239  COLOUR_END,
240  INVALID_COLOUR = 0xFF,
241 };
242 template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 8> {};
243 
246  TC_BEGIN = 0x00,
247  TC_FROMSTRING = 0x00,
248  TC_BLUE = 0x00,
249  TC_SILVER = 0x01,
250  TC_GOLD = 0x02,
251  TC_RED = 0x03,
252  TC_PURPLE = 0x04,
253  TC_LIGHT_BROWN = 0x05,
254  TC_ORANGE = 0x06,
255  TC_GREEN = 0x07,
256  TC_YELLOW = 0x08,
257  TC_DARK_GREEN = 0x09,
258  TC_CREAM = 0x0A,
259  TC_BROWN = 0x0B,
260  TC_WHITE = 0x0C,
261  TC_LIGHT_BLUE = 0x0D,
262  TC_GREY = 0x0E,
263  TC_DARK_BLUE = 0x0F,
264  TC_BLACK = 0x10,
265  TC_END,
266  TC_INVALID = 0xFF,
267 
269  TC_NO_SHADE = 0x200,
270  TC_FORCED = 0x400,
271 };
273 
274 
278 };
279 
285 };
286 
292  MAX_PAL = 2,
293 };
294 
296 enum SpriteType : byte {
297  ST_NORMAL = 0,
298  ST_MAPGEN = 1,
299  ST_FONT = 2,
302 };
303 
305 static const uint MILLISECONDS_PER_TICK = 30;
306 
308 struct Palette {
309  Colour palette[256];
312 };
313 
319 };
320 
321 #endif /* GFX_TYPE_H */
Helper template class that makes basic properties of given enumeration type visible from outsize...
Definition: enum_type.hpp:62
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition of various endian-dependant macros.
bool dirty
the rect occupied by the mouse is dirty (redraw)
Definition: gfx_type.h:140
Pseudosprite or other unusable sprite, used only internally.
Definition: gfx_type.h:301
Data about how and where to blit pixels.
Definition: gfx_type.h:154
Point pos
logical mouse position
Definition: gfx_type.h:117
Information about the currently used palette.
Definition: gfx_type.h:308
WindowKeyCodes
Definition: gfx_type.h:27
bool vehchain
vehicle chain is dragged
Definition: gfx_type.h:144
, Comma
Definition: gfx_type.h:102
uint sprite_count
number of sprites to draw
Definition: gfx_type.h:130
Index of the monospaced font in the font tables.
Definition: gfx_type.h:205
uint32 data
Conversion of the channel information to a 32 bit number.
Definition: gfx_type.h:163
uint8 a
colour channels in LE order
Definition: gfx_type.h:168
= Equals
Definition: gfx_type.h:97
Combination of a palette sprite and a &#39;real&#39; sprite.
Definition: gfx_type.h:22
const AnimCursor * animate_list
in case of animated cursor, list of frames
Definition: gfx_type.h:135
Use the Windows palette.
Definition: gfx_type.h:290
Use the DOS palette.
Definition: gfx_type.h:289
No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes.
Definition: gfx_type.h:317
bool visible
cursor is visible
Definition: gfx_type.h:139
FillRectMode
Define the operation GfxFillRect performs.
Definition: gfx_type.h:281
Point total_size
union of sprite properties
Definition: gfx_type.h:131
Types related to zooming in and out.
Point draw_size
position and size bounding-box for drawing
Definition: gfx_type.h:133
CursorID sprite
Must be set to LAST_ANIM when it is the last sprite of the loop.
Definition: gfx_type.h:110
Collection of variables for cursor-display and -animation.
Definition: gfx_type.h:115
&#39; Single quote
Definition: gfx_type.h:101
Special sprite for the map generator.
Definition: gfx_type.h:298
PaletteAnimationSizes
Defines a few values that are related to animations using palette changes.
Definition: gfx_type.h:275
A sprite used for fonts.
Definition: gfx_type.h:299
Fill rectangle with a single colour.
Definition: gfx_type.h:282
First font.
Definition: gfx_type.h:208
[ Left square bracket
Definition: gfx_type.h:98
] Right square bracket
Definition: gfx_type.h:100
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:284
\ Backslash
Definition: gfx_type.h:99
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
int wheel
mouse wheel movement
Definition: gfx_type.h:119
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
/ Forward slash
Definition: gfx_type.h:95
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:305
number of animated colours
Definition: gfx_type.h:276
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
A single sprite of a list of animated cursors.
Definition: gfx_type.h:108
byte display_time
Amount of ticks this sprite will be shown.
Definition: gfx_type.h:111
Colour(uint data=0)
Create a new colour.
Definition: gfx_type.h:192
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:469
int first_dirty
The first dirty element.
Definition: gfx_type.h:310
#define TTD_BIG_ENDIAN
Big endian builds use this for TTD_ENDIAN.
Definition: endian_type.hpp:24
; Semicolon
Definition: gfx_type.h:96
Automatically detect the palette based on the graphics pack.
Definition: gfx_type.h:291
SpriteType
Types of sprites that might be loaded.
Definition: gfx_type.h:296
The most basic (normal) sprite.
Definition: gfx_type.h:297
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:283
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition: gfx_type.h:316
Recolour sprite.
Definition: gfx_type.h:300
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
uint animate_timeout
in case of animated cursor, number of ticks to show the current cursor
Definition: gfx_type.h:137
Colour(uint8 r, uint8 g, uint8 b, uint8 a=0xFF)
Create a new colour.
Definition: gfx_type.h:179
The number of palettes.
Definition: gfx_type.h:292
Ignore colour changes from strings.
Definition: gfx_type.h:270
Do not add shading to this text colour.
Definition: gfx_type.h:269
FontSize
Available font sizes.
Definition: gfx_type.h:201
PaletteType
Palettes OpenTTD supports.
Definition: gfx_type.h:288
Index of the normal font in the font tables.
Definition: gfx_type.h:202
All geometry types in OpenTTD.
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
Used to only draw a part of the sprite.
Definition: gfx_type.h:217
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
Coordinates of a point in 2D.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:162
Index of the small font in the font tables.
Definition: gfx_type.h:203
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:268
Index of the large font in the font tables.
Definition: gfx_type.h:204
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
. Period
Definition: gfx_type.h:103
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
Support8bpp
Modes for 8bpp support.
Definition: gfx_type.h:315
Point delta
relative mouse movement in this tick
Definition: gfx_type.h:118
const AnimCursor * animate_cur
in case of animated cursor, current frame
Definition: gfx_type.h:136
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:23
int count_dirty
The number of dirty elements.
Definition: gfx_type.h:311
Index in the _palettes array from which all animations are taking places (table/palettes.h)
Definition: gfx_type.h:277
Fake keycode bit to indicate global hotkeys.
Definition: gfx_type.h:33
Full 8bpp support by OS and hardware.
Definition: gfx_type.h:318
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24