2007-12-23 10:56:02 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
/** @file gfx_type.h Types related to the graphics and/or input devices. */
|
|
|
|
|
|
|
|
#ifndef GFX_TYPE_H
|
|
|
|
#define GFX_TYPE_H
|
|
|
|
|
2008-06-18 21:19:04 +00:00
|
|
|
#include "core/endian_type.hpp"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "core/geometry_type.hpp"
|
|
|
|
#include "zoom_type.h"
|
|
|
|
|
2010-01-21 01:38:13 +00:00
|
|
|
typedef uint32 SpriteID; ///< The number of a sprite, without mapping bits and colourtables
|
|
|
|
typedef uint32 PaletteID; ///< The number of the palette
|
|
|
|
typedef uint32 CursorID; ///< The number of the cursor (sprite)
|
2008-08-01 09:34:34 +00:00
|
|
|
|
2008-10-13 03:26:48 +00:00
|
|
|
/** Combination of a palette sprite and a 'real' sprite */
|
2007-12-23 10:56:02 +00:00
|
|
|
struct PalSpriteID {
|
2008-10-13 03:26:48 +00:00
|
|
|
SpriteID sprite; ///< The 'real' sprite
|
2010-01-21 01:38:13 +00:00
|
|
|
PaletteID pal; ///< The palette (use \c PAL_NONE) if not needed)
|
2007-12-23 10:56:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum WindowKeyCodes {
|
|
|
|
WKC_SHIFT = 0x8000,
|
|
|
|
WKC_CTRL = 0x4000,
|
|
|
|
WKC_ALT = 0x2000,
|
|
|
|
WKC_META = 0x1000,
|
|
|
|
|
2010-07-03 20:14:56 +00:00
|
|
|
WKC_GLOBAL_HOTKEY = 0x0800, ///< Fake keycode bit to indicate global hotkeys
|
|
|
|
|
|
|
|
WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
|
2010-07-03 13:28:15 +00:00
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
/* Special ones */
|
|
|
|
WKC_NONE = 0,
|
|
|
|
WKC_ESC = 1,
|
|
|
|
WKC_BACKSPACE = 2,
|
|
|
|
WKC_INSERT = 3,
|
|
|
|
WKC_DELETE = 4,
|
|
|
|
|
|
|
|
WKC_PAGEUP = 5,
|
|
|
|
WKC_PAGEDOWN = 6,
|
|
|
|
WKC_END = 7,
|
|
|
|
WKC_HOME = 8,
|
|
|
|
|
|
|
|
/* Arrow keys */
|
|
|
|
WKC_LEFT = 9,
|
|
|
|
WKC_UP = 10,
|
|
|
|
WKC_RIGHT = 11,
|
|
|
|
WKC_DOWN = 12,
|
|
|
|
|
|
|
|
/* Return & tab */
|
|
|
|
WKC_RETURN = 13,
|
|
|
|
WKC_TAB = 14,
|
|
|
|
|
|
|
|
/* Space */
|
|
|
|
WKC_SPACE = 32,
|
|
|
|
|
|
|
|
/* Function keys */
|
|
|
|
WKC_F1 = 33,
|
|
|
|
WKC_F2 = 34,
|
|
|
|
WKC_F3 = 35,
|
|
|
|
WKC_F4 = 36,
|
|
|
|
WKC_F5 = 37,
|
|
|
|
WKC_F6 = 38,
|
|
|
|
WKC_F7 = 39,
|
|
|
|
WKC_F8 = 40,
|
|
|
|
WKC_F9 = 41,
|
|
|
|
WKC_F10 = 42,
|
|
|
|
WKC_F11 = 43,
|
|
|
|
WKC_F12 = 44,
|
|
|
|
|
|
|
|
/* Backquote is the key left of "1"
|
|
|
|
* we only store this key here, no matter what character is really mapped to it
|
|
|
|
* on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */
|
|
|
|
WKC_BACKQUOTE = 45,
|
|
|
|
WKC_PAUSE = 46,
|
|
|
|
|
|
|
|
/* 0-9 are mapped to 48-57
|
|
|
|
* A-Z are mapped to 65-90
|
|
|
|
* a-z are mapped to 97-122 */
|
|
|
|
|
|
|
|
/* Numerical keyboard */
|
|
|
|
WKC_NUM_DIV = 138,
|
|
|
|
WKC_NUM_MUL = 139,
|
|
|
|
WKC_NUM_MINUS = 140,
|
|
|
|
WKC_NUM_PLUS = 141,
|
|
|
|
WKC_NUM_ENTER = 142,
|
|
|
|
WKC_NUM_DECIMAL = 143,
|
|
|
|
|
|
|
|
/* Other keys */
|
|
|
|
WKC_SLASH = 144, ///< / Forward slash
|
|
|
|
WKC_SEMICOLON = 145, ///< ; Semicolon
|
|
|
|
WKC_EQUALS = 146, ///< = Equals
|
|
|
|
WKC_L_BRACKET = 147, ///< [ Left square bracket
|
|
|
|
WKC_BACKSLASH = 148, ///< \ Backslash
|
|
|
|
WKC_R_BRACKET = 149, ///< ] Right square bracket
|
|
|
|
WKC_SINGLEQUOTE = 150, ///< ' Single quote
|
|
|
|
WKC_COMMA = 151, ///< , Comma
|
|
|
|
WKC_PERIOD = 152, ///< . Period
|
|
|
|
WKC_MINUS = 153, ///< - Minus
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A single sprite of a list of animated cursors */
|
|
|
|
struct AnimCursor {
|
|
|
|
static const CursorID LAST = MAX_UVALUE(CursorID);
|
|
|
|
CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop
|
|
|
|
byte display_time; ///< Amount of ticks this sprite will be shown
|
|
|
|
};
|
|
|
|
|
2008-08-01 09:34:34 +00:00
|
|
|
/** Collection of variables for cursor-display and -animation */
|
2007-12-23 10:56:02 +00:00
|
|
|
struct CursorVars {
|
2016-08-15 18:30:50 +00:00
|
|
|
/* Logical mouse position */
|
|
|
|
Point pos; ///< logical mouse position
|
|
|
|
Point delta; ///< relative mouse movement in this tick
|
|
|
|
int wheel; ///< mouse wheel movement
|
|
|
|
bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling)
|
2007-12-23 10:56:02 +00:00
|
|
|
|
|
|
|
/* We need two different vars to keep track of how far the scrollwheel moved.
|
|
|
|
* OSX uses this for scrolling around the map. */
|
|
|
|
int v_wheel;
|
|
|
|
int h_wheel;
|
|
|
|
|
2016-08-15 18:30:50 +00:00
|
|
|
/* Mouse appearance */
|
2016-08-15 18:33:08 +00:00
|
|
|
PalSpriteID sprite_seq[16]; ///< current image of cursor
|
|
|
|
Point sprite_pos[16]; ///< relative position of individual sprites
|
|
|
|
uint sprite_count; ///< number of sprites to draw
|
|
|
|
Point total_offs, total_size; ///< union of sprite properties
|
|
|
|
|
2016-08-15 18:30:50 +00:00
|
|
|
Point draw_pos, draw_size; ///< position and size bounding-box for drawing
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
const AnimCursor *animate_list; ///< in case of animated cursor, list of frames
|
|
|
|
const AnimCursor *animate_cur; ///< in case of animated cursor, current frame
|
|
|
|
uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor
|
|
|
|
|
2016-08-15 18:30:50 +00:00
|
|
|
bool visible; ///< cursor is visible
|
|
|
|
bool dirty; ///< the rect occupied by the mouse is dirty (redraw)
|
|
|
|
bool in_window; ///< mouse inside this window, determines drawing logic
|
2008-04-05 11:27:50 +00:00
|
|
|
|
2016-08-15 18:30:50 +00:00
|
|
|
/* Drag data */
|
|
|
|
bool vehchain; ///< vehicle chain is dragged
|
2015-02-22 23:06:45 +00:00
|
|
|
|
|
|
|
bool UpdateCursorPosition(int x, int y, bool queued_warp);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool queued_warp;
|
|
|
|
Point last_position;
|
2007-12-23 10:56:02 +00:00
|
|
|
};
|
|
|
|
|
2009-06-20 15:48:55 +00:00
|
|
|
/** Data about how and where to blit pixels. */
|
2007-12-23 10:56:02 +00:00
|
|
|
struct DrawPixelInfo {
|
|
|
|
void *dst_ptr;
|
|
|
|
int left, top, width, height;
|
|
|
|
int pitch;
|
|
|
|
ZoomLevel zoom;
|
|
|
|
};
|
|
|
|
|
2009-06-20 15:48:55 +00:00
|
|
|
/** Structure to access the alpha, red, green, and blue channels from a 32 bit number. */
|
2009-06-22 23:15:27 +00:00
|
|
|
union Colour {
|
|
|
|
uint32 data; ///< Conversion of the channel information to a 32 bit number.
|
|
|
|
struct {
|
2008-06-18 21:19:04 +00:00
|
|
|
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
2009-06-22 23:15:27 +00:00
|
|
|
uint8 a, r, g, b; ///< colour channels in BE order
|
2008-06-18 21:19:04 +00:00
|
|
|
#else
|
2009-06-22 23:15:27 +00:00
|
|
|
uint8 b, g, r, a; ///< colour channels in LE order
|
2008-06-18 21:19:04 +00:00
|
|
|
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
2009-06-22 23:15:27 +00:00
|
|
|
};
|
2012-04-10 20:16:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new colour.
|
|
|
|
* @param r The channel for the red colour.
|
|
|
|
* @param g The channel for the green colour.
|
|
|
|
* @param b The channel for the blue colour.
|
|
|
|
* @param a The channel for the alpha/transparency.
|
|
|
|
*/
|
|
|
|
Colour(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) :
|
|
|
|
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
|
|
|
a(a), r(r), g(g), b(b)
|
|
|
|
#else
|
|
|
|
b(b), g(g), r(r), a(a)
|
|
|
|
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new colour.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param data The colour in the correct packed format.
|
2012-04-10 20:16:51 +00:00
|
|
|
*/
|
|
|
|
Colour(uint data = 0) : data(data)
|
|
|
|
{
|
|
|
|
}
|
2007-12-23 10:56:02 +00:00
|
|
|
};
|
|
|
|
|
2012-04-10 20:16:51 +00:00
|
|
|
assert_compile(sizeof(Colour) == sizeof(uint32));
|
|
|
|
|
|
|
|
|
2008-08-01 09:34:34 +00:00
|
|
|
/** Available font sizes */
|
2007-12-23 10:56:02 +00:00
|
|
|
enum FontSize {
|
2009-06-20 15:05:59 +00:00
|
|
|
FS_NORMAL, ///< Index of the normal font in the font tables.
|
|
|
|
FS_SMALL, ///< Index of the small font in the font tables.
|
|
|
|
FS_LARGE, ///< Index of the large font in the font tables.
|
2011-11-20 11:56:51 +00:00
|
|
|
FS_MONO, ///< Index of the monospaced font in the font tables.
|
2007-12-23 10:56:02 +00:00
|
|
|
FS_END,
|
2009-06-20 15:05:59 +00:00
|
|
|
|
|
|
|
FS_BEGIN = FS_NORMAL, ///< First font.
|
2007-12-23 10:56:02 +00:00
|
|
|
};
|
2010-03-23 22:25:43 +00:00
|
|
|
DECLARE_POSTFIX_INCREMENT(FontSize)
|
2007-12-23 10:56:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to only draw a part of the sprite.
|
|
|
|
* Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom).
|
|
|
|
* Both corners are included in the drawing area.
|
|
|
|
*/
|
|
|
|
struct SubSprite {
|
|
|
|
int left, top, right, bottom;
|
|
|
|
};
|
|
|
|
|
2008-04-24 11:11:50 +00:00
|
|
|
enum Colours {
|
2011-01-23 00:11:15 +00:00
|
|
|
COLOUR_BEGIN,
|
|
|
|
COLOUR_DARK_BLUE = COLOUR_BEGIN,
|
2007-12-23 10:56:02 +00:00
|
|
|
COLOUR_PALE_GREEN,
|
|
|
|
COLOUR_PINK,
|
|
|
|
COLOUR_YELLOW,
|
|
|
|
COLOUR_RED,
|
|
|
|
COLOUR_LIGHT_BLUE,
|
|
|
|
COLOUR_GREEN,
|
|
|
|
COLOUR_DARK_GREEN,
|
|
|
|
COLOUR_BLUE,
|
|
|
|
COLOUR_CREAM,
|
|
|
|
COLOUR_MAUVE,
|
|
|
|
COLOUR_PURPLE,
|
|
|
|
COLOUR_ORANGE,
|
|
|
|
COLOUR_BROWN,
|
|
|
|
COLOUR_GREY,
|
2008-04-24 11:11:50 +00:00
|
|
|
COLOUR_WHITE,
|
|
|
|
COLOUR_END,
|
2008-08-08 02:28:28 +00:00
|
|
|
INVALID_COLOUR = 0xFF,
|
2007-12-23 10:56:02 +00:00
|
|
|
};
|
2011-01-23 00:11:15 +00:00
|
|
|
template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 4> {};
|
2007-12-23 10:56:02 +00:00
|
|
|
|
2015-07-26 09:47:17 +00:00
|
|
|
/** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */
|
2007-12-23 10:56:02 +00:00
|
|
|
enum TextColour {
|
2011-01-03 12:04:53 +00:00
|
|
|
TC_BEGIN = 0x00,
|
2007-12-23 10:56:02 +00:00
|
|
|
TC_FROMSTRING = 0x00,
|
|
|
|
TC_BLUE = 0x00,
|
|
|
|
TC_SILVER = 0x01,
|
|
|
|
TC_GOLD = 0x02,
|
|
|
|
TC_RED = 0x03,
|
|
|
|
TC_PURPLE = 0x04,
|
|
|
|
TC_LIGHT_BROWN = 0x05,
|
|
|
|
TC_ORANGE = 0x06,
|
|
|
|
TC_GREEN = 0x07,
|
|
|
|
TC_YELLOW = 0x08,
|
|
|
|
TC_DARK_GREEN = 0x09,
|
|
|
|
TC_CREAM = 0x0A,
|
|
|
|
TC_BROWN = 0x0B,
|
|
|
|
TC_WHITE = 0x0C,
|
|
|
|
TC_LIGHT_BLUE = 0x0D,
|
|
|
|
TC_GREY = 0x0E,
|
|
|
|
TC_DARK_BLUE = 0x0F,
|
|
|
|
TC_BLACK = 0x10,
|
2011-01-03 12:04:53 +00:00
|
|
|
TC_END,
|
2008-08-09 02:11:46 +00:00
|
|
|
TC_INVALID = 0xFF,
|
2009-02-09 02:09:47 +00:00
|
|
|
|
2010-12-25 19:47:15 +00:00
|
|
|
TC_IS_PALETTE_COLOUR = 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour.
|
2010-12-25 20:02:04 +00:00
|
|
|
TC_NO_SHADE = 0x200, ///< Do not add shading to this text colour.
|
2007-12-23 10:56:02 +00:00
|
|
|
};
|
2010-03-23 22:25:43 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(TextColour)
|
2007-12-23 10:56:02 +00:00
|
|
|
|
2008-08-08 02:28:28 +00:00
|
|
|
/** Defines a few values that are related to animations using palette changes */
|
|
|
|
enum PaletteAnimationSizes {
|
2011-05-04 17:12:37 +00:00
|
|
|
PALETTE_ANIM_SIZE = 28, ///< number of animated colours
|
|
|
|
PALETTE_ANIM_START = 227, ///< Index in the _palettes array from which all animations are taking places (table/palettes.h)
|
2008-08-08 02:28:28 +00:00
|
|
|
};
|
|
|
|
|
2008-06-28 15:44:24 +00:00
|
|
|
/** Define the operation GfxFillRect performs */
|
|
|
|
enum FillRectMode {
|
2009-02-09 02:57:15 +00:00
|
|
|
FILLRECT_OPAQUE, ///< Fill rectangle with a single colour
|
2008-06-28 15:44:24 +00:00
|
|
|
FILLRECT_CHECKER, ///< Draw only every second pixel, used for greying-out
|
2009-02-09 02:57:15 +00:00
|
|
|
FILLRECT_RECOLOUR, ///< Apply a recolour sprite to the screen content
|
2008-06-28 15:44:24 +00:00
|
|
|
};
|
|
|
|
|
2008-08-23 20:16:54 +00:00
|
|
|
/** Palettes OpenTTD supports. */
|
2008-08-24 09:48:21 +00:00
|
|
|
enum PaletteType {
|
2008-08-23 20:16:54 +00:00
|
|
|
PAL_DOS, ///< Use the DOS palette.
|
|
|
|
PAL_WINDOWS, ///< Use the Windows palette.
|
|
|
|
PAL_AUTODETECT, ///< Automatically detect the palette based on the graphics pack.
|
|
|
|
MAX_PAL = 2, ///< The number of palettes.
|
|
|
|
};
|
|
|
|
|
2008-09-02 15:20:38 +00:00
|
|
|
/** Types of sprites that might be loaded */
|
|
|
|
enum SpriteType {
|
|
|
|
ST_NORMAL = 0, ///< The most basic (normal) sprite
|
|
|
|
ST_MAPGEN = 1, ///< Special sprite for the map generator
|
|
|
|
ST_FONT = 2, ///< A sprite used for fonts
|
|
|
|
ST_RECOLOUR = 3, ///< Recolour sprite
|
2009-01-11 22:28:30 +00:00
|
|
|
ST_INVALID = 4, ///< Pseudosprite or other unusable sprite, used only internally
|
2008-09-02 15:20:38 +00:00
|
|
|
};
|
|
|
|
|
2010-11-19 10:35:59 +00:00
|
|
|
/** The number of milliseconds per game tick. */
|
|
|
|
static const uint MILLISECONDS_PER_TICK = 30;
|
|
|
|
|
2011-12-08 18:13:29 +00:00
|
|
|
/** Information about the currently used palette. */
|
|
|
|
struct Palette {
|
|
|
|
Colour palette[256]; ///< Current palette. Entry 0 has to be always fully transparent!
|
|
|
|
int first_dirty; ///< The first dirty element.
|
|
|
|
int count_dirty; ///< The number of dirty elements.
|
|
|
|
};
|
|
|
|
|
2014-04-27 12:15:14 +00:00
|
|
|
/** Modes for 8bpp support */
|
|
|
|
enum Support8bpp {
|
|
|
|
S8BPP_NONE = 0, ///< No support for 8bpp by OS or hardware, force 32bpp blitters.
|
|
|
|
S8BPP_SYSTEM, ///< No 8bpp support by hardware, do not try to use 8bpp video modes or hardware palettes.
|
|
|
|
S8BPP_HARDWARE, ///< Full 8bpp support by OS and hardware.
|
|
|
|
};
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
#endif /* GFX_TYPE_H */
|