(svn r23005) -Fix (r23004): Of course there's still the 16-sprite version for shore...
[openttd/fttd.git] / src / gfx_type.h
blob77111b767c2a0ee9706d53477469f6bb60672599
1 /* $Id$ */
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 */
10 /** @file gfx_type.h Types related to the graphics and/or input devices. */
12 #ifndef GFX_TYPE_H
13 #define GFX_TYPE_H
15 #include "core/endian_type.hpp"
16 #include "core/geometry_type.hpp"
17 #include "zoom_type.h"
19 typedef uint32 SpriteID; ///< The number of a sprite, without mapping bits and colourtables
20 typedef uint32 PaletteID; ///< The number of the palette
21 typedef uint32 CursorID; ///< The number of the cursor (sprite)
23 /** Combination of a palette sprite and a 'real' sprite */
24 struct PalSpriteID {
25 SpriteID sprite; ///< The 'real' sprite
26 PaletteID pal; ///< The palette (use \c PAL_NONE) if not needed)
29 enum WindowKeyCodes {
30 WKC_SHIFT = 0x8000,
31 WKC_CTRL = 0x4000,
32 WKC_ALT = 0x2000,
33 WKC_META = 0x1000,
35 WKC_GLOBAL_HOTKEY = 0x0800, ///< Fake keycode bit to indicate global hotkeys
37 WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
39 /* Special ones */
40 WKC_NONE = 0,
41 WKC_ESC = 1,
42 WKC_BACKSPACE = 2,
43 WKC_INSERT = 3,
44 WKC_DELETE = 4,
46 WKC_PAGEUP = 5,
47 WKC_PAGEDOWN = 6,
48 WKC_END = 7,
49 WKC_HOME = 8,
51 /* Arrow keys */
52 WKC_LEFT = 9,
53 WKC_UP = 10,
54 WKC_RIGHT = 11,
55 WKC_DOWN = 12,
57 /* Return & tab */
58 WKC_RETURN = 13,
59 WKC_TAB = 14,
61 /* Space */
62 WKC_SPACE = 32,
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,
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,
84 /* 0-9 are mapped to 48-57
85 * A-Z are mapped to 65-90
86 * a-z are mapped to 97-122 */
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,
96 /* Other keys */
97 WKC_SLASH = 144, ///< / Forward slash
98 WKC_SEMICOLON = 145, ///< ; Semicolon
99 WKC_EQUALS = 146, ///< = Equals
100 WKC_L_BRACKET = 147, ///< [ Left square bracket
101 WKC_BACKSLASH = 148, ///< \ Backslash
102 WKC_R_BRACKET = 149, ///< ] Right square bracket
103 WKC_SINGLEQUOTE = 150, ///< ' Single quote
104 WKC_COMMA = 151, ///< , Comma
105 WKC_PERIOD = 152, ///< . Period
106 WKC_MINUS = 153, ///< - Minus
109 /** A single sprite of a list of animated cursors */
110 struct AnimCursor {
111 static const CursorID LAST = MAX_UVALUE(CursorID);
112 CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop
113 byte display_time; ///< Amount of ticks this sprite will be shown
116 /** Collection of variables for cursor-display and -animation */
117 struct CursorVars {
118 Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement
119 Point draw_pos, draw_size; ///< position and size bounding-box for drawing
120 int short_vehicle_offset; ///< offset of the X for short vehicles
121 CursorID sprite; ///< current image of cursor
122 PaletteID pal;
124 int wheel; ///< mouse wheel movement
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;
131 const AnimCursor *animate_list; ///< in case of animated cursor, list of frames
132 const AnimCursor *animate_cur; ///< in case of animated cursor, current frame
133 uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor
135 bool visible; ///< cursor is visible
136 bool dirty; ///< the rect occupied by the mouse is dirty (redraw)
137 bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling)
138 bool in_window; ///< mouse inside this window, determines drawing logic
140 bool vehchain; ///< vehicle chain is dragged
143 /** Data about how and where to blit pixels. */
144 struct DrawPixelInfo {
145 void *dst_ptr;
146 int left, top, width, height;
147 int pitch;
148 ZoomLevel zoom;
151 /** Structure to access the alpha, red, green, and blue channels from a 32 bit number. */
152 union Colour {
153 uint32 data; ///< Conversion of the channel information to a 32 bit number.
154 struct {
155 #if TTD_ENDIAN == TTD_BIG_ENDIAN
156 uint8 a, r, g, b; ///< colour channels in BE order
157 #else
158 uint8 b, g, r, a; ///< colour channels in LE order
159 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
163 /** Available font sizes */
164 enum FontSize {
165 FS_NORMAL, ///< Index of the normal font in the font tables.
166 FS_SMALL, ///< Index of the small font in the font tables.
167 FS_LARGE, ///< Index of the large font in the font tables.
168 FS_END,
170 FS_BEGIN = FS_NORMAL, ///< First font.
172 DECLARE_POSTFIX_INCREMENT(FontSize)
175 * Used to only draw a part of the sprite.
176 * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom).
177 * Both corners are included in the drawing area.
179 struct SubSprite {
180 int left, top, right, bottom;
183 enum Colours {
184 COLOUR_BEGIN,
185 COLOUR_DARK_BLUE = COLOUR_BEGIN,
186 COLOUR_PALE_GREEN,
187 COLOUR_PINK,
188 COLOUR_YELLOW,
189 COLOUR_RED,
190 COLOUR_LIGHT_BLUE,
191 COLOUR_GREEN,
192 COLOUR_DARK_GREEN,
193 COLOUR_BLUE,
194 COLOUR_CREAM,
195 COLOUR_MAUVE,
196 COLOUR_PURPLE,
197 COLOUR_ORANGE,
198 COLOUR_BROWN,
199 COLOUR_GREY,
200 COLOUR_WHITE,
201 COLOUR_END,
202 INVALID_COLOUR = 0xFF,
204 template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 4> {};
206 /** Colour of the strings, see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png */
207 enum TextColour {
208 TC_BEGIN = 0x00,
209 TC_FROMSTRING = 0x00,
210 TC_BLUE = 0x00,
211 TC_SILVER = 0x01,
212 TC_GOLD = 0x02,
213 TC_RED = 0x03,
214 TC_PURPLE = 0x04,
215 TC_LIGHT_BROWN = 0x05,
216 TC_ORANGE = 0x06,
217 TC_GREEN = 0x07,
218 TC_YELLOW = 0x08,
219 TC_DARK_GREEN = 0x09,
220 TC_CREAM = 0x0A,
221 TC_BROWN = 0x0B,
222 TC_WHITE = 0x0C,
223 TC_LIGHT_BLUE = 0x0D,
224 TC_GREY = 0x0E,
225 TC_DARK_BLUE = 0x0F,
226 TC_BLACK = 0x10,
227 TC_END,
228 TC_INVALID = 0xFF,
230 TC_IS_PALETTE_COLOUR = 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour.
231 TC_NO_SHADE = 0x200, ///< Do not add shading to this text colour.
233 DECLARE_ENUM_AS_BIT_SET(TextColour)
235 /** Defines a few values that are related to animations using palette changes */
236 enum PaletteAnimationSizes {
237 PALETTE_ANIM_SIZE = 28, ///< number of animated colours
238 PALETTE_ANIM_START = 227, ///< Index in the _palettes array from which all animations are taking places (table/palettes.h)
241 /** Define the operation GfxFillRect performs */
242 enum FillRectMode {
243 FILLRECT_OPAQUE, ///< Fill rectangle with a single colour
244 FILLRECT_CHECKER, ///< Draw only every second pixel, used for greying-out
245 FILLRECT_RECOLOUR, ///< Apply a recolour sprite to the screen content
248 /** Palettes OpenTTD supports. */
249 enum PaletteType {
250 PAL_DOS, ///< Use the DOS palette.
251 PAL_WINDOWS, ///< Use the Windows palette.
252 PAL_AUTODETECT, ///< Automatically detect the palette based on the graphics pack.
253 MAX_PAL = 2, ///< The number of palettes.
256 /** Types of sprites that might be loaded */
257 enum SpriteType {
258 ST_NORMAL = 0, ///< The most basic (normal) sprite
259 ST_MAPGEN = 1, ///< Special sprite for the map generator
260 ST_FONT = 2, ///< A sprite used for fonts
261 ST_RECOLOUR = 3, ///< Recolour sprite
262 ST_INVALID = 4, ///< Pseudosprite or other unusable sprite, used only internally
265 /** The number of milliseconds per game tick. */
266 static const uint MILLISECONDS_PER_TICK = 30;
268 #endif /* GFX_TYPE_H */