OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

gfx_type.h
Go to the documentation of this file.
1 /* $Id: gfx_type.h 27167 2015-02-22 23:06:45Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef GFX_TYPE_H
13 #define GFX_TYPE_H
14
15 #include "core/endian_type.hpp"
16 #include "core/geometry_type.hpp"
17 #include "zoom_type.h"
18
19 typedef uint32 SpriteID;
20 typedef uint32 PaletteID;
21 typedef uint32 CursorID;
22
24 struct PalSpriteID {
25 SpriteID sprite;
26 PaletteID pal;
27 };
28
29 enum WindowKeyCodes {
30 WKC_SHIFT = 0x8000,
31 WKC_CTRL = 0x4000,
32 WKC_ALT = 0x2000,
33 WKC_META = 0x1000,
34
35 WKC_GLOBAL_HOTKEY = 0x0800,
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,
98 WKC_SEMICOLON = 145,
99 WKC_EQUALS = 146,
100 WKC_L_BRACKET = 147,
101 WKC_BACKSLASH = 148,
102 WKC_R_BRACKET = 149,
103 WKC_SINGLEQUOTE = 150,
104 WKC_COMMA = 151,
105 WKC_PERIOD = 152,
106 WKC_MINUS = 153,
107 };
108
110 struct AnimCursor {
111 static const CursorID LAST = MAX_UVALUE(CursorID);
112 CursorID sprite;
113 byte display_time;
114 };
115
117 struct CursorVars {
118 Point pos, size, offs, delta;
119 Point draw_pos, draw_size;
120 int short_vehicle_offset;
121 CursorID sprite;
122 PaletteID pal;
123
124 int wheel;
125
126 /* We need two different vars to keep track of how far the scrollwheel moved.
127 * OSX uses this for scrolling around the map. */
128 int v_wheel;
129 int h_wheel;
130
131 const AnimCursor *animate_list;
132 const AnimCursor *animate_cur;
133 uint animate_timeout;
134
135 bool visible;
136 bool dirty;
137 bool fix_at;
138 bool in_window;
139
140 bool vehchain;
141
142 bool UpdateCursorPosition(int x, int y, bool queued_warp);
143
144 private:
145 bool queued_warp;
146 Point last_position;
147 };
148
150 struct DrawPixelInfo {
151 void *dst_ptr;
152 int left, top, width, height;
153 int pitch;
154 ZoomLevel zoom;
155 };
156
158 union Colour {
159 uint32 data;
160 struct {
161 #if TTD_ENDIAN == TTD_BIG_ENDIAN
162 uint8 a, r, g, b;
163 #else
164 uint8 b, g, r, a;
165 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
166 };
167
175 Colour(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) :
176 #if TTD_ENDIAN == TTD_BIG_ENDIAN
177 a(a), r(r), g(g), b(b)
178 #else
179 b(b), g(g), r(r), a(a)
180 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
181 {
182 }
183
188 Colour(uint data = 0) : data(data)
189 {
190 }
191 };
192
193 assert_compile(sizeof(Colour) == sizeof(uint32));
194
195
197 enum FontSize {
198 FS_NORMAL,
199 FS_SMALL,
200 FS_LARGE,
201 FS_MONO,
202 FS_END,
203
204 FS_BEGIN = FS_NORMAL,
205 };
206 DECLARE_POSTFIX_INCREMENT(FontSize)
207
208
213 struct SubSprite {
214 int left, top, right, bottom;
215 };
216
217 enum Colours {
218 COLOUR_BEGIN,
219 COLOUR_DARK_BLUE = COLOUR_BEGIN,
220 COLOUR_PALE_GREEN,
221 COLOUR_PINK,
222 COLOUR_YELLOW,
223 COLOUR_RED,
224 COLOUR_LIGHT_BLUE,
225 COLOUR_GREEN,
226 COLOUR_DARK_GREEN,
227 COLOUR_BLUE,
228 COLOUR_CREAM,
229 COLOUR_MAUVE,
230 COLOUR_PURPLE,
231 COLOUR_ORANGE,
232 COLOUR_BROWN,
233 COLOUR_GREY,
234 COLOUR_WHITE,
235 COLOUR_END,
236 INVALID_COLOUR = 0xFF,
237 };
238 template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 4> {};
239
241 enum TextColour {
242 TC_BEGIN = 0x00,
243 TC_FROMSTRING = 0x00,
244 TC_BLUE = 0x00,
245 TC_SILVER = 0x01,
246 TC_GOLD = 0x02,
247 TC_RED = 0x03,
248 TC_PURPLE = 0x04,
249 TC_LIGHT_BROWN = 0x05,
250 TC_ORANGE = 0x06,
251 TC_GREEN = 0x07,
252 TC_YELLOW = 0x08,
253 TC_DARK_GREEN = 0x09,
254 TC_CREAM = 0x0A,
255 TC_BROWN = 0x0B,
256 TC_WHITE = 0x0C,
257 TC_LIGHT_BLUE = 0x0D,
258 TC_GREY = 0x0E,
259 TC_DARK_BLUE = 0x0F,
260 TC_BLACK = 0x10,
261 TC_END,
262 TC_INVALID = 0xFF,
263
264 TC_IS_PALETTE_COLOUR = 0x100,
265 TC_NO_SHADE = 0x200,
266 };
267 DECLARE_ENUM_AS_BIT_SET(TextColour)
268
269
270 enum PaletteAnimationSizes {
271 PALETTE_ANIM_SIZE = 28,
272 PALETTE_ANIM_START = 227,
273 };
274
276 enum FillRectMode {
277 FILLRECT_OPAQUE,
278 FILLRECT_CHECKER,
279 FILLRECT_RECOLOUR,
280 };
281
283 enum PaletteType {
284 PAL_DOS,
285 PAL_WINDOWS,
286 PAL_AUTODETECT,
287 MAX_PAL = 2,
288 };
289
291 enum SpriteType {
292 ST_NORMAL = 0,
293 ST_MAPGEN = 1,
294 ST_FONT = 2,
295 ST_RECOLOUR = 3,
296 ST_INVALID = 4,
297 };
298
300 static const uint MILLISECONDS_PER_TICK = 30;
301
303 struct Palette {
304 Colour palette[256];
305 int first_dirty;
306 int count_dirty;
307 };
308
310 enum Support8bpp {
311 S8BPP_NONE = 0,
312 S8BPP_SYSTEM,
313 S8BPP_HARDWARE,
314 };
315
316 #endif /* GFX_TYPE_H */