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/>.
8 /** @file gfx_type.h Types related to the graphics and/or input devices. */
13 #include "core/endian_type.hpp"
14 #include "core/geometry_type.hpp"
15 #include "zoom_type.h"
17 typedef uint32_t SpriteID
; ///< The number of a sprite, without mapping bits and colourtables
18 typedef uint32_t PaletteID
; ///< The number of the palette
19 typedef uint32_t CursorID
; ///< The number of the cursor (sprite)
21 /** Combination of a palette sprite and a 'real' sprite */
23 SpriteID sprite
; ///< The 'real' sprite
24 PaletteID pal
; ///< The palette (use \c PAL_NONE) if not needed)
33 WKC_GLOBAL_HOTKEY
= 0x0800, ///< Fake keycode bit to indicate global hotkeys
35 WKC_SPECIAL_KEYS
= WKC_SHIFT
| WKC_CTRL
| WKC_ALT
| WKC_META
| WKC_GLOBAL_HOTKEY
,
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 °) */
82 /* 0-9 are mapped to 48-57
83 * A-Z are mapped to 65-90
84 * a-z are mapped to 97-122 */
86 /* Numerical keyboard */
92 WKC_NUM_DECIMAL
= 143,
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
107 /** A single sprite of a list of animated cursors */
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
114 /** Collection of variables for cursor-display and -animation */
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)
122 /* We need two different vars to keep track of how far the scrollwheel moved.
123 * OSX uses this for scrolling around the map. */
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
133 Point draw_pos
, draw_size
; ///< position and size bounding-box for drawing
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
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
144 bool vehchain
; ///< vehicle chain is dragged
146 void UpdateCursorPositionRelative(int delta_x
, int delta_y
);
147 bool UpdateCursorPosition(int x
, int y
);
150 /** Data about how and where to blit pixels. */
151 struct DrawPixelInfo
{
153 int left
, top
, width
, height
;
158 /** Structure to access the alpha, red, green, and blue channels from a 32 bit number. */
160 uint32_t data
; ///< Conversion of the channel information to a 32 bit number.
162 #if defined(__EMSCRIPTEN__)
163 uint8_t r
, g
, b
, a
; ///< colour channels as used in browsers
164 #elif TTD_ENDIAN == TTD_BIG_ENDIAN
165 uint8_t a
, r
, g
, b
; ///< colour channels in BE order
167 uint8_t b
, g
, r
, a
; ///< colour channels in LE order
168 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
172 * Create a new colour.
173 * @param r The channel for the red colour.
174 * @param g The channel for the green colour.
175 * @param b The channel for the blue colour.
176 * @param a The channel for the alpha/transparency.
178 Colour(uint8_t r
, uint8_t g
, uint8_t b
, uint8_t a
= 0xFF) :
179 #if defined(__EMSCRIPTEN__)
180 r(r
), g(g
), b(b
), a(a
)
181 #elif TTD_ENDIAN == TTD_BIG_ENDIAN
182 a(a
), r(r
), g(g
), b(b
)
184 b(b
), g(g
), r(r
), a(a
)
185 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
190 * Create a new colour.
191 * @param data The colour in the correct packed format.
193 Colour(uint data
= 0) : data(data
)
198 static_assert(sizeof(Colour
) == sizeof(uint32_t));
201 /** Available font sizes */
203 FS_NORMAL
, ///< Index of the normal font in the font tables.
204 FS_SMALL
, ///< Index of the small font in the font tables.
205 FS_LARGE
, ///< Index of the large font in the font tables.
206 FS_MONO
, ///< Index of the monospaced font in the font tables.
209 FS_BEGIN
= FS_NORMAL
, ///< First font.
211 DECLARE_POSTFIX_INCREMENT(FontSize
)
213 inline const char *FontSizeToName(FontSize fs
)
215 static const char *SIZE_TO_NAME
[] = { "medium", "small", "large", "mono" };
217 return SIZE_TO_NAME
[fs
];
221 * Used to only draw a part of the sprite.
222 * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom).
223 * Both corners are included in the drawing area.
226 int left
, top
, right
, bottom
;
229 enum Colours
: byte
{
231 COLOUR_DARK_BLUE
= COLOUR_BEGIN
,
248 INVALID_COLOUR
= 0xFF,
250 DECLARE_ENUM_AS_ADDABLE(Colours
)
252 /** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */
255 TC_FROMSTRING
= 0x00,
261 TC_LIGHT_BROWN
= 0x05,
265 TC_DARK_GREEN
= 0x09,
269 TC_LIGHT_BLUE
= 0x0D,
276 TC_IS_PALETTE_COLOUR
= 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour.
277 TC_NO_SHADE
= 0x200, ///< Do not add shading to this text colour.
278 TC_FORCED
= 0x400, ///< Ignore colour changes from strings.
280 TC_COLOUR_MASK
= 0xFF, ///< Mask to test if TextColour (without flags) is within limits.
281 TC_FLAGS_MASK
= 0x700, ///< Mask to test if TextColour (with flags) is within limits.
283 DECLARE_ENUM_AS_BIT_SET(TextColour
)
285 /** Defines a few values that are related to animations using palette changes */
286 enum PaletteAnimationSizes
{
287 PALETTE_ANIM_SIZE
= 28, ///< number of animated colours
288 PALETTE_ANIM_START
= 227, ///< Index in the _palettes array from which all animations are taking places (table/palettes.h)
291 /** Define the operation GfxFillRect performs */
293 FILLRECT_OPAQUE
, ///< Fill rectangle with a single colour
294 FILLRECT_CHECKER
, ///< Draw only every second pixel, used for greying-out
295 FILLRECT_RECOLOUR
, ///< Apply a recolour sprite to the screen content
298 /** Palettes OpenTTD supports. */
300 PAL_DOS
, ///< Use the DOS palette.
301 PAL_WINDOWS
, ///< Use the Windows palette.
302 PAL_AUTODETECT
, ///< Automatically detect the palette based on the graphics pack.
303 MAX_PAL
= 2, ///< The number of palettes.
306 /** Types of sprites that might be loaded */
307 enum class SpriteType
: byte
{
308 Normal
= 0, ///< The most basic (normal) sprite
309 MapGen
= 1, ///< Special sprite for the map generator
310 Font
= 2, ///< A sprite used for fonts
311 Recolour
= 3, ///< Recolour sprite
312 Invalid
= 4, ///< Pseudosprite or other unusable sprite, used only internally
316 * The number of milliseconds per game tick.
317 * The value 27 together with a day length of 74 ticks makes one day 1998 milliseconds, almost exactly 2 seconds.
318 * With a 2 second day, one standard month is 1 minute, and one standard year is slightly over 12 minutes.
320 static const uint MILLISECONDS_PER_TICK
= 27;
322 /** Information about the currently used palette. */
324 Colour palette
[256]; ///< Current palette. Entry 0 has to be always fully transparent!
325 int first_dirty
; ///< The first dirty element.
326 int count_dirty
; ///< The number of dirty elements.
329 /** Modes for 8bpp support */
331 S8BPP_NONE
= 0, ///< No support for 8bpp by OS or hardware, force 32bpp blitters.
332 S8BPP_SYSTEM
, ///< No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes.
333 S8BPP_HARDWARE
, ///< Full 8bpp support by OS and hardware.
336 /** How to align the to-be drawn text. */
337 enum StringAlignment
{
338 SA_LEFT
= 0 << 0, ///< Left align the text.
339 SA_HOR_CENTER
= 1 << 0, ///< Horizontally center the text.
340 SA_RIGHT
= 2 << 0, ///< Right align the text (must be a single bit).
341 SA_HOR_MASK
= 3 << 0, ///< Mask for horizontal alignment.
343 SA_TOP
= 0 << 2, ///< Top align the text.
344 SA_VERT_CENTER
= 1 << 2, ///< Vertically center the text.
345 SA_BOTTOM
= 2 << 2, ///< Bottom align the text.
346 SA_VERT_MASK
= 3 << 2, ///< Mask for vertical alignment.
348 SA_CENTER
= SA_HOR_CENTER
| SA_VERT_CENTER
, ///< Center both horizontally and vertically.
350 SA_FORCE
= 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages.
352 DECLARE_ENUM_AS_BIT_SET(StringAlignment
)
354 #endif /* GFX_TYPE_H */