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 8 /** @file gfx_type.h Types related to the graphics and/or input devices. */ 9 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; ///< The number of a sprite, without mapping bits and colourtables 18 typedef uint32 PaletteID; ///< The number of the palette 19 typedef uint32 CursorID; ///< The number of the cursor (sprite) 20 21 /** Combination of a palette sprite and a 'real' sprite */ 22 struct PalSpriteID { 23 SpriteID sprite; ///< The 'real' sprite 24 PaletteID pal; ///< The palette (use \c PAL_NONE) if not needed) 25 }; 26 27 enum WindowKeyCodes { 28 WKC_SHIFT = 0x8000, 29 WKC_CTRL = 0x4000, 30 WKC_ALT = 0x2000, 31 WKC_META = 0x1000, 32 33 WKC_GLOBAL_HOTKEY = 0x0800, ///< Fake keycode bit to indicate global hotkeys 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, ///< / Forward slash 96 WKC_SEMICOLON = 145, ///< ; Semicolon 97 WKC_EQUALS = 146, ///< = Equals 98 WKC_L_BRACKET = 147, ///< [ Left square bracket 99 WKC_BACKSLASH = 148, ///< \ Backslash 100 WKC_R_BRACKET = 149, ///< ] Right square bracket 101 WKC_SINGLEQUOTE = 150, ///< ' Single quote 102 WKC_COMMA = 151, ///< , Comma 103 WKC_PERIOD = 152, ///< . Period 104 WKC_MINUS = 153, ///< - Minus 105 }; 106 107 /** A single sprite of a list of animated cursors */ 108 struct AnimCursor { 109 static const CursorID LAST = MAX_UVALUE(CursorID); 110 CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop 111 byte display_time; ///< Amount of ticks this sprite will be shown 112 }; 113 114 /** Collection of variables for cursor-display and -animation */ 115 struct CursorVars { 116 /* Logical mouse position */ 117 Point pos; ///< logical mouse position 118 Point delta; ///< relative mouse movement in this tick 119 int wheel; ///< mouse wheel movement 120 bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling) 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]; ///< current image of cursor 129 Point sprite_pos[16]; ///< relative position of individual sprites 130 uint sprite_count; ///< number of sprites to draw 131 Point total_offs, total_size; ///< union of sprite properties 132 133 Point draw_pos, draw_size; ///< position and size bounding-box for drawing 134 135 const AnimCursor *animate_list; ///< in case of animated cursor, list of frames 136 const AnimCursor *animate_cur; ///< in case of animated cursor, current frame 137 uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor 138 139 bool visible; ///< cursor is visible 140 bool dirty; ///< the rect occupied by the mouse is dirty (redraw) 141 bool in_window; ///< mouse inside this window, determines drawing logic 142 143 /* Drag data */ 144 bool vehchain; ///< vehicle chain is dragged 145 146 void UpdateCursorPositionRelative(int delta_x, int delta_y); 147 bool UpdateCursorPosition(int x, int y, bool queued_warp); 148 149 private: 150 bool queued_warp; 151 Point last_position; 152 }; 153 154 /** Data about how and where to blit pixels. */ 155 struct DrawPixelInfo { 156 void *dst_ptr; 157 int left, top, width, height; 158 int pitch; 159 ZoomLevel zoom; 160 }; 161 162 /** Structure to access the alpha, red, green, and blue channels from a 32 bit number. */ 163 union Colour { 164 uint32 data; ///< Conversion of the channel information to a 32 bit number. 165 struct { 166 #if defined(__EMSCRIPTEN__) 167 uint8 r, g, b, a; ///< colour channels as used in browsers 168 #elif TTD_ENDIAN == TTD_BIG_ENDIAN 169 uint8 a, r, g, b; ///< colour channels in BE order 170 #else 171 uint8 b, g, r, a; ///< colour channels in LE order 172 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */ 173 }; 174 175 /** 176 * Create a new colour. 177 * @param r The channel for the red colour. 178 * @param g The channel for the green colour. 179 * @param b The channel for the blue colour. 180 * @param a The channel for the alpha/transparency. 181 */ 182 Colour(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) : 183 #if defined(__EMSCRIPTEN__) r(r)184 r(r), g(g), b(b), a(a) 185 #elif TTD_ENDIAN == TTD_BIG_ENDIAN 186 a(a), r(r), g(g), b(b) 187 #else 188 b(b), g(g), r(r), a(a) 189 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */ 190 { 191 } 192 193 /** 194 * Create a new colour. 195 * @param data The colour in the correct packed format. 196 */ data(data)197 Colour(uint data = 0) : data(data) 198 { 199 } 200 }; 201 202 static_assert(sizeof(Colour) == sizeof(uint32)); 203 204 205 /** Available font sizes */ 206 enum FontSize { 207 FS_NORMAL, ///< Index of the normal font in the font tables. 208 FS_SMALL, ///< Index of the small font in the font tables. 209 FS_LARGE, ///< Index of the large font in the font tables. 210 FS_MONO, ///< Index of the monospaced font in the font tables. 211 FS_END, 212 213 FS_BEGIN = FS_NORMAL, ///< First font. 214 }; 215 DECLARE_POSTFIX_INCREMENT(FontSize) 216 217 /** 218 * Used to only draw a part of the sprite. 219 * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom). 220 * Both corners are included in the drawing area. 221 */ 222 struct SubSprite { 223 int left, top, right, bottom; 224 }; 225 226 enum Colours { 227 COLOUR_BEGIN, 228 COLOUR_DARK_BLUE = COLOUR_BEGIN, 229 COLOUR_PALE_GREEN, 230 COLOUR_PINK, 231 COLOUR_YELLOW, 232 COLOUR_RED, 233 COLOUR_LIGHT_BLUE, 234 COLOUR_GREEN, 235 COLOUR_DARK_GREEN, 236 COLOUR_BLUE, 237 COLOUR_CREAM, 238 COLOUR_MAUVE, 239 COLOUR_PURPLE, 240 COLOUR_ORANGE, 241 COLOUR_BROWN, 242 COLOUR_GREY, 243 COLOUR_WHITE, 244 COLOUR_END, 245 INVALID_COLOUR = 0xFF, 246 }; 247 template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 8> {}; 248 249 /** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */ 250 enum TextColour { 251 TC_BEGIN = 0x00, 252 TC_FROMSTRING = 0x00, 253 TC_BLUE = 0x00, 254 TC_SILVER = 0x01, 255 TC_GOLD = 0x02, 256 TC_RED = 0x03, 257 TC_PURPLE = 0x04, 258 TC_LIGHT_BROWN = 0x05, 259 TC_ORANGE = 0x06, 260 TC_GREEN = 0x07, 261 TC_YELLOW = 0x08, 262 TC_DARK_GREEN = 0x09, 263 TC_CREAM = 0x0A, 264 TC_BROWN = 0x0B, 265 TC_WHITE = 0x0C, 266 TC_LIGHT_BLUE = 0x0D, 267 TC_GREY = 0x0E, 268 TC_DARK_BLUE = 0x0F, 269 TC_BLACK = 0x10, 270 TC_END, 271 TC_INVALID = 0xFF, 272 273 TC_IS_PALETTE_COLOUR = 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour. 274 TC_NO_SHADE = 0x200, ///< Do not add shading to this text colour. 275 TC_FORCED = 0x400, ///< Ignore colour changes from strings. 276 }; 277 DECLARE_ENUM_AS_BIT_SET(TextColour) 278 279 /** Defines a few values that are related to animations using palette changes */ 280 enum PaletteAnimationSizes { 281 PALETTE_ANIM_SIZE = 28, ///< number of animated colours 282 PALETTE_ANIM_START = 227, ///< Index in the _palettes array from which all animations are taking places (table/palettes.h) 283 }; 284 285 /** Define the operation GfxFillRect performs */ 286 enum FillRectMode { 287 FILLRECT_OPAQUE, ///< Fill rectangle with a single colour 288 FILLRECT_CHECKER, ///< Draw only every second pixel, used for greying-out 289 FILLRECT_RECOLOUR, ///< Apply a recolour sprite to the screen content 290 }; 291 292 /** Palettes OpenTTD supports. */ 293 enum PaletteType { 294 PAL_DOS, ///< Use the DOS palette. 295 PAL_WINDOWS, ///< Use the Windows palette. 296 PAL_AUTODETECT, ///< Automatically detect the palette based on the graphics pack. 297 MAX_PAL = 2, ///< The number of palettes. 298 }; 299 300 /** Types of sprites that might be loaded */ 301 enum SpriteType : byte { 302 ST_NORMAL = 0, ///< The most basic (normal) sprite 303 ST_MAPGEN = 1, ///< Special sprite for the map generator 304 ST_FONT = 2, ///< A sprite used for fonts 305 ST_RECOLOUR = 3, ///< Recolour sprite 306 ST_INVALID = 4, ///< Pseudosprite or other unusable sprite, used only internally 307 }; 308 309 /** The number of milliseconds per game tick. */ 310 static const uint MILLISECONDS_PER_TICK = 30; 311 312 /** Information about the currently used palette. */ 313 struct Palette { 314 Colour palette[256]; ///< Current palette. Entry 0 has to be always fully transparent! 315 int first_dirty; ///< The first dirty element. 316 int count_dirty; ///< The number of dirty elements. 317 }; 318 319 /** Modes for 8bpp support */ 320 enum Support8bpp { 321 S8BPP_NONE = 0, ///< No support for 8bpp by OS or hardware, force 32bpp blitters. 322 S8BPP_SYSTEM, ///< No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes. 323 S8BPP_HARDWARE, ///< Full 8bpp support by OS and hardware. 324 }; 325 326 /** How to align the to-be drawn text. */ 327 enum StringAlignment { 328 SA_LEFT = 0 << 0, ///< Left align the text. 329 SA_HOR_CENTER = 1 << 0, ///< Horizontally center the text. 330 SA_RIGHT = 2 << 0, ///< Right align the text (must be a single bit). 331 SA_HOR_MASK = 3 << 0, ///< Mask for horizontal alignment. 332 333 SA_TOP = 0 << 2, ///< Top align the text. 334 SA_VERT_CENTER = 1 << 2, ///< Vertically center the text. 335 SA_BOTTOM = 2 << 2, ///< Bottom align the text. 336 SA_VERT_MASK = 3 << 2, ///< Mask for vertical alignment. 337 338 SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically. 339 340 SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages. 341 }; 342 DECLARE_ENUM_AS_BIT_SET(StringAlignment) 343 344 #endif /* GFX_TYPE_H */ 345