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/>.
10 /** @file gfx_type.h Types related to the graphics and/or input devices. */
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 */
25 SpriteID sprite
; ///< The 'real' sprite
26 PaletteID pal
; ///< The palette (use \c PAL_NONE) if not needed)
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
,
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 °) */
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 */
94 WKC_NUM_DECIMAL
= 143,
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 */
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 */
118 /* Logical mouse position */
119 Point pos
; ///< logical mouse position
120 Point delta
; ///< relative mouse movement in this tick
121 int wheel
; ///< mouse wheel movement
122 bool fix_at
; ///< mouse is moving, but cursor is not (used for scrolling)
124 /* We need two different vars to keep track of how far the scrollwheel moved.
125 * OSX uses this for scrolling around the map. */
129 /* Mouse appearance */
130 PalSpriteID sprite_seq
[16]; ///< current image of cursor
131 Point sprite_pos
[16]; ///< relative position of individual sprites
132 uint sprite_count
; ///< number of sprites to draw
133 Point total_offs
, total_size
; ///< union of sprite properties
135 Point draw_pos
, draw_size
; ///< position and size bounding-box for drawing
137 const AnimCursor
*animate_list
; ///< in case of animated cursor, list of frames
138 const AnimCursor
*animate_cur
; ///< in case of animated cursor, current frame
139 uint animate_timeout
; ///< in case of animated cursor, number of ticks to show the current cursor
141 bool visible
; ///< cursor is visible
142 bool dirty
; ///< the rect occupied by the mouse is dirty (redraw)
143 bool in_window
; ///< mouse inside this window, determines drawing logic
146 bool vehchain
; ///< vehicle chain is dragged
148 bool UpdateCursorPosition(int x
, int y
, bool queued_warp
);
155 /** Data about how and where to blit pixels. */
156 struct DrawPixelInfo
{
158 int left
, top
, width
, height
;
163 /** Structure to access the alpha, red, green, and blue channels from a 32 bit number. */
165 uint32 data
; ///< Conversion of the channel information to a 32 bit number.
167 #if TTD_ENDIAN == TTD_BIG_ENDIAN
168 uint8 a
, r
, g
, b
; ///< colour channels in BE order
170 uint8 b
, g
, r
, a
; ///< colour channels in LE order
171 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
175 * Create a new colour.
176 * @param r The channel for the red colour.
177 * @param g The channel for the green colour.
178 * @param b The channel for the blue colour.
179 * @param a The channel for the alpha/transparency.
181 Colour(uint8 r
, uint8 g
, uint8 b
, uint8 a
= 0xFF) :
182 #if TTD_ENDIAN == TTD_BIG_ENDIAN
183 a(a
), r(r
), g(g
), b(b
)
185 b(b
), g(g
), r(r
), a(a
)
186 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
191 * Create a new colour.
192 * @param The colour in the correct packed format.
194 Colour(uint data
= 0) : data(data
)
199 assert_compile(sizeof(Colour
) == sizeof(uint32
));
202 /** Available font sizes */
204 FS_NORMAL
, ///< Index of the normal font in the font tables.
205 FS_SMALL
, ///< Index of the small font in the font tables.
206 FS_LARGE
, ///< Index of the large font in the font tables.
207 FS_MONO
, ///< Index of the monospaced font in the font tables.
210 FS_BEGIN
= FS_NORMAL
, ///< First font.
212 DECLARE_POSTFIX_INCREMENT(FontSize
)
215 * Used to only draw a part of the sprite.
216 * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom).
217 * Both corners are included in the drawing area.
220 int left
, top
, right
, bottom
;
225 COLOUR_DARK_BLUE
= COLOUR_BEGIN
,
242 INVALID_COLOUR
= 0xFF,
244 template <> struct EnumPropsT
<Colours
> : MakeEnumPropsT
<Colours
, byte
, COLOUR_BEGIN
, COLOUR_END
, INVALID_COLOUR
, 4> {};
246 /** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */
249 TC_FROMSTRING
= 0x00,
255 TC_LIGHT_BROWN
= 0x05,
259 TC_DARK_GREEN
= 0x09,
263 TC_LIGHT_BLUE
= 0x0D,
270 TC_IS_PALETTE_COLOUR
= 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour.
271 TC_NO_SHADE
= 0x200, ///< Do not add shading to this text colour.
273 DECLARE_ENUM_AS_BIT_SET(TextColour
)
275 /** Defines a few values that are related to animations using palette changes */
276 enum PaletteAnimationSizes
{
277 PALETTE_ANIM_SIZE
= 28, ///< number of animated colours
278 PALETTE_ANIM_START
= 227, ///< Index in the _palettes array from which all animations are taking places (table/palettes.h)
281 /** Define the operation GfxFillRect performs */
283 FILLRECT_OPAQUE
, ///< Fill rectangle with a single colour
284 FILLRECT_CHECKER
, ///< Draw only every second pixel, used for greying-out
285 FILLRECT_RECOLOUR
, ///< Apply a recolour sprite to the screen content
288 /** Palettes OpenTTD supports. */
290 PAL_DOS
, ///< Use the DOS palette.
291 PAL_WINDOWS
, ///< Use the Windows palette.
292 PAL_AUTODETECT
, ///< Automatically detect the palette based on the graphics pack.
293 MAX_PAL
= 2, ///< The number of palettes.
296 /** Types of sprites that might be loaded */
298 ST_NORMAL
= 0, ///< The most basic (normal) sprite
299 ST_MAPGEN
= 1, ///< Special sprite for the map generator
300 ST_FONT
= 2, ///< A sprite used for fonts
301 ST_RECOLOUR
= 3, ///< Recolour sprite
302 ST_INVALID
= 4, ///< Pseudosprite or other unusable sprite, used only internally
305 /** The number of milliseconds per game tick. */
306 static const uint MILLISECONDS_PER_TICK
= 30;
308 /** Information about the currently used palette. */
310 Colour palette
[256]; ///< Current palette. Entry 0 has to be always fully transparent!
311 int first_dirty
; ///< The first dirty element.
312 int count_dirty
; ///< The number of dirty elements.
315 /** Modes for 8bpp support */
317 S8BPP_NONE
= 0, ///< No support for 8bpp by OS or hardware, force 32bpp blitters.
318 S8BPP_SYSTEM
, ///< No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes.
319 S8BPP_HARDWARE
, ///< Full 8bpp support by OS and hardware.
322 #endif /* GFX_TYPE_H */